From 427ac0c8c10ab4ba68b814d43b68d98f4db19501 Mon Sep 17 00:00:00 2001 From: Ben Thorner Date: Mon, 23 Aug 2021 16:50:56 +0100 Subject: [PATCH] Fix misleading name for overlap method Resolves: https://github.com/alphagov/notifications-admin/pull/3980#discussion_r692919874 Previously it was unclear what kinds of areas this method returned, and whether there would be any duplicates (due to the hierarchy of areas we work with). This clarifies that. In addition, the areas returned may not overlap with the custom one [1], so we should reword to avoid falsely implying that. We could do the overlap check as part of the method as an alternative, but that would create extra work when calculating the ratio of intersection. We could always add "overlapping areas" as a complementary method to this one in future. [1]: https://github.com/alphagov/notifications-admin/pull/3980#discussion_r692919874 --- app/broadcast_areas/models.py | 5 +++-- tests/app/broadcast_areas/test_broadcast_area.py | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/broadcast_areas/models.py b/app/broadcast_areas/models.py index 105a456dc..d7776c4ed 100644 --- a/app/broadcast_areas/models.py +++ b/app/broadcast_areas/models.py @@ -163,10 +163,11 @@ class CustomBroadcastArea(BaseBroadcastArea): simple_polygons = polygons @cached_property - def overlapping_areas(self): + def nearby_electoral_wards(self): if not self.polygons: return [] return broadcast_area_libraries.get_areas_with_simple_polygons([ + # We only index electoral wards in the RTree overlap.data for overlap in rtree_index.query( Rect(*self.polygons.bounds) ) @@ -176,7 +177,7 @@ class CustomBroadcastArea(BaseBroadcastArea): def count_of_phones(self): return sum( area.simple_polygons.ratio_of_intersection_with(self.polygons) * area.count_of_phones - for area in self.overlapping_areas + for area in self.nearby_electoral_wards ) diff --git a/tests/app/broadcast_areas/test_broadcast_area.py b/tests/app/broadcast_areas/test_broadcast_area.py index 4c2af384b..ef862f10d 100644 --- a/tests/app/broadcast_areas/test_broadcast_area.py +++ b/tests/app/broadcast_areas/test_broadcast_area.py @@ -386,7 +386,7 @@ def test_count_of_phones_for_custom_area( ) assert sorted( - overlap.name for overlap in area.overlapping_areas + overlap.name for overlap in area.nearby_electoral_wards ) == expected_possible_overlaps assert close_enough(area.count_of_phones, expected_count_of_phones)