mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-05-22 17:53:48 -04:00
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:
@@ -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))
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user