mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-08 08:28:15 -04:00
move add steps into separate functions
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
import csv
|
import csv
|
||||||
from copy import deepcopy
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import geojson
|
import geojson
|
||||||
@@ -88,7 +87,7 @@ la_code_to_cty_id_mapping = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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())
|
||||||
repo.insert_broadcast_area_library(
|
repo.insert_broadcast_area_library(
|
||||||
@@ -118,7 +117,7 @@ def _add_countries():
|
|||||||
repo.insert_broadcast_areas(areas_to_add)
|
repo.insert_broadcast_areas(areas_to_add)
|
||||||
|
|
||||||
|
|
||||||
def _add_wards_local_authorities_and_counties():
|
def add_wards_local_authorities_and_counties():
|
||||||
dataset_name = "Local authorities"
|
dataset_name = "Local authorities"
|
||||||
dataset_name_singular = "local authority"
|
dataset_name_singular = "local authority"
|
||||||
dataset_id = "wd20-lad20-ctyua19"
|
dataset_id = "wd20-lad20-ctyua19"
|
||||||
@@ -130,15 +129,15 @@ def _add_wards_local_authorities_and_counties():
|
|||||||
)
|
)
|
||||||
_add_electoral_wards(dataset_id)
|
_add_electoral_wards(dataset_id)
|
||||||
_add_local_authorities(dataset_id)
|
_add_local_authorities(dataset_id)
|
||||||
_add_wards_local_authorities_and_counties(dataset_id)
|
_add_counties_and_unitary_authorities(dataset_id)
|
||||||
|
|
||||||
|
|
||||||
def _add_electoral_wards(dataset_id):
|
def _add_electoral_wards(dataset_id):
|
||||||
areas_to_add = []
|
areas_to_add = []
|
||||||
|
|
||||||
for f in geojson.loads(wd20_filepath.read_text())["features"]:
|
for feature in geojson.loads(wd20_filepath.read_text())["features"]:
|
||||||
ward_code = f["properties"]["wd20cd"]
|
ward_code = feature["properties"]["wd20cd"]
|
||||||
ward_name = f["properties"]["wd20nm"]
|
ward_name = feature["properties"]["wd20nm"]
|
||||||
ward_id = "wd20-" + ward_code
|
ward_id = "wd20-" + ward_code
|
||||||
|
|
||||||
print() # noqa: T001
|
print() # noqa: T001
|
||||||
@@ -146,9 +145,9 @@ def _add_electoral_wards(dataset_id):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
la_id = "lad20-" + ward_code_to_la_id_mapping[ward_code]
|
la_id = "lad20-" + ward_code_to_la_id_mapping[ward_code]
|
||||||
la_name = ward_code_to_la_mapping[ward_code]
|
|
||||||
feature, simple_feature = (
|
feature, simple_feature = (
|
||||||
polygons_and_simplified_polygons(f["geometry"])
|
polygons_and_simplified_polygons(feature["geometry"])
|
||||||
)
|
)
|
||||||
|
|
||||||
areas_to_add.append([
|
areas_to_add.append([
|
||||||
@@ -167,11 +166,12 @@ def _add_local_authorities(dataset_id):
|
|||||||
areas_to_add = []
|
areas_to_add = []
|
||||||
|
|
||||||
for feature in geojson.loads(lad20_filepath.read_text())["features"]:
|
for feature in geojson.loads(lad20_filepath.read_text())["features"]:
|
||||||
print() # noqa: T001
|
|
||||||
print(group_name) # noqa: T001
|
|
||||||
la_id = feature["properties"]["lad20cd"]
|
la_id = feature["properties"]["lad20cd"]
|
||||||
group_name = feature["properties"]["lad20nm"]
|
group_name = feature["properties"]["lad20nm"]
|
||||||
|
|
||||||
|
print() # noqa: T001
|
||||||
|
print(group_name) # noqa: T001
|
||||||
|
|
||||||
group_id = "lad20-" + la_id
|
group_id = "lad20-" + la_id
|
||||||
|
|
||||||
feature, simple_feature = (
|
feature, simple_feature = (
|
||||||
@@ -179,8 +179,6 @@ def _add_local_authorities(dataset_id):
|
|||||||
)
|
)
|
||||||
|
|
||||||
ctyua_id = la_code_to_cty_id_mapping.get(la_id)
|
ctyua_id = la_code_to_cty_id_mapping.get(la_id)
|
||||||
if ctyua_id:
|
|
||||||
print(f'{group_id} {group_name} is part of {ctyua_id}') # noqa: T001
|
|
||||||
areas_to_add.append([
|
areas_to_add.append([
|
||||||
group_id,
|
group_id,
|
||||||
group_name,
|
group_name,
|
||||||
@@ -199,8 +197,6 @@ def _add_counties_and_unitary_authorities(dataset_id):
|
|||||||
ctyua_id = feature["properties"]["ctyua19cd"]
|
ctyua_id = feature["properties"]["ctyua19cd"]
|
||||||
group_name = feature["properties"]["ctyua19nm"]
|
group_name = feature["properties"]["ctyua19nm"]
|
||||||
|
|
||||||
print('County/Unitary Authority', group_name) # noqa: T001
|
|
||||||
|
|
||||||
la_id = 'lad20-' + ctyua_id
|
la_id = 'lad20-' + ctyua_id
|
||||||
if repo.get_areas([la_id]):
|
if repo.get_areas([la_id]):
|
||||||
continue
|
continue
|
||||||
@@ -223,8 +219,8 @@ def _add_counties_and_unitary_authorities(dataset_id):
|
|||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
repo.delete_db()
|
repo.delete_db()
|
||||||
repo.create_tables()
|
repo.create_tables()
|
||||||
_add_countries()
|
add_countries()
|
||||||
_add_wards_local_authorities_and_counties()
|
add_wards_local_authorities_and_counties()
|
||||||
|
|
||||||
most_detailed_polygons = formatted_list(
|
most_detailed_polygons = formatted_list(
|
||||||
sorted(point_counts, reverse=True)[:5],
|
sorted(point_counts, reverse=True)[:5],
|
||||||
|
|||||||
Reference in New Issue
Block a user