mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-23 17:01:35 -05:00
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:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user