This repository was archived by the owner on Jul 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunsd_publish08.py
87 lines (61 loc) · 2.82 KB
/
unsd_publish08.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import set_release
import metadata
import utils
# *******************************************************************
# Write final csv files to data/processed
# *******************************************************************
release = set_release.set_release()
sdg_meta = utils.open_json('data/external/metadata_' + release + '.json')
# print(sdg_meta[0].keys())
for g in sdg_meta:
# if g['code'] != '1':
# continue
goal_code = g['code']
goal_labelEN = g['labelEN']
goal_descEN = g['descEN']
for t in g['targets']:
# if t['code'] != '1.1':
# continue
target_code = t['code']
target_descEN = t['descEN']
for i in t['indicators']:
# if i['reference'] != '1.1.1':
# continue
indicator_code = utils.clean_str(i['code'])
indicator_reference = utils.clean_str(i['reference'])
indicator_descEN = utils.clean_str(i['descEN'])
for s in i['series']:
# Use this for release 2020.Q1.G.01
# if s['code'] == 'SE_ADT_ACTS':
# continue
series_code = utils.clean_str(s['code'])
series_description = utils.clean_str(s['description'])
series_release = utils.clean_str(s['release'])
series_tags = utils.clean_str(s['tags'])
file_pivot = 'data/interim/' + release + \
'/pivot/PivotSeries_' + series_code + '.txt'
data = utils.tsv2dictlist(file_pivot)
new_data = []
for r in data:
d = dict()
d['goal_code'] = goal_code
d['goal_labelEN'] = goal_labelEN
d['goal_descEN'] = goal_descEN
d['target_code'] = target_code
d['target_descEN'] = target_descEN
d['indicator_code'] = indicator_code
d['indicator_reference'] = indicator_reference
d['indicator_descEN'] = indicator_descEN
d['series_release'] = series_release
d['series_tags'] = series_tags
for k, v in r.items():
d[k] = utils.clean_str(v)
new_data.append(d)
# print(new_data[0])
# Note: ArcGIS only accepts .csv extension (even if it's tab-delimited)
file_out = 'data/processed/' + release + '/Indicator_' + \
indicator_reference.replace(
'.', '_') + '__Series_' + series_code + '.csv'
# It thas to be tab-delimited, in order to be able to deal with commans within strings.
utils.dictList2tsv(new_data, file_out)
print(f'--finished processing file {file_out}')