mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-16 20:48:37 -04:00
pending count
This commit is contained in:
@@ -230,13 +230,18 @@ def get_service_statistics_for_specific_days(service_id, start, days=1):
|
||||
end_date = datetime.strptime(start, "%Y-%m-%d")
|
||||
start_date = end_date - timedelta(days=days - 1)
|
||||
|
||||
results = dao_fetch_stats_for_service_from_days(
|
||||
total_notifications, results = dao_fetch_stats_for_service_from_days(
|
||||
service_id,
|
||||
start_date,
|
||||
end_date,
|
||||
)
|
||||
|
||||
stats = get_specific_days_stats(results, start_date, days=days)
|
||||
stats = get_specific_days_stats(
|
||||
results,
|
||||
start_date,
|
||||
days=days,
|
||||
total_notifications=total_notifications,
|
||||
)
|
||||
|
||||
return stats
|
||||
|
||||
|
||||
@@ -7,10 +7,11 @@ from app.enums import (
|
||||
NotificationStatus,
|
||||
StatisticsType,
|
||||
TemplateType,
|
||||
NotificationType
|
||||
)
|
||||
|
||||
|
||||
def format_statistics(statistics):
|
||||
def format_statistics(statistics, total_notifications=None):
|
||||
# statistics come in a named tuple with uniqueness from 'notification_type', 'status' - however missing
|
||||
# statuses/notification types won't be represented and the status types need to be simplified/summed up
|
||||
# so we can return emails/sms * created, sent, and failed
|
||||
@@ -24,8 +25,18 @@ def format_statistics(statistics):
|
||||
row,
|
||||
)
|
||||
|
||||
return counts
|
||||
if NotificationType.SMS in counts and total_notifications is not None:
|
||||
sms_dict = counts[NotificationType.SMS]
|
||||
delivered_count = sms_dict[StatisticsType.DELIVERED]
|
||||
failed_count = sms_dict[StatisticsType.FAILURE]
|
||||
print('total_notifications',total_notifications)
|
||||
pending_count = total_notifications - (delivered_count + failed_count)
|
||||
|
||||
pending_count = max(0, pending_count)
|
||||
|
||||
sms_dict[StatisticsType.PENDING] = pending_count
|
||||
|
||||
return counts
|
||||
|
||||
def format_admin_stats(statistics):
|
||||
counts = create_stats_dict()
|
||||
@@ -98,12 +109,10 @@ def _update_statuses_from_row(update_dict, row):
|
||||
# Update requested count
|
||||
if row.status != NotificationStatus.CANCELLED:
|
||||
update_dict[StatisticsType.REQUESTED] += row.count
|
||||
requested_count += row.count
|
||||
|
||||
# Update delivered count
|
||||
if row.status in (NotificationStatus.DELIVERED, NotificationStatus.SENT):
|
||||
update_dict[StatisticsType.DELIVERED] += row.count
|
||||
delivered_count += row.count
|
||||
|
||||
# Update failure count
|
||||
if row.status in (
|
||||
|
||||
Reference in New Issue
Block a user