mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-08 08:28:15 -04:00
Admin app uses the new API response formats.
This commit is contained in:
@@ -66,11 +66,12 @@ def template_history(service_id):
|
||||
template_statistics = aggregate_usage(
|
||||
template_statistics_client.get_template_statistics_for_service(service_id)
|
||||
)
|
||||
|
||||
return render_template(
|
||||
'views/dashboard/all-template-statistics.html',
|
||||
template_statistics=template_statistics,
|
||||
most_used_template_count=max(
|
||||
[row['usage_count'] for row in template_statistics] or [0]
|
||||
[row['count'] for row in template_statistics] or [0]
|
||||
)
|
||||
)
|
||||
|
||||
@@ -98,34 +99,28 @@ def weekly(service_id):
|
||||
|
||||
|
||||
def aggregate_usage(template_statistics):
|
||||
|
||||
immutable_template = namedtuple('Template', ['template_type', 'name', 'id'])
|
||||
|
||||
# grouby requires the list to be sorted by template first
|
||||
statistics_sorted_by_template = sorted(
|
||||
(
|
||||
(
|
||||
immutable_template(**row['template']),
|
||||
row['usage_count']
|
||||
)
|
||||
for row in template_statistics
|
||||
),
|
||||
key=lambda items: items[0]
|
||||
template_statistics,
|
||||
key=lambda template_statistic: template_statistic['template_name']
|
||||
)
|
||||
|
||||
# then group and sort the result by usage
|
||||
return sorted(
|
||||
totals = sorted(
|
||||
(
|
||||
{
|
||||
'usage_count': sum(usage[1] for usage in usages),
|
||||
'template': template
|
||||
'count': sum(usage['count'] for usage in usages),
|
||||
'template_name': template_name,
|
||||
'template_id': template_id,
|
||||
'template_type': template_type
|
||||
}
|
||||
for template, usages in groupby(statistics_sorted_by_template, lambda items: items[0])
|
||||
for (template_name, template_id, template_type), usages in groupby(statistics_sorted_by_template, lambda items: (items['template_name'], items['template_id'], items['template_type'])) # noqa
|
||||
),
|
||||
key=lambda row: row['usage_count'],
|
||||
key=lambda row: row['count'],
|
||||
reverse=True
|
||||
)
|
||||
|
||||
return totals
|
||||
|
||||
|
||||
def get_dashboard_partials(service_id):
|
||||
|
||||
@@ -149,7 +144,7 @@ def get_dashboard_partials(service_id):
|
||||
'views/dashboard/template-statistics.html',
|
||||
template_statistics=template_statistics,
|
||||
most_used_template_count=max(
|
||||
[row['usage_count'] for row in template_statistics] or [0]
|
||||
[row['count'] for row in template_statistics] or [0]
|
||||
),
|
||||
),
|
||||
'has_template_statistics': bool(template_statistics),
|
||||
|
||||
Reference in New Issue
Block a user