Skip to content

Commit

Permalink
update scripts to add 'use_nation_clause' option
Browse files Browse the repository at this point in the history
  • Loading branch information
chris48s committed Mar 19, 2020
1 parent c7da0ed commit cf2b828
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 11 deletions.
19 changes: 13 additions & 6 deletions scripts/country-gb/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
'gss_column': 'pcon18cd',
'name_column': 'pcon18nm',
'prefix': 'pcon',
'filename': 'uk_parliament_consitituencies.csv'
'filename': 'uk_parliament_consitituencies.csv',
'use_nation_clause': False,
}


Expand All @@ -17,15 +18,17 @@
'gss_column': 'spc16cd',
'name_column': 'spc16nm',
'prefix': 'spc',
'filename': 'scottish_parliament_consitituencies.csv'
'filename': 'scottish_parliament_consitituencies.csv',
'use_nation_clause': True,
}
spr = {
# data from: http://geoportal.statistics.gov.uk/datasets/scottish-parliamentary-regions-may-2016-full-extent-boundaries-in-scotland
'url': 'https://opendata.arcgis.com/datasets/c890fc7b1ad14311bb71660ec6524c9e_1.csv',
'gss_column': 'spr16cd',
'name_column': 'spr16nm',
'prefix': 'spr',
'filename': 'scottish_parliament_regions.csv'
'filename': 'scottish_parliament_regions.csv',
'use_nation_clause': True,
}


Expand All @@ -37,15 +40,17 @@
'gss_column': 'nawc17cd',
'name_column': 'nawc17nm',
'prefix': 'nawc',
'filename': 'naw_consitituencies.csv'
'filename': 'naw_consitituencies.csv',
'use_nation_clause': True,
}
nawr = {
# data from: http://geoportal.statistics.gov.uk/datasets/national-assembly-for-wales-electoral-regions-december-2017-wa-bfe
'url': 'https://opendata.arcgis.com/datasets/d10026914aa64c4cadcfafad73f81bf7_1.csv',
'gss_column': 'nawer17cd',
'name_column': 'nawer17nm',
'prefix': 'nawr',
'filename': 'naw_regions.csv'
'filename': 'naw_regions.csv',
'use_nation_clause': True,
}


Expand All @@ -56,7 +61,8 @@
'gss_column': 'cauth17cd',
'name_column': 'cauth17nm',
'prefix': 'cauth',
'filename': 'combined_authorities.csv'
'filename': 'combined_authorities.csv',
'use_nation_clause': False,
}


Expand All @@ -69,6 +75,7 @@
'name_column': 'pfa17nm',
'prefix': 'pfa',
'filename': 'police_force_areas.csv',
'use_nation_clause': False,
'exclude': [
# These areas don't elect a Police & Crime Commissioner:
'E23000001', # Metropolitan Police
Expand Down
28 changes: 23 additions & 5 deletions scripts/country-gb/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,39 @@ def gss_to_constituent_nation_id(gss):
return constituent_nations[gss[0]]


def make_id(prefix, gss, name):
return 'ocd-division/country:gb/part:{nation_id}/{prefix}:{slug}'.format(
nation_id=gss_to_constituent_nation_id(gss),
def make_id(prefix, gss, name, use_nation_clause):
if use_nation_clause:
return 'ocd-division/country:gb/part:{nation_id}/{prefix}:{slug}'.format(
nation_id=gss_to_constituent_nation_id(gss),
prefix=prefix,
slug=make_slug(name)
)
return 'ocd-division/country:gb/{prefix}:{slug}'.format(
prefix=prefix,
slug=make_slug(name)
)


def make_csv_for_area_type(url, gss_column, name_column, prefix, filename, exclude=[]):
def make_csv_for_area_type(
url,
gss_column,
name_column,
prefix,
filename,
use_nation_clause,
exclude=[]
):
in_rows = get_csv_data(url)
out_rows = []

for in_row in in_rows:
out_row = {}
out_row['id'] = make_id(prefix, in_row[gss_column], in_row[name_column])
out_row['id'] = make_id(
prefix,
in_row[gss_column],
in_row[name_column],
use_nation_clause,
)
out_row['name'] = in_row[name_column]
out_row['gss_code'] = in_row[gss_column]
if out_row['gss_code'] in exclude:
Expand Down

0 comments on commit cf2b828

Please sign in to comment.