mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-06 08:08:25 -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),
|
||||
|
||||
@@ -16,12 +16,14 @@ class TemplateStatisticsApiClient(BaseAPIClient):
|
||||
params = {}
|
||||
if limit_days is not None:
|
||||
params['limit_days'] = limit_days
|
||||
|
||||
return self.get(
|
||||
url='/service/{}/template-statistics'.format(service_id),
|
||||
params=params
|
||||
)['data']
|
||||
|
||||
def get_template_statistics_for_template(self, service_id, template_id):
|
||||
|
||||
return self.get(
|
||||
url='/service/{}/template-statistics/{}'.format(service_id, template_id)
|
||||
)['data']
|
||||
|
||||
@@ -17,18 +17,18 @@
|
||||
) %}
|
||||
{% call row_heading() %}
|
||||
<span class="spark-bar-label">
|
||||
<a href="{{ url_for('.view_template', service_id=current_service.id, template_id=item.template.id) }}">{{ item.template.name }}</a>
|
||||
<a href="{{ url_for('.view_template', service_id=current_service.id, template_id=item.template_id) }}">{{ item.template_name }}</a>
|
||||
<span class="file-list-hint">
|
||||
{{ message_count_label(1, item.template.template_type, suffix='template')|capitalize }}
|
||||
{{ message_count_label(1, item.template_type, suffix='template')|capitalize }}
|
||||
</span>
|
||||
</span>
|
||||
{% endcall %}
|
||||
{% call field() %}
|
||||
{% if template_statistics|length > 1 %}
|
||||
<span class="spark-bar">
|
||||
<span style="width: {{ item.usage_count / most_used_template_count * 100 }}%">
|
||||
<span style="width: {{ item.count / most_used_template_count * 100 }}%">
|
||||
{{ big_number(
|
||||
item.usage_count,
|
||||
item.count,
|
||||
smallest=True
|
||||
) }}
|
||||
</span>
|
||||
@@ -36,7 +36,7 @@
|
||||
{% else %}
|
||||
<span class="heading-small">
|
||||
{{ big_number(
|
||||
item.usage_count,
|
||||
item.count,
|
||||
smallest=True
|
||||
) }}
|
||||
</span>
|
||||
|
||||
Reference in New Issue
Block a user