mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-05-27 09:29:22 -04:00
Added new template usage page which will replace template-activity
The current template-activity page is slow as it is using the end point which uses notification_history and hence is timing out. This adds a new pages (so that they can be compared side by side) which will be hidden until is is approved with the larger data set and tested.
This commit is contained in:
@@ -106,6 +106,61 @@ def template_history(service_id):
|
||||
)
|
||||
|
||||
|
||||
@main.route("/services/<service_id>/template-usage")
|
||||
@login_required
|
||||
@user_has_permissions('view_activity', admin_override=True)
|
||||
def template_usage(service_id):
|
||||
|
||||
year, current_financial_year = requested_and_current_financial_year(request)
|
||||
stats = template_statistics_client.get_monthly_template_usage_for_service(service_id, year)
|
||||
|
||||
stats = sorted(stats, key=lambda x: (x['count']), reverse=True)
|
||||
|
||||
stats_by_month = list()
|
||||
|
||||
for month in get_months_for_financial_year(year, time_format='%Y-%m'):
|
||||
long_month = yyyy_mm_to_datetime(month).strftime('%B')
|
||||
|
||||
template_used = list()
|
||||
|
||||
for stat in stats:
|
||||
if long_month == datetime(1900, stat['month'], 1).strftime("%B"):
|
||||
template_used.append(
|
||||
{
|
||||
'name': stat['name'],
|
||||
'type': stat['type'],
|
||||
'requested_count': stat['count']
|
||||
}
|
||||
)
|
||||
|
||||
stats_by_month.append(
|
||||
{
|
||||
'name': long_month,
|
||||
'templates_used': template_used
|
||||
}
|
||||
)
|
||||
|
||||
months = stats_by_month
|
||||
|
||||
return render_template(
|
||||
'views/dashboard/all-template-statistics.html',
|
||||
months=months,
|
||||
stats=stats,
|
||||
most_used_template_count=max(
|
||||
max((
|
||||
template['requested_count']
|
||||
for template in month['templates_used']
|
||||
), default=0)
|
||||
for month in months
|
||||
),
|
||||
years=get_tuples_of_financial_years(
|
||||
partial(url_for, '.template_history', service_id=service_id),
|
||||
end=current_financial_year,
|
||||
),
|
||||
selected_year=year
|
||||
)
|
||||
|
||||
|
||||
@main.route("/services/<service_id>/usage")
|
||||
@login_required
|
||||
@user_has_permissions('manage_settings', admin_override=True)
|
||||
|
||||
@@ -26,6 +26,12 @@ class TemplateStatisticsApiClient(NotifyAdminAPIClient):
|
||||
url='/service/{}/notifications/templates/monthly?year={}'.format(service_id, year)
|
||||
)['data']
|
||||
|
||||
def get_monthly_template_usage_for_service(self, service_id, year):
|
||||
|
||||
return self.get(
|
||||
url='/service/{}/notifications/templates_usage/monthly?year={}'.format(service_id, year)
|
||||
)['stats']
|
||||
|
||||
def get_template_statistics_for_template(self, service_id, template_id):
|
||||
|
||||
return self.get(
|
||||
|
||||
Reference in New Issue
Block a user