mirror of
https://github.com/GSA/notifications-api.git
synced 2026-09-06 11:08:24 -04:00
Add dao method to get template stats per month in financial year for service
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import itertools
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from app.models import TEMPLATE_TYPES
|
||||
from app.models import NOTIFICATION_STATUS_TYPES, TEMPLATE_TYPES
|
||||
|
||||
|
||||
def format_statistics(statistics):
|
||||
@@ -15,6 +15,28 @@ def format_statistics(statistics):
|
||||
return counts
|
||||
|
||||
|
||||
def format_monthly_template_notification_stats(year, rows):
|
||||
dict = {
|
||||
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 dict[formatted_month]:
|
||||
dict[formatted_month][str(row.template_id)] = {
|
||||
"name": row.name,
|
||||
"counts": dict.fromkeys(NOTIFICATION_STATUS_TYPES, 0)
|
||||
}
|
||||
dict[formatted_month][str(row.template_id)]["counts"][row.status] += row.count
|
||||
|
||||
return dict
|
||||
|
||||
|
||||
def create_zeroed_stats_dicts():
|
||||
return {
|
||||
template_type: {
|
||||
|
||||
Reference in New Issue
Block a user