From c3699e0e359bb519ff373caeee67e88d89546cf7 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Thu, 11 Mar 2021 13:23:02 +0000 Subject: [PATCH] Format numbers as millions or billions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This matches the existing performance platform page, and I think is a bit easier to read for high-level numbers where you don’t need to see that they’re changing second-by-second. --- app/__init__.py | 2 ++ app/formatters.py | 4 ++++ app/templates/views/performance.html | 8 ++++---- tests/app/main/views/test_performance.py | 8 ++++---- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/app/__init__.py b/app/__init__.py index e1ce3ccd5..fc9ad0a2d 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -38,6 +38,7 @@ from app.config import configs from app.extensions import antivirus_client, redis_client, zendesk_client from app.formatters import ( convert_to_boolean, + format_billions, format_date, format_date_human, format_date_normal, @@ -527,6 +528,7 @@ def setup_event_handlers(): def add_template_filters(application): for fn in [ + format_billions, format_datetime, format_datetime_24h, format_datetime_normal, diff --git a/app/formatters.py b/app/formatters.py index 2f9223a44..612e45113 100644 --- a/app/formatters.py +++ b/app/formatters.py @@ -515,3 +515,7 @@ def format_mobile_network(network): if network in ('three', 'vodafone', 'o2'): return network.capitalize() return 'EE' + + +def format_billions(count): + return humanize.intword(count) diff --git a/app/templates/views/performance.html b/app/templates/views/performance.html index 20e70551b..05235134c 100644 --- a/app/templates/views/performance.html +++ b/app/templates/views/performance.html @@ -22,28 +22,28 @@

Total messages

-
{{ total_notifications }}
+
{{ total_notifications|format_billions }}
total
{{ big_number( - email_notifications, + email_notifications|format_billions, label=email_notifications|message_count_noun('email'), smallest=True, ) }}
{{ big_number( - sms_notifications, + sms_notifications|format_billions, label=sms_notifications|message_count_noun('sms'), smallest=True, ) }}
{{ big_number( - letter_notifications, + letter_notifications|format_billions, label=letter_notifications|message_count_noun('letter'), smallest=True, ) }} diff --git a/tests/app/main/views/test_performance.py b/tests/app/main/views/test_performance.py index c6dc25074..6709d8b73 100644 --- a/tests/app/main/views/test_performance.py +++ b/tests/app/main/views/test_performance.py @@ -117,10 +117,10 @@ def test_should_render_performance_page( '' 'Messages sent since May 2016 ' 'Total messages ' - '1789000000 total ' - '1,123,000,000 emails ' - '987,654,321 text messages ' - '1,234,567 letters ' + '1.8 billion total ' + '1.1 billion emails ' + '987.7 million text messages ' + '1.2 million letters ' '' 'Date Emails Text messages Letters ' '21 February 2021 1,234,567 123,456 123 '