From 0dd862f9362e308483827158e1d3b6c27e0725e9 Mon Sep 17 00:00:00 2001 From: Andrew Shumway Date: Fri, 22 Sep 2023 09:57:18 -0600 Subject: [PATCH] Revert removal of unneeded code --- app/service/statistics.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/app/service/statistics.py b/app/service/statistics.py index 9d20c5f7f..c61a3c55f 100644 --- a/app/service/statistics.py +++ b/app/service/statistics.py @@ -1,7 +1,8 @@ from collections import defaultdict +from datetime import datetime from app.dao.date_util import get_months_for_financial_year -from app.models import NOTIFICATION_TYPES +from app.models import NOTIFICATION_STATUS_TYPES, NOTIFICATION_TYPES def format_statistics(statistics): @@ -54,6 +55,26 @@ def create_stats_dict(): return stats_dict +def format_monthly_template_notification_stats(year, rows): + stats = { + datetime.strftime(date, "%Y-%m"): {} + for date in [datetime(year, month, 1) for month in range(4, 13)] + + [datetime(year + 1, month, 1) for month in range(1, 4)] + } + + for row in rows: + formatted_month = row.month.strftime("%Y-%m") + if str(row.template_id) not in stats[formatted_month]: + stats[formatted_month][str(row.template_id)] = { + "name": row.name, + "type": row.template_type, + "counts": dict.fromkeys(NOTIFICATION_STATUS_TYPES, 0), + } + stats[formatted_month][str(row.template_id)]["counts"][row.status] += row.count + + return stats + + def create_zeroed_stats_dicts(): return { template_type: {status: 0 for status in ("requested", "delivered", "failed")}