From f553158846f7a77b272c3004ab83a9c0b2fefdcf Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Tue, 8 Sep 2020 16:35:03 +0100 Subject: [PATCH] Add estimated areas for non-visual users MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since the key relies on visual association between the shapes on the maps and the styling of the key, it won’t work for non-visual users. An alternative way of giving them the same information is by providing the size of the area numerically. --- app/broadcast_areas/polygons.py | 9 ++++++++ .../views/broadcast/macros/area-map.html | 23 +++++++++++++++++++ .../views/broadcast/preview-areas.html | 11 ++------- .../views/broadcast/view-message.html | 3 ++- tests/app/main/views/test_broadcast.py | 20 +++++++++++++++- 5 files changed, 55 insertions(+), 11 deletions(-) create mode 100644 app/templates/views/broadcast/macros/area-map.html diff --git a/app/broadcast_areas/polygons.py b/app/broadcast_areas/polygons.py index 53cdf32fa..f6fcd328f 100644 --- a/app/broadcast_areas/polygons.py +++ b/app/broadcast_areas/polygons.py @@ -14,6 +14,9 @@ class Polygons(): approx_metres_to_degree = 111_320 approx_square_metres_to_square_degree = approx_metres_to_degree ** 2 + square_degrees_to_square_miles = ( + approx_square_metres_to_square_degree / (1000 * 1000) * 0.386102 + ) # Estimated amount of bleed into neigbouring areas based on typical # range/separation of cell towers. @@ -161,6 +164,12 @@ class Polygons(): def point_count(self): return len(list(itertools.chain(*self.as_coordinate_pairs_long_lat))) + @property + def estimated_area(self): + return sum( + polygon.area for polygon in self + ) * self.square_degrees_to_square_miles + def flatten_polygons(polygons): if isinstance(polygons, GeometryCollection): diff --git a/app/templates/views/broadcast/macros/area-map.html b/app/templates/views/broadcast/macros/area-map.html new file mode 100644 index 000000000..67d0cce94 --- /dev/null +++ b/app/templates/views/broadcast/macros/area-map.html @@ -0,0 +1,23 @@ +{% macro map(broadcast_message) %} +
+ +{% endmacro %} diff --git a/app/templates/views/broadcast/preview-areas.html b/app/templates/views/broadcast/preview-areas.html index 83a231876..9e1efad65 100644 --- a/app/templates/views/broadcast/preview-areas.html +++ b/app/templates/views/broadcast/preview-areas.html @@ -1,6 +1,7 @@ {% from "components/button/macro.njk" import govukButton %} {% from "components/page-header.html" import page_header %} {% from "components/page-footer.html" import page_footer %} +{% from "views/broadcast/macros/area-map.html" import map %} {% extends "withnav_template.html" %} @@ -51,15 +52,7 @@ {% endfor %} {% if broadcast_message.areas %} -
-
-
- Will get alert -
-
- Likely to get alert -
-
+ {{ map(broadcast_message) }}
{{ page_footer('Continue to preview') }}
diff --git a/app/templates/views/broadcast/view-message.html b/app/templates/views/broadcast/view-message.html index 29db61202..236090bc5 100644 --- a/app/templates/views/broadcast/view-message.html +++ b/app/templates/views/broadcast/view-message.html @@ -5,6 +5,7 @@ {% from "components/banner.html" import banner %} {% from "components/page-header.html" import page_header %} {% from "components/page-footer.html" import page_footer %} +{% from "views/broadcast/macros/area-map.html" import map %} {% extends "withnav_template.html" %} @@ -139,7 +140,7 @@ {{ govukDetails({ "summaryText": "Show map", - "html": '
' + "html": map(broadcast_message) }) }} {{ broadcast_message.template|string }} diff --git a/tests/app/main/views/test_broadcast.py b/tests/app/main/views/test_broadcast.py index 37b8d7ce6..41bbde824 100644 --- a/tests/app/main/views/test_broadcast.py +++ b/tests/app/main/views/test_broadcast.py @@ -331,12 +331,30 @@ def test_preview_broadcast_areas_page( mock_get_draft_broadcast_message, ): service_one['permissions'] += ['broadcast'] - client_request.get( + page = client_request.get( '.preview_broadcast_areas', service_id=SERVICE_ONE_ID, broadcast_message_id=fake_uuid, ) + assert [ + normalize_spaces(item.text) + for item in page.select('ul.area-list li.area-list-item') + ] == [ + 'England remove', + 'Scotland remove', + ] + + assert len(page.select('#map')) == 1 + + assert [ + normalize_spaces(item.text) + for item in page.select('ul li.area-key') + ] == [ + 'An area of 176,714.9 square miles Will get the alert', + 'An extra area of 3,052.8 square miles is Likely to get the alert', + ] + def test_choose_broadcast_library_page( client_request,