Cleaning up function a bit.

Signed-off-by: Cliff Hill <Clifford.hill@gsa.gov>
This commit is contained in:
Cliff Hill
2025-01-10 15:08:44 -05:00
parent 162823e59b
commit 9219049150

View File

@@ -87,21 +87,19 @@ def create_zeroed_stats_dicts():
def _update_statuses_from_row(update_dict, row, total_notifications=None): def _update_statuses_from_row(update_dict, row, total_notifications=None):
# Initialize pending_count to total_notifications requested_count = 0
if total_notifications is not None: delivered_count = 0
pending_count = total_notifications failed_count = 0
# Update requested count # Update requested count
if row.status != NotificationStatus.CANCELLED: if row.status != NotificationStatus.CANCELLED:
update_dict[StatisticsType.REQUESTED] += row.count update_dict[StatisticsType.REQUESTED] += row.count
if total_notifications is not None: requested_count += row.count
pending_count -= row.count # Subtract from pending_count
# Update delivered count # Update delivered count
if row.status in (NotificationStatus.DELIVERED, NotificationStatus.SENT): if row.status in (NotificationStatus.DELIVERED, NotificationStatus.SENT):
update_dict[StatisticsType.DELIVERED] += row.count update_dict[StatisticsType.DELIVERED] += row.count
if total_notifications is not None: delivered_count += row.count
pending_count -= row.count # Subtract from pending_count
# Update failure count # Update failure count
if row.status in ( if row.status in (
@@ -113,11 +111,11 @@ def _update_statuses_from_row(update_dict, row, total_notifications=None):
NotificationStatus.VIRUS_SCAN_FAILED, NotificationStatus.VIRUS_SCAN_FAILED,
): ):
update_dict[StatisticsType.FAILURE] += row.count update_dict[StatisticsType.FAILURE] += row.count
if total_notifications is not None: failed_count += row.count
pending_count -= row.count # Subtract from pending_count
if total_notifications is not None: if total_notifications is not None:
# Update pending count directly # Update pending count directly
pending_count = total_notifications - (requested_count + delivered_count + failed_count)
update_dict[StatisticsType.PENDING] = pending_count update_dict[StatisticsType.PENDING] = pending_count