# Path: app/models.py
# class ResponseLog(models.Model):
#     """
#     Model for logging info about the device response.
#     """
#     platform = models.CharField(choices=PLATFORM_CHOICES, max_length=10)
#     roundtrip_time = models.FloatField()
#     available = models.BooleanField()
#     date = models.DateTimeField(auto_now_add=True)


import logging
from django.db.models import Avg, Max, Min
from logentries import LogentriesHandler
from .models import ResponseLog
LOG_NONCE = 'nonce'
LOG_USERNAME = 'username'
LOG_EMAIL = 'email'

LOGENTRIES_HANDLERS = {}

django_logger = logging.getLogger('django')


def get_metrics(start_date, end_date, platform):
    """
    Function to get a dict with metrics for the given date range and platform.

    Args:
        start_date (date): Start date to get metrics for.
        end_date (date): End date to get metrics for.
        platform (string): Platform to get metrics for.

    Returns:
        Dict containing the metrics.
    """
    def _get_min(query):
        return query.aggregate(Min('roundtrip_time'))['roundtrip_time__min']

    def _get_max(query):
        return query.aggregate(Max('roundtrip_time'))['roundtrip_time__max']

    def _get_avg(query):
        return query.aggregate(Avg('roundtrip_time'))['roundtrip_time__avg']


# Path: app/models.py
# class ResponseLog(models.Model):
#     """
#     Model for logging info about the device response.
#     """
#     platform = models.CharField(choices=PLATFORM_CHOICES, max_length=10)
#     roundtrip_time = models.FloatField()
#     available = models.BooleanField()
#     date = models.DateTimeField(auto_now_add=True)


# Path: app/utils.py
import logging
from django.db.models import Avg, Max, Min
from logentries import LogentriesHandler
from .models import ResponseLog

LOG_NONCE = 'nonce'
LOG_USERNAME = 'username'
LOG_EMAIL = 'email'

LOGENTRIES_HANDLERS = {}

django_logger = logging.getLogger('django')


def get_metrics(start_date, end_date, platform):
    """
    Function to get a dict with metrics for the given date range and platform.

    Args:
        start_date (date): Start date to get metrics for.
        end_date (date): End date to get metrics for.
        platform (string): Platform to get metrics for.

    Returns:
        Dict containing the metrics.
    """
    def _get_min(query):
        return query.aggregate(Min('roundtrip_time'))['roundtrip_time__min']

    def _get_max(query):
        return query.aggregate(Max('roundtrip_time'))['roundtrip_time__max']

    def _get_avg(query):
        return query.aggregate(Avg('roundtrip_time'))['roundtrip_time__avg']


    base_query = ResponseLog.objects.filter(