mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 15:46:07 -05:00
Getting total notifications per day made.
Signed-off-by: Cliff Hill <Clifford.hill@gsa.gov>
This commit is contained in:
@@ -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()
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user