Refactor logic to identify types of areas

I did consider whether to store this explicitly in the SQLite DB,
but this is less effort for now and we can always switch to that
more robust approach in future if we need to.
This commit is contained in:
Ben Thorner
2021-08-24 16:06:46 +01:00
parent bcfa21428f
commit de804805ac
2 changed files with 10 additions and 2 deletions

View File

@@ -86,6 +86,14 @@ class BroadcastArea(BaseBroadcastArea, SortableMixin):
def __init__(self, row):
self.id, self.name, self._count_of_phones, self.library_id = row
@cached_property
def is_lower_tier_local_authority(self):
return self.id.startswith('lad20-') and self.parent
@cached_property
def is_electoral_ward(self):
return self.id.startswith('wd20-')
@classmethod
def from_row_with_simple_polygons(cls, row):
instance = cls(row[:4])

View File

@@ -24,7 +24,7 @@ def _convert_custom_areas_to_wards(areas):
def _aggregate_wards_by_local_authority(areas):
return {
area.parent if area.id.startswith('wd20-')
area.parent if area.is_electoral_ward
else area for area in areas
}
@@ -56,7 +56,7 @@ def _cluster_lower_tier_authorities(areas):
for area in areas:
# group lower tier authorities by "county"
if area.id.startswith('lad20-') and area.parent:
if area.is_lower_tier_local_authority:
result[area.parent] += [area]
# leave countries, unitary authorities as-is
else: