mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-19 14:08:47 -04:00
Updated BE code to breakdown stats by hour instead of day
This commit is contained in:
@@ -604,7 +604,7 @@ def dao_fetch_stats_for_service_from_days_for_user(
|
|||||||
|
|
||||||
total_substmt = (
|
total_substmt = (
|
||||||
select(
|
select(
|
||||||
func.date_trunc("day", NotificationAllTimeView.created_at).label("day"),
|
func.date_trunc("hour", NotificationAllTimeView.created_at).label("hour"),
|
||||||
Job.notification_count.label("notification_count"),
|
Job.notification_count.label("notification_count"),
|
||||||
)
|
)
|
||||||
.join(Job, NotificationAllTimeView.job_id == Job.id)
|
.join(Job, NotificationAllTimeView.job_id == Job.id)
|
||||||
@@ -618,25 +618,25 @@ def dao_fetch_stats_for_service_from_days_for_user(
|
|||||||
.group_by(
|
.group_by(
|
||||||
Job.id,
|
Job.id,
|
||||||
Job.notification_count,
|
Job.notification_count,
|
||||||
func.date_trunc("day", NotificationAllTimeView.created_at),
|
func.date_trunc("hour", NotificationAllTimeView.created_at),
|
||||||
)
|
)
|
||||||
.subquery()
|
.subquery()
|
||||||
)
|
)
|
||||||
|
|
||||||
total_stmt = select(
|
total_stmt = select(
|
||||||
total_substmt.c.day,
|
total_substmt.c.hour,
|
||||||
func.sum(total_substmt.c.notification_count).label("total_notifications"),
|
func.sum(total_substmt.c.notification_count).label("total_notifications"),
|
||||||
).group_by(total_substmt.c.day)
|
).group_by(total_substmt.c.hour)
|
||||||
|
|
||||||
total_notifications = {
|
total_notifications = {
|
||||||
row.day: row.total_notifications for row in db.session.execute(total_stmt).all()
|
row.hour: row.total_notifications for row in db.session.execute(total_stmt).all()
|
||||||
}
|
}
|
||||||
|
|
||||||
stmt = (
|
stmt = (
|
||||||
select(
|
select(
|
||||||
NotificationAllTimeView.notification_type,
|
NotificationAllTimeView.notification_type,
|
||||||
NotificationAllTimeView.status,
|
NotificationAllTimeView.status,
|
||||||
func.date_trunc("day", NotificationAllTimeView.created_at).label("day"),
|
func.date_trunc("hour", NotificationAllTimeView.created_at).label("hour"),
|
||||||
func.count(NotificationAllTimeView.id).label("count"),
|
func.count(NotificationAllTimeView.id).label("count"),
|
||||||
)
|
)
|
||||||
.where(
|
.where(
|
||||||
@@ -649,7 +649,7 @@ def dao_fetch_stats_for_service_from_days_for_user(
|
|||||||
.group_by(
|
.group_by(
|
||||||
NotificationAllTimeView.notification_type,
|
NotificationAllTimeView.notification_type,
|
||||||
NotificationAllTimeView.status,
|
NotificationAllTimeView.status,
|
||||||
func.date_trunc("day", NotificationAllTimeView.created_at),
|
func.date_trunc("hour", NotificationAllTimeView.created_at),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -282,10 +282,12 @@ def get_service_statistics_for_specific_days_by_user(
|
|||||||
service_id, start_date, end_date, user_id
|
service_id, start_date, end_date, user_id
|
||||||
)
|
)
|
||||||
|
|
||||||
stats = get_specific_days_stats(
|
hours = days * 24
|
||||||
|
|
||||||
|
stats = get_specific_hours_stats(
|
||||||
results,
|
results,
|
||||||
start_date,
|
start_date,
|
||||||
days=days,
|
hours=hours,
|
||||||
total_notifications=total_notifications,
|
total_notifications=total_notifications,
|
||||||
)
|
)
|
||||||
return stats
|
return stats
|
||||||
|
|||||||
287
poetry.lock
generated
287
poetry.lock
generated
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user