Fix for misunderstanding about date range required for templates

stats.

It should always be last n days, whether or not there is data.
This commit is contained in:
Adam Shimali
2016-04-07 09:30:02 +01:00
parent 3912cd95aa
commit 4ed2e7f8f2
3 changed files with 20 additions and 31 deletions

View File

@@ -63,11 +63,8 @@ def dao_get_notification_statistics_for_service_and_day(service_id, day):
def dao_get_template_statistics_for_service(service_id, limit_days=None):
filter = [TemplateStatistics.service_id == service_id]
if limit_days:
latest_stat = TemplateStatistics.query.filter_by(service_id=service_id).order_by(
desc(TemplateStatistics.day)).limit(1).first()
if latest_stat:
last_date_to_fetch = latest_stat.day - timedelta(days=limit_days)
filter.append(TemplateStatistics.day > last_date_to_fetch)
last_date_to_fetch = date.today() - timedelta(days=limit_days)
filter.append(TemplateStatistics.day > last_date_to_fetch)
return TemplateStatistics.query.filter(*filter).order_by(
desc(TemplateStatistics.updated_at)).all()