Spaces:
Sleeping
Sleeping
ElvarThorS
commited on
Commit
·
cb29405
1
Parent(s):
d12fc4e
Added proportionality to age
Browse files
app/app.py
CHANGED
@@ -111,7 +111,7 @@ with ui.layout_columns(col_widths=[8, 4]):
|
|
111 |
station_coord = (y,x)
|
112 |
|
113 |
# Fetch age bracket data from the Data_provider instance
|
114 |
-
age_data = initBackend.get_station_score(station_coord)['age_data'] # Assume this returns a dictionary or DataFrame
|
115 |
|
116 |
# Example structure: {'0-4 ára': 120, '5-9 ára': 140, ...}
|
117 |
age_brackets = list(age_data.keys())
|
|
|
111 |
station_coord = (y,x)
|
112 |
|
113 |
# Fetch age bracket data from the Data_provider instance
|
114 |
+
age_data = initBackend.get_station_score(station_coord, radius=input.rad())['age_data'] # Assume this returns a dictionary or DataFrame
|
115 |
|
116 |
# Example structure: {'0-4 ára': 120, '5-9 ára': 140, ...}
|
117 |
age_brackets = list(age_data.keys())
|
app/data_processing/get_station_coverage.py
CHANGED
@@ -38,13 +38,17 @@ def get_station_coverage(
|
|
38 |
intersection = geometry.intersection(station_buffer)
|
39 |
intersection_area = intersection.area
|
40 |
|
41 |
-
# Calculate the percentage of the
|
42 |
coverage_percentage = (intersection_area / buffer_area) * 100
|
43 |
|
|
|
|
|
|
|
44 |
# Add the area and coverage percentage to the result
|
45 |
covered_areas.append({
|
46 |
"id": area["id"], # Include the area's ID or relevant metadata
|
47 |
-
"coverage_percentage": coverage_percentage
|
|
|
48 |
})
|
49 |
|
50 |
return covered_areas
|
|
|
38 |
intersection = geometry.intersection(station_buffer)
|
39 |
intersection_area = intersection.area
|
40 |
|
41 |
+
# Calculate the percentage of the radius covered by this area
|
42 |
coverage_percentage = (intersection_area / buffer_area) * 100
|
43 |
|
44 |
+
# Calculate the percentage of the area covered by the radius
|
45 |
+
small_zone_percentage = (intersection_area / geometry.area) * 100
|
46 |
+
|
47 |
# Add the area and coverage percentage to the result
|
48 |
covered_areas.append({
|
49 |
"id": area["id"], # Include the area's ID or relevant metadata
|
50 |
+
"coverage_percentage": coverage_percentage,
|
51 |
+
"small_zone_percentage": small_zone_percentage
|
52 |
})
|
53 |
|
54 |
return covered_areas
|
app/data_processing/point_scoring.py
CHANGED
@@ -39,14 +39,24 @@ def score_current(station_coord, df_features, cov_smsv, w_density, w_income, w_a
|
|
39 |
income_score = 0
|
40 |
density_score = 0
|
41 |
age_score = 0
|
42 |
-
|
43 |
-
|
44 |
|
|
|
45 |
smsv_info = df_features[df_features["smallAreaId"] == smsv["id"]]
|
46 |
|
|
|
47 |
age_dist = smsv_info["age_distribution"].iloc[0].get(2024, {}) # only interested in 2024 for current score
|
48 |
-
|
49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
|
51 |
income_dist = smsv_info["income_distribution_per_year"].iloc[0].get(2024, {}) # only interested in 2024 for current score
|
52 |
# print(data_2024)
|
@@ -54,9 +64,13 @@ def score_current(station_coord, df_features, cov_smsv, w_density, w_income, w_a
|
|
54 |
|
55 |
density_score = smsv_info["density"].iloc[0] * w_density
|
56 |
total_score += (age_score + income_score + density_score) * smsv["coverage_percentage"] # TODO: Area of the cricle * percent covered / total area of the small area
|
57 |
-
return {"total_score": total_score, "income_score": income_score, "age_score": age_score, "density_score": density_score, "age_data": age_dist}
|
58 |
|
59 |
-
|
|
|
|
|
|
|
|
|
|
|
60 |
"""
|
61 |
Calculate a score based on age distribution.
|
62 |
|
@@ -94,10 +108,10 @@ def get_age_score(age_distribution):
|
|
94 |
}
|
95 |
|
96 |
# Calculate the weighted sum of the age distribution
|
97 |
-
weighted_sum = sum(
|
98 |
|
99 |
# Normalize the score by the total population
|
100 |
-
total_population = sum(
|
101 |
if total_population == 0:
|
102 |
return 0
|
103 |
|
|
|
39 |
income_score = 0
|
40 |
density_score = 0
|
41 |
age_score = 0
|
42 |
+
aggregated_age_distribution = {}
|
|
|
43 |
|
44 |
+
for smsv in cov_smsv:
|
45 |
smsv_info = df_features[df_features["smallAreaId"] == smsv["id"]]
|
46 |
|
47 |
+
# Get age distribution for the year 2024
|
48 |
age_dist = smsv_info["age_distribution"].iloc[0].get(2024, {}) # only interested in 2024 for current score
|
49 |
+
|
50 |
+
# Aggregate proportional age distribution
|
51 |
+
for age_group, population in age_dist.items():
|
52 |
+
proportion = population * (smsv["small_zone_percentage"]/100)
|
53 |
+
if age_group in aggregated_age_distribution:
|
54 |
+
aggregated_age_distribution[age_group] += proportion
|
55 |
+
else:
|
56 |
+
aggregated_age_distribution[age_group] = proportion
|
57 |
+
|
58 |
+
|
59 |
+
|
60 |
|
61 |
income_dist = smsv_info["income_distribution_per_year"].iloc[0].get(2024, {}) # only interested in 2024 for current score
|
62 |
# print(data_2024)
|
|
|
64 |
|
65 |
density_score = smsv_info["density"].iloc[0] * w_density
|
66 |
total_score += (age_score + income_score + density_score) * smsv["coverage_percentage"] # TODO: Area of the cricle * percent covered / total area of the small area
|
|
|
67 |
|
68 |
+
# Calculate age score
|
69 |
+
age_score = get_age_score(aggregated_age_distribution) * w_age
|
70 |
+
total_score += age_score
|
71 |
+
return {"total_score": total_score, "income_score": income_score, "age_score": age_score, "density_score": density_score, "age_data": aggregated_age_distribution}
|
72 |
+
|
73 |
+
def get_age_score(proportional_age_distribution):
|
74 |
"""
|
75 |
Calculate a score based on age distribution.
|
76 |
|
|
|
108 |
}
|
109 |
|
110 |
# Calculate the weighted sum of the age distribution
|
111 |
+
weighted_sum = sum(proportional_age_distribution.get(age, 0) * weight for age, weight in age_weights.items())
|
112 |
|
113 |
# Normalize the score by the total population
|
114 |
+
total_population = sum(proportional_age_distribution.values())
|
115 |
if total_population == 0:
|
116 |
return 0
|
117 |
|