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
This commit is contained in:
Ben Thorner
2021-08-23 16:50:56 +01:00
parent d2784d0d8a
commit 427ac0c8c1
2 changed files with 4 additions and 3 deletions

View File

@@ -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
)

View File

@@ -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)