Merge pull request #3617 from alphagov/population-estimates

Give estimates of the number of phones in a broadcast area
This commit is contained in:
Chris Hill-Scott
2020-09-17 11:41:00 +01:00
committed by GitHub
16 changed files with 9923 additions and 21 deletions

View File

@@ -3,6 +3,7 @@ from notifications_utils.serialised_model import SerialisedModelCollection
from werkzeug.utils import cached_property
from .polygons import Polygons
from .populations import CITY_OF_LONDON
from .repo import BroadcastAreasRepository
@@ -28,7 +29,7 @@ class GetItemByIdMixin:
class BroadcastArea(SortableMixin):
def __init__(self, row):
self.id, self.name = row
self.id, self.name, self._count_of_phones = row
def __eq__(self, other):
return self.id == other.id
@@ -52,6 +53,18 @@ class BroadcastArea(SortableMixin):
for row in BroadcastAreasRepository().get_all_areas_for_group(self.id)
]
@property
def count_of_phones(self):
if self.id.endswith(CITY_OF_LONDON.WARDS):
return CITY_OF_LONDON.DAYTIME_POPULATION * (
self.polygons.estimated_area / CITY_OF_LONDON.AREA_SQUARE_MILES
)
if self.sub_areas:
return sum(area.count_of_phones for area in self.sub_areas)
# TODO: remove the `or 0` once missing data is fixed, see
# https://www.pivotaltracker.com/story/show/174837293
return self._count_of_phones or 0
class BroadcastAreaLibrary(SerialisedModelCollection, SortableMixin, GetItemByIdMixin):