mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-03 18:01:08 -05:00
create initial stats query
get statistics for all services, for today only
This commit is contained in:
@@ -180,3 +180,23 @@ def dao_fetch_weekly_historical_stats_for_service(service_id):
|
|||||||
).order_by(
|
).order_by(
|
||||||
asc(monday_of_notification_week), NotificationHistory.status
|
asc(monday_of_notification_week), NotificationHistory.status
|
||||||
).all()
|
).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
|
||||||
|
)
|
||||||
|
|||||||
@@ -52,6 +52,8 @@ def get_services():
|
|||||||
if user_id:
|
if user_id:
|
||||||
services = dao_fetch_all_services_by_user(user_id)
|
services = dao_fetch_all_services_by_user(user_id)
|
||||||
else:
|
else:
|
||||||
|
if request.args.get('detailed') == 'True':
|
||||||
|
return get_detailed_services()
|
||||||
services = dao_fetch_all_services()
|
services = dao_fetch_all_services()
|
||||||
data = service_schema.dump(services, many=True).data
|
data = service_schema.dump(services, many=True).data
|
||||||
return jsonify(data=data)
|
return jsonify(data=data)
|
||||||
@@ -245,3 +247,16 @@ def get_detailed_service(service_id, today_only=False):
|
|||||||
|
|
||||||
data = detailed_service_schema.dump(service).data
|
data = detailed_service_schema.dump(service).data
|
||||||
return jsonify(data=data)
|
return jsonify(data=data)
|
||||||
|
|
||||||
|
|
||||||
|
def get_detailed_services():
|
||||||
|
services = {service.id: service for service in dao_fetch_all_services()}
|
||||||
|
stats = dao_fetch_todays_stats_for_all_services(service_id)
|
||||||
|
|
||||||
|
for row in stats:
|
||||||
|
services[row.service_id].statistics
|
||||||
|
# todo: how do we separate rows of statistics by service?
|
||||||
|
service.statistics = statistics.format_statistics(stats)
|
||||||
|
|
||||||
|
data = detailed_service_schema.dump(service).data
|
||||||
|
return jsonify(data=data)
|
||||||
|
|||||||
Reference in New Issue
Block a user