Allow filtering of notification stats by days

https://www.pivotaltracker.com/story/show/117920839

On the dashboard we want to show counts of notifications sent in the
last 7 days, plus today. So the API enpoint needs to accept an argument
to limit how many days worth of statistics it will return.

This is a bit fiddly at the DAO level because the date is just stored as
a string.
This commit is contained in:
Chris Hill-Scott
2016-04-19 16:34:17 +01:00
parent 16553af133
commit 9c2c9435e3
3 changed files with 72 additions and 4 deletions

View File

@@ -69,6 +69,19 @@ def dao_get_notification_statistics_for_service_and_day(service_id, day):
).order_by(desc(NotificationStatistics.day)).first()
def dao_get_notification_statistics_for_service_and_previous_days(service_id, limit_days):
return NotificationStatistics.query.filter_by(
service_id=service_id
).filter(
NotificationStatistics.day.in_((
(date.today() - timedelta(days=days_ago)).strftime('%Y-%m-%d')
for days_ago in range(0, limit_days + 1)
))
).order_by(
desc(NotificationStatistics.day)
).all()
def dao_get_template_statistics_for_service(service_id, limit_days=None):
filter = [TemplateStatistics.service_id == service_id]
if limit_days: