Clarify comments for aggregation algorithm

In response to [1] and [2].

[1]: https://github.com/alphagov/notifications-admin/pull/4003#discussion_r695919270
[2]: https://github.com/alphagov/notifications-admin/pull/4003#discussion_r695920213
This commit is contained in:
Ben Thorner
2021-08-27 14:41:00 +01:00
parent de804805ac
commit a94291d5a4

View File

@@ -34,17 +34,17 @@ def _aggregate_lower_tier_authorities(areas):
clusters = _cluster_lower_tier_authorities(areas)
for cluster in clusters:
# always keep lone area as itself
# always show a single area cluster as itself (aggregation isn't helpful)
if len(cluster) == 1:
results |= set(cluster)
# aggregate multi-area cluster
# aggregate a single cluster with lots of areas (too complex to show in full)
elif len(cluster) > 3:
results |= {cluster[0].parent}
# aggregate many small clusters
# if cluster is 2 or 3 areas, and there are more than 1 cluster, aggregate the cluster
elif len(clusters) > 1:
area = cluster[0]
results |= {area.parent or area}
# keep one small cluster in full
# else keep single 2-3 areas cluster in full (easy enough to understand)
else:
results |= set(cluster)