Handle areas which don’t have population data

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.
This commit is contained in:
Chris Hill-Scott
2021-03-19 15:36:25 +00:00
parent 4367908269
commit a74db6eaa7
2 changed files with 7 additions and 1 deletions

View File

@@ -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))

View File

@@ -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,