Added a date range filter for the get all services end point.

When the start_date and end_date query argruments exists in the request,
the query will return the results from the NotificationHistory table for the given date range.
We will need to check the performance of this query, but this will only be used by the platform admin page.
This commit is contained in:
Rebecca Law
2016-12-28 15:39:55 +00:00
parent 8c5c712f2b
commit 8ad078b663
4 changed files with 81 additions and 9 deletions

View File

@@ -263,3 +263,31 @@ def dao_fetch_todays_stats_for_all_services(include_from_test_key=True):
query = query.filter(Notification.key_type != KEY_TYPE_TEST)
return query
@statsd(namespace='dao')
def fetch_stats_by_date_range_for_all_services(start_date, end_date, include_from_test_key=True):
query = db.session.query(
NotificationHistory.notification_type,
NotificationHistory.status,
NotificationHistory.service_id,
func.count(NotificationHistory.id).label('count')
).select_from(
Service
).join(
NotificationHistory
).filter(
func.date(NotificationHistory.created_at) >= start_date,
func.date(NotificationHistory.created_at) <= end_date
).group_by(
NotificationHistory.notification_type,
NotificationHistory.status,
NotificationHistory.service_id
).order_by(
NotificationHistory.service_id
)
if not include_from_test_key:
query = query.filter(NotificationHistory.key_type != KEY_TYPE_TEST)
return query