This commit is contained in:
Rebecca Law
2017-10-25 16:47:39 +01:00
parent 4304aad9fc
commit 61a68a2d13
4 changed files with 34 additions and 18 deletions

View File

@@ -413,8 +413,7 @@ def fetch_stats_by_date_range_for_all_services(start_date, end_date, include_fro
if start_date >= datetime.utcnow() - timedelta(days=7):
table = Notification
query = db.session.query(
subquery = db.session.query(
table.notification_type,
table.status,
table.service_id,
@@ -426,12 +425,23 @@ def fetch_stats_by_date_range_for_all_services(start_date, end_date, include_fro
table.notification_type,
table.status,
table.service_id
).order_by(
table.service_id
)
if not include_from_test_key:
query = query.filter(table.key_type != KEY_TYPE_TEST)
subquery = subquery.filter(table.key_type != KEY_TYPE_TEST)
subquery = subquery.subquery()
query = db.session.query(
Service.id.label('service_id'),
Service.name,
Service.restricted,
Service.research_mode,
subquery.c.notification_type,
subquery.c.status,
subquery.c.count
).join(
subquery,
subquery.c.service_id == Service.id
).order_by(Service.id)
return query.all()