Spaces:
Sleeping
Sleeping
nastasiasnk
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -62,55 +62,9 @@ def test(input_json):
|
|
62 |
|
63 |
def accessibilityToLivability (DistanceMatrix,subdomainsAccessibility, SubdomainAttributeDict):
|
64 |
|
65 |
-
"""
|
66 |
-
Converts accessibility measures into livability scores for various urban subdomains
|
67 |
-
using a specified scaling mechanism based on predefined thresholds and maximum points.
|
68 |
-
|
69 |
-
This function takes a DataFrame of total accessibility per subdomain and remaps these values
|
70 |
-
into livability scores based on thresholds and maximum scores provided in a dictionary.
|
71 |
-
The output DataFrame retains the original order of indices from a reference distance matrix.
|
72 |
-
New columns for combined values such as 'social infrastructure' and 'transportation' are added,
|
73 |
-
aggregating scores from relevant subdomains.
|
74 |
-
|
75 |
-
Parameters:
|
76 |
-
- DistanceMatrix (pd.DataFrame): DataFrame used to maintain the order of indices.
|
77 |
-
- totalAccessibility (pd.DataFrame): DataFrame containing accessibility scores for various subdomains.
|
78 |
-
- SubdomainAttributeDict (dict): Dictionary where each key is a subdomain and each value is a list
|
79 |
-
where the first element is the minimum threshold for good accessibility, and the second element is
|
80 |
-
the maximum livability score for that threshold.
|
81 |
-
|
82 |
-
Returns:
|
83 |
-
- pd.DataFrame: A new DataFrame with the same indices as DistanceMatrix and columns corresponding to
|
84 |
-
totalAccessibility, enhanced with additional columns for combined livability metrics.
|
85 |
-
|
86 |
-
The function processes each subdomain defined in SubdomainAttributeDict. If the accessibility in a
|
87 |
-
subdomain exceeds the threshold, the maximum livability score is assigned. Otherwise, a livability
|
88 |
-
score is calculated based on linear interpolation between 0 and the threshold. Combined metrics
|
89 |
-
for broader categories like 'social infrastructure' are computed by summing up relevant subdomain
|
90 |
-
scores.
|
91 |
-
|
92 |
-
Example:
|
93 |
-
--------
|
94 |
-
# Define the DistanceMatrix and totalAccessibility with example data
|
95 |
-
DistanceMatrix = pd.DataFrame(index=[0, 1, 2])
|
96 |
-
totalAccessibility = pd.DataFrame({'jobs': [100, 150, 200], 'health': [80, 90, 95]}, index=[0, 1, 2])
|
97 |
-
SubdomainAttributeDict = {'jobs': [100, 50], 'health': [80, 40]}
|
98 |
-
|
99 |
-
# Call the function
|
100 |
-
livability_scores = accessibilityToLivability(DistanceMatrix, totalAccessibility, SubdomainAttributeDict)
|
101 |
-
print(livability_scores)
|
102 |
-
|
103 |
-
Notes:
|
104 |
-
------
|
105 |
-
- The function assumes all columns in totalAccessibility are represented in SubdomainAttributeDict unless
|
106 |
-
explicitly handled otherwise within the function.
|
107 |
-
"""
|
108 |
-
|
109 |
livability = pd.DataFrame(index=DistanceMatrix.index, columns=subdomainsAccessibility.columns)
|
110 |
-
# livability["Workplaces"] = 0
|
111 |
livability.fillna(0, inplace=True)
|
112 |
|
113 |
-
|
114 |
# find a set of unique domains, to which subdomains are aggregated
|
115 |
|
116 |
temp = []
|
@@ -154,9 +108,6 @@ def test(input_json):
|
|
154 |
|
155 |
|
156 |
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
|
161 |
|
162 |
|
|
|
62 |
|
63 |
def accessibilityToLivability (DistanceMatrix,subdomainsAccessibility, SubdomainAttributeDict):
|
64 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
livability = pd.DataFrame(index=DistanceMatrix.index, columns=subdomainsAccessibility.columns)
|
|
|
66 |
livability.fillna(0, inplace=True)
|
67 |
|
|
|
68 |
# find a set of unique domains, to which subdomains are aggregated
|
69 |
|
70 |
temp = []
|
|
|
108 |
|
109 |
|
110 |
|
|
|
|
|
|
|
111 |
|
112 |
|
113 |
|