Merge pull request #3868 from alphagov/add-another-test-area

Add another area to the library of test polygons
This commit is contained in:
Chris Hill-Scott
2021-05-11 15:47:01 +01:00
committed by GitHub
5 changed files with 72 additions and 1 deletions

View File

@@ -88,6 +88,7 @@ def estimate_number_of_smartphones_in_area(country_or_ward_code):
test_filepath = source_files_path / "Test.geojson" test_filepath = source_files_path / "Test.geojson"
demo_filepath = source_files_path / "Demo.geojson"
ctry19_filepath = source_files_path / "Countries.geojson" ctry19_filepath = source_files_path / "Countries.geojson"
# https://geoportal.statistics.gov.uk/datasets/wards-may-2020-boundaries-uk-bgc # https://geoportal.statistics.gov.uk/datasets/wards-may-2020-boundaries-uk-bgc
@@ -181,6 +182,41 @@ def add_test_areas():
repo.insert_broadcast_areas(areas_to_add, keep_old_polygons) repo.insert_broadcast_areas(areas_to_add, keep_old_polygons)
def add_demo_areas():
dataset_id = 'demo'
dataset_geojson = geojson.loads(demo_filepath.read_text())
repo.insert_broadcast_area_library(
dataset_id,
name='Demo areas',
name_singular='demo area',
is_group=False,
)
areas_to_add = []
for feature in dataset_geojson["features"]:
f_id = feature["properties"]['id']
f_name = feature["properties"]['name']
f_count_of_phones = feature["properties"]['count_of_phones']
print() # noqa: T001
print(f_name) # noqa: T001
feature, _ = polygons_and_simplified_polygons(
feature["geometry"]
)
print(' Phones: ', f_count_of_phones) # noqa: T001
areas_to_add.append([
f'{dataset_id}-{f_id}', f_name,
dataset_id, None,
feature, feature,
f_count_of_phones,
])
repo.insert_broadcast_areas(areas_to_add, keep_old_polygons)
def add_countries(): def add_countries():
dataset_id = 'ctry19' dataset_id = 'ctry19'
dataset_geojson = geojson.loads(ctry19_filepath.read_text()) dataset_geojson = geojson.loads(ctry19_filepath.read_text())
@@ -330,6 +366,7 @@ else:
repo.delete_db() repo.delete_db()
repo.create_tables() repo.create_tables()
add_test_areas() add_test_areas()
add_demo_areas()
add_countries() add_countries()
add_wards_local_authorities_and_counties() add_wards_local_authorities_and_counties()

View File

@@ -0,0 +1,24 @@
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"id": "sizewell",
"name": "Sizewell",
"count_of_phones": 700
},
"geometry": {
"type": "Polygon",
"coordinates": [[
[1.58242, 52.22035],
[1.58491, 52.19521],
[1.59971, 52.19325],
[1.62352, 52.19372],
[1.62599, 52.21901],
[1.58242, 52.22035]
]]
}
}
]
}

View File

@@ -27,6 +27,11 @@ def test_loads_libraries():
'Countries', 'Countries',
False, False,
), ),
(
'demo',
'Demo areas',
False,
),
( (
'wd20-lad20-ctyua19', 'wd20-lad20-ctyua19',
'Local authorities', 'Local authorities',
@@ -159,9 +164,10 @@ def test_repository_has_all_libraries():
repo = BroadcastAreasRepository() repo = BroadcastAreasRepository()
libraries = repo.get_libraries() libraries = repo.get_libraries()
assert len(libraries) == 3 assert len(libraries) == 4
assert [ assert [
('Countries', 'country'), ('Countries', 'country'),
('Demo areas', 'demo area'),
('Test areas', 'test area'), ('Test areas', 'test area'),
('Local authorities', 'local authority'), ('Local authorities', 'local authority'),
] == [(name, name_singular) for _, name, name_singular, _is_group in libraries] ] == [(name, name_singular) for _, name, name_singular, _is_group in libraries]

View File

@@ -900,6 +900,7 @@ def test_preview_broadcast_areas_page_with_custom_polygons(
@pytest.mark.parametrize('areas, expected_list', ( @pytest.mark.parametrize('areas, expected_list', (
([], [ ([], [
'Countries', 'Countries',
'Demo areas',
'Local authorities', 'Local authorities',
'Test areas', 'Test areas',
]), ]),
@@ -909,6 +910,7 @@ def test_preview_broadcast_areas_page_with_custom_polygons(
'ctry19-S92000003', 'ctry19-S92000003',
], [ ], [
'Countries', 'Countries',
'Demo areas',
'Local authorities', 'Local authorities',
'Test areas', 'Test areas',
]), ]),
@@ -919,6 +921,7 @@ def test_preview_broadcast_areas_page_with_custom_polygons(
'lad20-E06000052', # Cornwall, a unitary authority 'lad20-E06000052', # Cornwall, a unitary authority
], [ ], [
'Countries', 'Countries',
'Demo areas',
'Local authorities', 'Local authorities',
'Test areas', 'Test areas',
]), ]),
@@ -936,6 +939,7 @@ def test_preview_broadcast_areas_page_with_custom_polygons(
'Shetland Islands', 'Shetland Islands',
# --- # ---
'Countries', 'Countries',
'Demo areas',
'Local authorities', 'Local authorities',
'Test areas', 'Test areas',
]), ]),