# Path: esperaparaderos/models.py
# class InfoParadas(models.Model):
#     codigo = models.CharField(max_length=20, blank=True, null=True)
#     latitud = models.FloatField(blank=True, null=True)
#     longitud = models.FloatField(blank=True, null=True)
#     tiempo_ultimo_bus = models.DateTimeField(blank=True, null=True)
#     subidas = models.FloatField(blank=True, null=True)
# 
#     class Meta:
#         managed = False
#         db_table = 'info_paradas'


from django.shortcuts import render
from django.views.generic import View
from django.http import JsonResponse
from esperaparaderos.models import InfoParadas
from datetime import datetime



# Create your views here.
class GetWaitingUsersByBusStop(View):
    '''This class requests to the database the number of users are waiting for a bus by bus stop'''

    def __init__(self):
        """the contructor, context are the parameter given to the html template"""
        self.context={}

    def get(self, request, quantity):
        """ the {quantity} most populated bus stops """
        busStops = InfoParadas.objects.all().order_by('-subidas')[:quantity]

        return JsonResponse(applyFormatAnswer(busStops), safe=False)

class GetMostDelayedBusesByBusStop(View):
    '''This class requests to the database the bus stops with most waiting time by bus stop '''

    def __init__(self):
        """the contructor, context are the parameter given to the html template"""
        self.context={}

    def get(self, request, quantity):
        """ the {quantity} bus stops with most waiting time for a bus """

# Path: esperaparaderos/models.py
# class InfoParadas(models.Model):
#     codigo = models.CharField(max_length=20, blank=True, null=True)
#     latitud = models.FloatField(blank=True, null=True)
#     longitud = models.FloatField(blank=True, null=True)
#     tiempo_ultimo_bus = models.DateTimeField(blank=True, null=True)
#     subidas = models.FloatField(blank=True, null=True)
# 
#     class Meta:
#         managed = False
#         db_table = 'info_paradas'


# Path: esperaparaderos/views.py
from django.shortcuts import render
from django.views.generic import View
from django.http import JsonResponse
from esperaparaderos.models import InfoParadas
from datetime import datetime




# Create your views here.
class GetWaitingUsersByBusStop(View):
    '''This class requests to the database the number of users are waiting for a bus by bus stop'''

    def __init__(self):
        """the contructor, context are the parameter given to the html template"""
        self.context={}

    def get(self, request, quantity):
        """ the {quantity} most populated bus stops """
        busStops = InfoParadas.objects.all().order_by('-subidas')[:quantity]

        return JsonResponse(applyFormatAnswer(busStops), safe=False)

class GetMostDelayedBusesByBusStop(View):
    '''This class requests to the database the bus stops with most waiting time by bus stop '''

    def __init__(self):
        """the contructor, context are the parameter given to the html template"""
        self.context={}

    def get(self, request, quantity):
        """ the {quantity} bus stops with most waiting time for a bus """

        busStops = InfoParadas.objects.all().order_by('tiempo_ultimo_bus')[:quantity]