create initial stats query

get statistics for all services, for today only
This commit is contained in:
Leo Hemsted
2016-08-11 17:24:44 +01:00
parent a9f51f5b48
commit ebb13a1251
2 changed files with 35 additions and 0 deletions

View File

@@ -180,3 +180,23 @@ def dao_fetch_weekly_historical_stats_for_service(service_id):
).order_by(
asc(monday_of_notification_week), NotificationHistory.status
).all()
@statsd(namespace='dao')
def dao_fetch_todays_stats_for_all_services():
return db.session.query(
Notification.notification_type,
Notification.status,
func.count(Notification.id).label('count')
).select_from(
Service
).join(
# don't want to create a relationship in case we accidentally lazily load it, so manually define the join term
Notification
).filter(
func.date(Notification.created_at) == date.today()
).group_by(
Notification.notification_type,
Notification.status,
Notification.service_id
)