mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-07-12 01:14:11 -04:00
Support area aggregation for custom polygons
This commit is contained in:
@@ -1,8 +1,24 @@
|
||||
from app.broadcast_areas.models import CustomBroadcastArea
|
||||
|
||||
|
||||
def aggregate_areas(areas):
|
||||
areas = _convert_custom_areas_to_wards(areas)
|
||||
areas = _aggregate_wards_by_local_authority(areas)
|
||||
return areas
|
||||
|
||||
|
||||
def _convert_custom_areas_to_wards(areas):
|
||||
results = set()
|
||||
|
||||
for area in areas:
|
||||
if type(area) == CustomBroadcastArea:
|
||||
results |= set(area.overlapping_electoral_wards)
|
||||
else:
|
||||
results |= {area}
|
||||
|
||||
return results
|
||||
|
||||
|
||||
def _aggregate_wards_by_local_authority(areas):
|
||||
return {
|
||||
area.parent if area.id.startswith('wd20-')
|
||||
|
||||
@@ -69,3 +69,55 @@ def test_aggregate_areas(
|
||||
assert sorted(
|
||||
area.name for area in aggregate_areas(broadcast_message.areas)
|
||||
) == expected_area_names
|
||||
|
||||
|
||||
@pytest.mark.parametrize(('simple_polygons', 'expected_area_names'), [
|
||||
(
|
||||
[SKYE], [
|
||||
# Area covers a single unitary authority
|
||||
'Highland',
|
||||
]
|
||||
),
|
||||
(
|
||||
[BRISTOL], [
|
||||
# Area covers a single unitary authority
|
||||
'Bristol, City of',
|
||||
]
|
||||
),
|
||||
(
|
||||
[CHELTENHAM], [
|
||||
# Area covers three lower-tier authorities
|
||||
# in Gloucestershire (upper tier authority)
|
||||
'Cheltenham',
|
||||
'Cotswold',
|
||||
'Tewkesbury',
|
||||
]
|
||||
),
|
||||
(
|
||||
[BURFORD], [
|
||||
# Area covers two lower-tier authorities
|
||||
# in Gloucestershire (upper tier authority)
|
||||
'Cotswold',
|
||||
'West Oxfordshire',
|
||||
],
|
||||
),
|
||||
(
|
||||
[SANTA_A], [
|
||||
# Does not overlap with the UK
|
||||
],
|
||||
),
|
||||
])
|
||||
def test_aggregate_areas_for_custom_polygons(
|
||||
simple_polygons,
|
||||
expected_area_names,
|
||||
):
|
||||
broadcast_message = BroadcastMessage(
|
||||
broadcast_message_json(
|
||||
area_ids=['derived from polygons'],
|
||||
simple_polygons=simple_polygons
|
||||
)
|
||||
)
|
||||
|
||||
assert sorted(
|
||||
area.name for area in aggregate_areas(broadcast_message.areas)
|
||||
) == expected_area_names
|
||||
|
||||
Reference in New Issue
Block a user