# Path: dashboard/models.py
# class ProjectSummary(models.Model):
#     """Summary data about a JIRA filter for a particular date."""
# 
#     filter_id = models.IntegerField()
#     incomplete = models.IntegerField()
#     complete = models.IntegerField()
#     total = models.IntegerField()
#     created_on = models.DateField()
#     updated_at = models.DateTimeField(null=False)
# 
#     class Meta:
#         verbose_name = "project summary"
#         verbose_name_plural = "project summaries"
#         unique_together = (("filter_id", "created_on"))
#         get_latest_by = "updated_at"
# 
#     def __repr__(self):
#         return "<ProjectSummary {} filter: {} created_on: {}>".format(self.id, self.filter_id, self.created_on)
# 
#     @property
#     def pct_complete(self):
#         """How complete is the project.
# 
#         Returns:
#             float: Percentage of the project that is complete.
#         """
#         if self.total == 0:
#             return float(0)
#         return self.complete / float(self.total)


import datetime
from django.utils import timezone
from ..models import ProjectSummary
    except ProjectSummary.DoesNotExist:
        return None


def for_date_range(filter_id, start_date, end_date=None):
    """Find all the summaries for a given filter_id and a date range.
    Args:
        filter_id (int): The filter_id for the project in question.
        start_date (Date): The start of the range you want summaries for
        end_date (Date[today]): The end of the range you want summaries for, default: today
    Returns:
        List[ProjectSummary]: 0 or more project summaries for that filter in the range
    """
    if end_date is None:
        end_date = datetime.date.today()
    return ProjectSummary.objects.filter(
        filter_id=filter_id,
        created_on__gte=start_date,
        created_on__lte=end_date,
    ).order_by('created_on')


def latest_update():
    """Retun the most recent datetime of summary updates.

    Returns:
        datetime: When the most recent ProjectSummary was updated.
    """
    try:
        return ProjectSummary.objects.latest().updated_at

# Path: dashboard/models.py
# class ProjectSummary(models.Model):
#     """Summary data about a JIRA filter for a particular date."""
# 
#     filter_id = models.IntegerField()
#     incomplete = models.IntegerField()
#     complete = models.IntegerField()
#     total = models.IntegerField()
#     created_on = models.DateField()
#     updated_at = models.DateTimeField(null=False)
# 
#     class Meta:
#         verbose_name = "project summary"
#         verbose_name_plural = "project summaries"
#         unique_together = (("filter_id", "created_on"))
#         get_latest_by = "updated_at"
# 
#     def __repr__(self):
#         return "<ProjectSummary {} filter: {} created_on: {}>".format(self.id, self.filter_id, self.created_on)
# 
#     @property
#     def pct_complete(self):
#         """How complete is the project.
# 
#         Returns:
#             float: Percentage of the project that is complete.
#         """
#         if self.total == 0:
#             return float(0)
#         return self.complete / float(self.total)


# Path: dashboard/services/summaries.py
import datetime
from django.utils import timezone
from ..models import ProjectSummary

    except ProjectSummary.DoesNotExist:
        return None


def for_date_range(filter_id, start_date, end_date=None):
    """Find all the summaries for a given filter_id and a date range.
    Args:
        filter_id (int): The filter_id for the project in question.
        start_date (Date): The start of the range you want summaries for
        end_date (Date[today]): The end of the range you want summaries for, default: today
    Returns:
        List[ProjectSummary]: 0 or more project summaries for that filter in the range
    """
    if end_date is None:
        end_date = datetime.date.today()
    return ProjectSummary.objects.filter(
        filter_id=filter_id,
        created_on__gte=start_date,
        created_on__lte=end_date,
    ).order_by('created_on')


def latest_update():
    """Retun the most recent datetime of summary updates.

    Returns:
        datetime: When the most recent ProjectSummary was updated.
    """
    try:
        return ProjectSummary.objects.latest().updated_at

    except ProjectSummary.DoesNotExist: