Merge pull request #412 from alphagov/aggregate-template-stats

Aggregation of template stats in admin app.
This commit is contained in:
Adam Shimali
2016-04-07 12:10:11 +01:00
3 changed files with 97 additions and 11 deletions

View File

@@ -35,7 +35,7 @@ def service_dashboard(service_id):
return redirect(url_for("main.tour", service_id=service_id, page=1))
statistics = statistics_api_client.get_statistics_for_service(service_id)['data']
template_statistics = template_statistics_client.get_template_statistics_for_service(service_id)
template_statistics = aggregate_usage(template_statistics_client.get_template_statistics_for_service(service_id))
return render_template(
'views/dashboard/dashboard.html',
@@ -53,7 +53,7 @@ def service_dashboard(service_id):
def service_dashboard_updates(service_id):
statistics = statistics_api_client.get_statistics_for_service(service_id)['data']
template_statistics = template_statistics_client.get_template_statistics_for_service(service_id)
template_statistics = aggregate_usage(template_statistics_client.get_template_statistics_for_service(service_id))
return jsonify(**{
'today': render_template(
@@ -87,3 +87,15 @@ def add_rates_to(delivery_statistics):
})
return latest_stats
def aggregate_usage(template_statistics):
import collections
stats = collections.OrderedDict()
for item in template_statistics:
stat = stats.get(item['template']['id'])
if stat:
stat['usage_count'] = stat['usage_count'] + item['usage_count']
else:
stats[item['template']['id']] = item
return stats.values()

View File

@@ -1,9 +1,9 @@
{% from "components/table.html" import list_table, field, right_aligned_field_heading %}
{% call(item, row_number) list_table(
template_statistics,
caption="Recent templates used",
caption="Recent templates last 7 days",
empty_message='You havent sent any batch messages yet',
field_headings=['Template', 'Type', 'Date', right_aligned_field_heading('Usage')]
field_headings=['Template', 'Type', right_aligned_field_heading('Usage')]
) %}
{% call field() %}
<a href="{{ url_for('.edit_service_template', service_id=current_service.id, template_id=item.template.id) }}">
@@ -13,9 +13,6 @@
{% call field() %}
{{item.template.template_type}}
{% endcall %}
{% call field() %}
{{item.day|format_date}}
{% endcall %}
{% call field(align='right') %}
{{ item.usage_count }}
{% endcall %}