Add new report to show monthly notification stats for each service

This report will be used by the engagement team. There is a form to give
a start and end date for the report, and the form is then downloaded
as a CSV file when the form is submitted.
This commit is contained in:
Katie Smith
2019-07-22 13:09:03 +01:00
parent 1bd5ff1dfc
commit 9dc13f1d8e
8 changed files with 169 additions and 1 deletions

View File

@@ -11,6 +11,7 @@ from app import (
complaint_api_client,
format_date_numeric,
letter_jobs_client,
notification_api_client,
platform_stats_api_client,
service_api_client,
)
@@ -20,6 +21,7 @@ from app.main.forms import (
ClearCacheForm,
DateFilterForm,
PDFUploadForm,
RequiredDateFilterForm,
ReturnedLettersForm,
)
from app.statistics_utils import (
@@ -263,6 +265,33 @@ def performance_platform_xlsx():
}
@main.route("/platform-admin/reports/notifications-sent-by-service", methods=['GET', 'POST'])
@user_is_platform_admin
def notifications_sent_by_service():
form = RequiredDateFilterForm()
if form.validate_on_submit():
start_date = form.start_date.data
end_date = form.end_date.data
headers = [
'date_created', 'service_id', 'service_name', 'notification_type', 'count_sending', 'count_delivered',
'count_technical_failure', 'count_temporary_failure', 'count_permanent_failure', 'count_sent'
]
result = notification_api_client.get_notification_status_by_service(start_date, end_date)
for row in result:
row[0] = datetime.strptime(row[0], '%a, %d %b %Y %X %Z').strftime('%Y-%m-%d')
return Spreadsheet.from_rows([headers] + result).as_csv_data, 200, {
'Content-Type': 'text/csv; charset=utf-8',
'Content-Disposition': 'attachment; filename="{} to {} notification status per service report.csv"'.format(
start_date, end_date)
}
return render_template('views/platform-admin/notifications_by_service.html', form=form)
@main.route("/platform-admin/complaints")
@user_is_platform_admin
def platform_admin_list_complaints():