Limit templates usage on dashboard to last 7 days

Previous the table of templates on the dashboard was for all time.
This commit uses the `limit_days` parameter of the API endpoint to only
show template usage from the last 7 days, aligning with the big numbers
shown above.
This commit is contained in:
Chris Hill-Scott
2016-04-20 13:59:24 +01:00
parent 75214f7e54
commit 312a903e65
5 changed files with 21 additions and 16 deletions

View File

@@ -38,13 +38,8 @@ def service_dashboard(service_id):
return render_template(
'views/dashboard/dashboard.html',
statistics=add_rates_to(
statistics_api_client.get_statistics_for_service(service_id, limit_days=7)['data']
),
templates=service_api_client.get_service_templates(service_id)['data'],
template_statistics=aggregate_usage(
template_statistics_client.get_template_statistics_for_service(service_id)
)
**get_dashboard_statistics_for_service(service_id)
)
@@ -54,12 +49,7 @@ def service_dashboard_updates(service_id):
return jsonify(**{
'today': render_template(
'views/dashboard/today.html',
statistics=add_rates_to(
statistics_api_client.get_statistics_for_service(service_id, limit_days=7)['data']
),
template_statistics=aggregate_usage(
template_statistics_client.get_template_statistics_for_service(service_id)
)
**get_dashboard_statistics_for_service(service_id)
)
})
@@ -125,3 +115,14 @@ def aggregate_usage(template_statistics):
key=lambda row: row['usage_count'],
reverse=True
)
def get_dashboard_statistics_for_service(service_id):
return {
'statistics': add_rates_to(
statistics_api_client.get_statistics_for_service(service_id, limit_days=7)['data']
),
'template_statistics': aggregate_usage(
template_statistics_client.get_template_statistics_for_service(service_id, limit_days=7)
)
}