diff --git a/app/dao/services_dao.py b/app/dao/services_dao.py index a7db2415d..db983697e 100644 --- a/app/dao/services_dao.py +++ b/app/dao/services_dao.py @@ -604,7 +604,7 @@ def dao_fetch_stats_for_service_from_days_for_user( total_substmt = ( 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"), ) .join(Job, NotificationAllTimeView.job_id == Job.id) @@ -618,25 +618,25 @@ def dao_fetch_stats_for_service_from_days_for_user( .group_by( Job.id, Job.notification_count, - func.date_trunc("day", NotificationAllTimeView.created_at), + func.date_trunc("hour", NotificationAllTimeView.created_at), ) .subquery() ) total_stmt = select( - total_substmt.c.day, + total_substmt.c.hour, func.sum(total_substmt.c.notification_count).label("total_notifications"), - ).group_by(total_substmt.c.day) + ).group_by(total_substmt.c.hour) 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 = ( select( NotificationAllTimeView.notification_type, 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"), ) .where( @@ -649,7 +649,7 @@ def dao_fetch_stats_for_service_from_days_for_user( .group_by( NotificationAllTimeView.notification_type, NotificationAllTimeView.status, - func.date_trunc("day", NotificationAllTimeView.created_at), + func.date_trunc("hour", NotificationAllTimeView.created_at), ) ) diff --git a/app/service/rest.py b/app/service/rest.py index c6dac0840..154ce3997 100644 --- a/app/service/rest.py +++ b/app/service/rest.py @@ -282,10 +282,12 @@ def get_service_statistics_for_specific_days_by_user( service_id, start_date, end_date, user_id ) - stats = get_specific_days_stats( + hours = days * 24 + + stats = get_specific_hours_stats( results, start_date, - days=days, + hours=hours, total_notifications=total_notifications, ) return stats