From 4367908269ed93653ba2d873989400069c6d1653 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Fri, 19 Mar 2021 15:28:13 +0000 Subject: [PATCH] Add limits to max/min bleed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This prevents us from giving unrealistically large or small bleed estimates in case we have areas which are more dense or less dense than the most/least dense areas we currently have. Also means we don’t have to treat City of London as a special case. --- app/broadcast_areas/__init__.py | 5 ++--- tests/app/broadcast_areas/test_broadcast_area.py | 4 ++-- tests/app/main/views/test_broadcast.py | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/app/broadcast_areas/__init__.py b/app/broadcast_areas/__init__.py index c9e40ec89..338763fe3 100644 --- a/app/broadcast_areas/__init__.py +++ b/app/broadcast_areas/__init__.py @@ -80,9 +80,8 @@ class BroadcastArea(SortableMixin): @property def estimated_bleed_in_m(self): - if self.id.endswith(CITY_OF_LONDON.WARDS): - return 500 - return 5_900 - (math.log(self.phone_density, 10) * 1_250) + estimated_bleed = 5_900 - (math.log(self.phone_density, 10) * 1_250) + return max(500, min(estimated_bleed, 5000)) @property def estimated_bleed_in_degrees(self): diff --git a/tests/app/broadcast_areas/test_broadcast_area.py b/tests/app/broadcast_areas/test_broadcast_area.py index 7c904ce55..705916cb5 100644 --- a/tests/app/broadcast_areas/test_broadcast_area.py +++ b/tests/app/broadcast_areas/test_broadcast_area.py @@ -315,7 +315,7 @@ def test_phone_density( @pytest.mark.parametrize('area, expected_bleed_in_m, expected_bleed_in_degrees', ( ( # Islington (most dense in UK) - 'lad20-E09000019', 488, 0.00439 + 'lad20-E09000019', 500, 0.00449 ), ( # Cordwainer Ward (City of London) @@ -332,7 +332,7 @@ def test_phone_density( ), ( # Highland (least dense in UK) - 'lad20-S12000017', 5_095, 0.0458 + 'lad20-S12000017', 5_000, 0.0449 ), )) def test_estimated_bleed( diff --git a/tests/app/main/views/test_broadcast.py b/tests/app/main/views/test_broadcast.py index ba473e376..2fa9a5140 100644 --- a/tests/app/main/views/test_broadcast.py +++ b/tests/app/main/views/test_broadcast.py @@ -649,7 +649,7 @@ def test_broadcast_page( 'Islington remove', ], [ 'An area of 9.7 square miles Will get the alert', - 'An extra area of 4.6 square miles is Likely to get the alert', + 'An extra area of 4.7 square miles is Likely to get the alert', '200,000 to 300,000 phones', ]), ))