mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-23 15:56:45 -04:00
Moving where the pending calculation is done.
Signed-off-by: Cliff Hill <Clifford.hill@gsa.gov>
This commit is contained in:
@@ -457,8 +457,9 @@ def dao_fetch_stats_for_service_from_days(service_id, start_date, end_date):
|
|||||||
|
|
||||||
# Getting the total notifications through this query.
|
# Getting the total notifications through this query.
|
||||||
|
|
||||||
total_stmt = (
|
total_substmt = (
|
||||||
select(
|
select(
|
||||||
|
func.date_trunc("day", NotificationAllTimeView.created_at).label("day"),
|
||||||
cast(Job.notification_count, Integer).label(
|
cast(Job.notification_count, Integer).label(
|
||||||
"notification_count"
|
"notification_count"
|
||||||
), # <-- i added cast here
|
), # <-- i added cast here
|
||||||
@@ -475,10 +476,16 @@ def dao_fetch_stats_for_service_from_days(service_id, start_date, end_date):
|
|||||||
.group_by(
|
.group_by(
|
||||||
Job.id,
|
Job.id,
|
||||||
Job.notification_count,
|
Job.notification_count,
|
||||||
|
func.date_trunc("day", NotificationAllTimeView.created_at),
|
||||||
)
|
)
|
||||||
|
.subquery()
|
||||||
)
|
)
|
||||||
|
|
||||||
total_notifications = sum(db.session.execute(total_stmt).scalars())
|
total_stmt = select(
|
||||||
|
func.sum(total_substmt.c.notification_count).label("total_notifications")
|
||||||
|
)
|
||||||
|
|
||||||
|
total_notifications = db.session.execute(total_stmt).scalar_one()
|
||||||
|
|
||||||
stmt = (
|
stmt = (
|
||||||
select(
|
select(
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ from collections import defaultdict
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from app.dao.date_util import get_months_for_financial_year
|
from app.dao.date_util import get_months_for_financial_year
|
||||||
from app.enums import KeyType, NotificationStatus, StatisticsType, TemplateType
|
from app.enums import KeyType, NotificationStatus, NotificationType, StatisticsType, TemplateType
|
||||||
|
|
||||||
|
|
||||||
def format_statistics(statistics, total_notifications=None):
|
def format_statistics(statistics, total_notifications=None):
|
||||||
@@ -17,9 +17,17 @@ def format_statistics(statistics, total_notifications=None):
|
|||||||
_update_statuses_from_row(
|
_update_statuses_from_row(
|
||||||
counts[row.notification_type],
|
counts[row.notification_type],
|
||||||
row,
|
row,
|
||||||
total_notifications=total_notifications,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Update pending count directly
|
||||||
|
if NotificationType.SMS in counts and total_notifications is not None:
|
||||||
|
sms_dict = counts[NotificationType.SMS]
|
||||||
|
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)
|
||||||
|
sms_dict[StatisticsType.PENDING] = pending_count
|
||||||
|
|
||||||
return counts
|
return counts
|
||||||
|
|
||||||
|
|
||||||
@@ -86,7 +94,7 @@ def create_zeroed_stats_dicts():
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def _update_statuses_from_row(update_dict, row, total_notifications=None):
|
def _update_statuses_from_row(update_dict, row):
|
||||||
requested_count = 0
|
requested_count = 0
|
||||||
delivered_count = 0
|
delivered_count = 0
|
||||||
failed_count = 0
|
failed_count = 0
|
||||||
@@ -113,11 +121,6 @@ def _update_statuses_from_row(update_dict, row, total_notifications=None):
|
|||||||
update_dict[StatisticsType.FAILURE] += row.count
|
update_dict[StatisticsType.FAILURE] += row.count
|
||||||
failed_count += row.count
|
failed_count += row.count
|
||||||
|
|
||||||
if total_notifications is not None:
|
|
||||||
# Update pending count directly
|
|
||||||
pending_count = total_notifications - (requested_count + delivered_count + failed_count)
|
|
||||||
update_dict[StatisticsType.PENDING] = pending_count
|
|
||||||
|
|
||||||
|
|
||||||
def create_empty_monthly_notification_status_stats_dict(year):
|
def create_empty_monthly_notification_status_stats_dict(year):
|
||||||
utc_month_starts = get_months_for_financial_year(year)
|
utc_month_starts = get_months_for_financial_year(year)
|
||||||
|
|||||||
Reference in New Issue
Block a user