Getting total notifications per day made.

Signed-off-by: Cliff Hill <Clifford.hill@gsa.gov>
This commit is contained in:
Cliff Hill
2025-01-10 16:21:15 -05:00
parent b543db474f
commit 467357c031
2 changed files with 20 additions and 5 deletions

View File

@@ -482,10 +482,13 @@ def dao_fetch_stats_for_service_from_days(service_id, start_date, end_date):
)
total_stmt = select(
func.sum(total_substmt.c.notification_count).label("total_notifications")
func.date_trunc("day", NotificationAllTimeView.created_at).label("day"),
func.sum(total_substmt.c.notification_count).label("total_notifications"),
).group_by(
func.date_trunc("day", NotificationAllTimeView.created_at),
)
total_notifications = db.session.execute(total_stmt).scalar_one()
total_notifications = {day: count for day, count in db.session.execute(total_stmt)}
stmt = (
select(
@@ -777,7 +780,11 @@ def get_specific_days_stats(
stats = {
day.strftime("%Y-%m-%d"): statistics.format_statistics(
rows,
total_notifications=total_notifications,
total_notifications=(
total_notifications.get(day, 0)
if total_notifications is not None
else None
),
)
for day, rows in grouped_data.items()
}

View File

@@ -2,7 +2,13 @@ from collections import defaultdict
from datetime import datetime
from app.dao.date_util import get_months_for_financial_year
from app.enums import KeyType, NotificationStatus, NotificationType, StatisticsType, TemplateType
from app.enums import (
KeyType,
NotificationStatus,
NotificationType,
StatisticsType,
TemplateType,
)
def format_statistics(statistics, total_notifications=None):
@@ -25,7 +31,9 @@ def format_statistics(statistics, total_notifications=None):
requested_count = sms_dict[StatisticsType.REQUESTED]
delivered_count = sms_dict[StatisticsType.DELIVERED]
failed_count = sms_dict[StatisticsType.FAILURE]
pending_count = total_notifications - (requested_count + delivered_count + failed_count)
pending_count = total_notifications - (
requested_count + delivered_count + failed_count
)
sms_dict[StatisticsType.PENDING] = pending_count
return counts