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) def get_monthly_template_stats(month_name, stats): return { 'name': month_name, 'templates_used': [ { 'id': stat['template_id'], 'name': stat['name'], 'type': stat['type'], 'requested_count': stat['count'] } for stat in stats if calendar.month_name[int(stat['month'])] == month_name ], } months = [ get_monthly_template_stats(month, stats) for month in get_months_for_financial_year(year, time_format='%B') ] 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_usage', service_id=service_id), start=current_financial_year - 2, end=current_financial_year, ), selected_year=year )
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) def get_monthly_template_stats(month_name, stats): return { "name": month_name, "templates_used": [{ "id": stat["template_id"], "name": stat["name"], "type": stat["type"], "requested_count": stat["count"], } for stat in stats if calendar.month_name[int(stat["month"])] == month_name], } months = [ get_monthly_template_stats(month, stats) for month in get_months_for_financial_year(year, time_format="%B") ] return render_template( "views/dashboard/all-template-statistics.html", months=reversed(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_usage", service_id=service_id), start=current_financial_year - 2, end=current_financial_year, ), selected_year=year, )