From a74db6eaa71411f01785a720b4e6994a740f993e Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Fri, 19 Mar 2021 15:36:25 +0000 Subject: [PATCH] =?UTF-8?q?Handle=20areas=20which=20don=E2=80=99t=20have?= =?UTF-8?q?=20population=20data?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If an area has a `count_of_phones` value of `0` it means we don’t have data about the population. This means we can’t do the maths to work out the estimated bleed. So we should return the default amount of bleed of 1,500m instead, which is something in between what we’d expect for a built up area and a rural area. --- app/broadcast_areas/__init__.py | 4 +++- tests/app/broadcast_areas/test_broadcast_area.py | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/broadcast_areas/__init__.py b/app/broadcast_areas/__init__.py index 338763fe3..54022216b 100644 --- a/app/broadcast_areas/__init__.py +++ b/app/broadcast_areas/__init__.py @@ -74,12 +74,14 @@ class BroadcastArea(SortableMixin): # https://www.pivotaltracker.com/story/show/174837293 return self._count_of_phones or 0 - @property + @cached_property def phone_density(self): return self.count_of_phones / self.polygons.estimated_area @property def estimated_bleed_in_m(self): + if self.phone_density < 1: + return Polygons.approx_bleed_in_degrees * Polygons.approx_metres_to_degree estimated_bleed = 5_900 - (math.log(self.phone_density, 10) * 1_250) return max(500, min(estimated_bleed, 5000)) diff --git a/tests/app/broadcast_areas/test_broadcast_area.py b/tests/app/broadcast_areas/test_broadcast_area.py index 705916cb5..02d84f3da 100644 --- a/tests/app/broadcast_areas/test_broadcast_area.py +++ b/tests/app/broadcast_areas/test_broadcast_area.py @@ -334,6 +334,10 @@ def test_phone_density( # Highland (least dense in UK) 'lad20-S12000017', 5_000, 0.0449 ), + ( + # No population data available + 'test-santa-claus-village-rovaniemi', 1_500, 0.01347 + ) )) def test_estimated_bleed( area, expected_bleed_in_m, expected_bleed_in_degrees,