use new detailed service endpoint for dashboard totals

we don't want to use the old statistics endpoints any more
also a couple of quality of life changes
* moves some logic out of the _totals.html template
* tidies up statistics_utils
This commit is contained in:
Leo Hemsted
2016-07-19 17:10:48 +01:00
parent 4451a8634d
commit 3e6eedd079
5 changed files with 49 additions and 45 deletions

View File

@@ -31,18 +31,12 @@ def sum_of_statistics(delivery_statistics):
def add_rates_to(delivery_statistics):
return dict(
emails_failure_rate=(
"{0:.1f}".format(
float(delivery_statistics['emails_failed']) / delivery_statistics['emails_requested'] * 100
)
if delivery_statistics['emails_requested'] else 0
),
sms_failure_rate=(
"{0:.1f}".format(
float(delivery_statistics['sms_failed']) / delivery_statistics['sms_requested'] * 100
)
if delivery_statistics['sms_requested'] else 0
),
email_failure_rate=get_formatted_percentage(
delivery_statistics['email_failed'],
delivery_statistics['email_requested']),
sms_failure_rate=get_formatted_percentage(
delivery_statistics['sms_failed'],
delivery_statistics['sms_requested']),
week_end_datetime=parser.parse(
delivery_statistics.get('week_end', str(datetime.utcnow()))
),
@@ -50,6 +44,13 @@ def add_rates_to(delivery_statistics):
)
def get_formatted_percentage(x, tot):
"""
Return a percentage to one decimal place (respecting )
"""
return "{0:.1f}".format((float(x) / tot * 100)) if tot else 0
def statistics_by_state(statistics):
return {
'sms': {