Spaces:
Sleeping
Sleeping
Jan
commited on
Commit
·
9d4d6fa
1
Parent(s):
037aeab
increment in aggregate_data.py: implement calculating the age_distrbution using the smsv ids
Browse files
data_processing/aggregate_data.py
CHANGED
@@ -1,5 +1,7 @@
|
|
1 |
import csv
|
2 |
from age_distribution_by_id import get_age_distribution
|
|
|
|
|
3 |
|
4 |
# Small area id: id of the small area
|
5 |
# Density: current density of the small area
|
@@ -21,5 +23,8 @@ def open_file(filename):
|
|
21 |
except Exception as e:
|
22 |
print(f"An error occurred: {e}")
|
23 |
return []
|
24 |
-
|
|
|
|
|
|
|
25 |
|
|
|
1 |
import csv
|
2 |
from age_distribution_by_id import get_age_distribution
|
3 |
+
from get_smallAreaInfo import get_smallAreas
|
4 |
+
|
5 |
|
6 |
# Small area id: id of the small area
|
7 |
# Density: current density of the small area
|
|
|
23 |
except Exception as e:
|
24 |
print(f"An error occurred: {e}")
|
25 |
return []
|
26 |
+
|
27 |
+
# get list of smsv, each represented as {"id": smsv_id, "geometry": [(long, lat), ...]}
|
28 |
+
smsv_id_geom = get_smallAreas()
|
29 |
+
# get_age_distribution([2024] , [smsv["id"] for smsv in smsv_id_geom], "")
|
30 |
|
data_processing/get_smallAreaInfo.py
CHANGED
@@ -10,9 +10,8 @@ with open(file_path, 'r', encoding='utf-8') as file:
|
|
10 |
|
11 |
def get_smallAreas():
|
12 |
'''
|
13 |
-
Returns a list of
|
14 |
-
|
15 |
-
features in Höfuðborgarsvæði.
|
16 |
'''
|
17 |
# Extract smsv IDs and geometries for Höfuðborgarsvæði
|
18 |
hofudborgarsvaedi_areas = []
|
@@ -31,5 +30,9 @@ def get_smallAreas():
|
|
31 |
|
32 |
hofudborgarsvaedi_areas.append({"id": smsv, "geometry": processed_geometry})
|
33 |
|
|
|
|
|
|
|
|
|
34 |
|
35 |
return hofudborgarsvaedi_areas
|
|
|
10 |
|
11 |
def get_smallAreas():
|
12 |
'''
|
13 |
+
Returns a list of dict of format {"id": smsv_id, "geometry": [(long, lat), ...]}
|
14 |
+
for all smsv in in Höfuðborgarsvæði.
|
|
|
15 |
'''
|
16 |
# Extract smsv IDs and geometries for Höfuðborgarsvæði
|
17 |
hofudborgarsvaedi_areas = []
|
|
|
30 |
|
31 |
hofudborgarsvaedi_areas.append({"id": smsv, "geometry": processed_geometry})
|
32 |
|
33 |
+
ids = [area["id"] for area in hofudborgarsvaedi_areas]
|
34 |
+
if len(ids) != len(set(ids)):
|
35 |
+
duplicates = [smsv for smsv in ids if ids.count(smsv) > 1]
|
36 |
+
raise ValueError(f"Duplicate IDs found: {set(duplicates)}")
|
37 |
|
38 |
return hofudborgarsvaedi_areas
|