nastasiasnk commited on
Commit
51b1074
1 Parent(s): d92e7dc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -51
app.py CHANGED
@@ -102,7 +102,6 @@ df_lu = df_lu.set_index("ids", drop=False)
102
 
103
  df_dm = matrices[distanceMatrixActivityNodes]
104
  df_dm_transport = matrices[distanceMatrixTransportStops]
105
-
106
  dm_dictionary = df_dm.to_dict('index')
107
  df_dm_transport_dictionary = df_dm_transport.to_dict('index')
108
 
@@ -114,7 +113,7 @@ for name in df_lu.columns:
114
  if name.startswith("lu+"):
115
  lu_columns.append(name)
116
  df_lu_filtered = df_lu[lu_columns].loc[mask_connected]
117
- df_lu_filtered
118
 
119
  df_lu_filtered_dict = df_lu_filtered.to_dict('index')
120
 
@@ -129,9 +128,8 @@ def test(input_json):
129
  except json.JSONDecodeError:
130
  inputs = json.loads(input_json.replace("'", '"'))
131
 
132
-
133
 
134
- # Accessing input data from Grasshopper
135
 
136
  #if df_dm is None:
137
  matrix = inputs['input']["matrix"]
@@ -139,8 +137,10 @@ def test(input_json):
139
  #if df_dm_transport is None:
140
  matrix_transport = inputs['input']["transportMatrix"]
141
 
142
- #if df_lu_filtered is None:
143
- landuses = inputs['input']["landuse_areas"]
 
 
144
 
145
  attributeMapperDict_gh = inputs['input']["attributeMapperDict"]
146
  landuseMapperDict_gh = inputs['input']["landuseMapperDict"]
@@ -213,8 +213,6 @@ def test(input_json):
213
 
214
  subdomainsUnique = list(set(temp))
215
 
216
-
217
-
218
 
219
  from imports_utils import landusesToSubdomains
220
  from imports_utils import FindWorkplacesNumber
@@ -225,69 +223,27 @@ def test(input_json):
225
 
226
  LivabilitySubdomainsWeights = landusesToSubdomains(df_dm,df_landuses_filtered,landuseMapperDict,subdomainsUnique)
227
 
228
-
229
  WorkplacesNumber = FindWorkplacesNumber(df_dm,attributeMapperDict,LivabilitySubdomainsWeights,subdomainsUnique)
230
 
231
  # prepare an input weights dataframe for the parameter LivabilitySubdomainsInputs
232
  LivabilitySubdomainsInputs =pd.concat([LivabilitySubdomainsWeights, WorkplacesNumber], axis=1)
233
 
234
-
235
  subdomainsAccessibility = computeAccessibility(df_dm,LivabilitySubdomainsInputs,alpha,threshold)
236
  artAccessibility = computeAccessibility_pointOfInterest(df_art_matrix,'ART',alpha,threshold)
237
  gmtAccessibility = computeAccessibility_pointOfInterest(df_gmt_matrix,'GMT+HSR',alpha,threshold)
 
238
  AccessibilityInputs = pd.concat([subdomainsAccessibility, artAccessibility,gmtAccessibility], axis=1)
239
 
240
 
241
  if 'jobs' not in subdomainsAccessibility.columns:
242
  print("Error: Column 'jobs' does not exist in the subdomainsAccessibility.")
243
 
244
-
245
- """
246
- def accessibilityToLivability (DistanceMatrix,accessibilityInputs, SubdomainAttributeDict,UniqueDomainsList):
247
-
248
- livability = pd.DataFrame(index=DistanceMatrix.index, columns=accessibilityInputs.columns)
249
-
250
- for domain in UniqueDomainsList:
251
- livability[domain] = 0
252
-
253
- livability.fillna(0, inplace=True)
254
-
255
- templist = []
256
- # remap accessibility to livability points
257
-
258
- for key, values in SubdomainAttributeDict.items():
259
- threshold = float(SubdomainAttributeDict[key]['thresholds'])
260
- max_livability = float(SubdomainAttributeDict[key]['max_points'])
261
- domains = [str(item) for item in SubdomainAttributeDict[key]['domain']]
262
-
263
- if key in accessibilityInputs.columns and key != 'commercial':
264
- livability_score = remap(accessibilityInputs[key], 0, threshold, 0, max_livability)
265
- livability.loc[accessibilityInputs[key] >= threshold, key] = max_livability
266
- livability.loc[accessibilityInputs[key] < threshold, key] = livability_score
267
- if any(domains):
268
- for domain in domains:
269
- if domain != 'Workplaces':
270
- livability.loc[accessibilityInputs[key] >= threshold, domain] += max_livability
271
- livability.loc[accessibilityInputs[key] < threshold, domain] += livability_score
272
-
273
- elif key == 'commercial':
274
- livability_score = remap(accessibilityInputs['jobs'], 0, threshold, 0, max_livability)
275
- livability.loc[accessibilityInputs['jobs'] >= threshold, domains[0]] = max_livability
276
- livability.loc[accessibilityInputs['jobs'] < threshold, domains[0]] = livability_score
277
-
278
-
279
- return livability
280
-
281
-
282
- """
283
-
284
  livability = accessibilityToLivability(df_dm,AccessibilityInputs,attributeMapperDict,domainsUnique)
285
 
286
 
287
  livability_dictionary = livability.to_dict('index')
288
  LivabilitySubdomainsInputs_dictionary = LivabilitySubdomainsInputs.to_dict('index')
289
  subdomainsAccessibility_dictionary = AccessibilityInputs.to_dict('index')
290
-
291
  artmatrix = df_art_matrix.to_dict('index')
292
 
293
  # Prepare the output
 
102
 
103
  df_dm = matrices[distanceMatrixActivityNodes]
104
  df_dm_transport = matrices[distanceMatrixTransportStops]
 
105
  dm_dictionary = df_dm.to_dict('index')
106
  df_dm_transport_dictionary = df_dm_transport.to_dict('index')
107
 
 
113
  if name.startswith("lu+"):
114
  lu_columns.append(name)
115
  df_lu_filtered = df_lu[lu_columns].loc[mask_connected]
116
+ df_lu_filtered.columns = [col.replace('lu+', '') for col in df_lu_filtered.columns]
117
 
118
  df_lu_filtered_dict = df_lu_filtered.to_dict('index')
119
 
 
128
  except json.JSONDecodeError:
129
  inputs = json.loads(input_json.replace("'", '"'))
130
 
 
131
 
132
+ # ------------------------- Accessing input data from Grasshopper ------------------------- #
133
 
134
  #if df_dm is None:
135
  matrix = inputs['input']["matrix"]
 
137
  #if df_dm_transport is None:
138
  matrix_transport = inputs['input']["transportMatrix"]
139
 
140
+ if df_lu_filtered is None:
141
+ landuses = inputs['input']["landuse_areas"]
142
+ else:
143
+ landuses = df_lu_filtered
144
 
145
  attributeMapperDict_gh = inputs['input']["attributeMapperDict"]
146
  landuseMapperDict_gh = inputs['input']["landuseMapperDict"]
 
213
 
214
  subdomainsUnique = list(set(temp))
215
 
 
 
216
 
217
  from imports_utils import landusesToSubdomains
218
  from imports_utils import FindWorkplacesNumber
 
223
 
224
  LivabilitySubdomainsWeights = landusesToSubdomains(df_dm,df_landuses_filtered,landuseMapperDict,subdomainsUnique)
225
 
 
226
  WorkplacesNumber = FindWorkplacesNumber(df_dm,attributeMapperDict,LivabilitySubdomainsWeights,subdomainsUnique)
227
 
228
  # prepare an input weights dataframe for the parameter LivabilitySubdomainsInputs
229
  LivabilitySubdomainsInputs =pd.concat([LivabilitySubdomainsWeights, WorkplacesNumber], axis=1)
230
 
 
231
  subdomainsAccessibility = computeAccessibility(df_dm,LivabilitySubdomainsInputs,alpha,threshold)
232
  artAccessibility = computeAccessibility_pointOfInterest(df_art_matrix,'ART',alpha,threshold)
233
  gmtAccessibility = computeAccessibility_pointOfInterest(df_gmt_matrix,'GMT+HSR',alpha,threshold)
234
+
235
  AccessibilityInputs = pd.concat([subdomainsAccessibility, artAccessibility,gmtAccessibility], axis=1)
236
 
237
 
238
  if 'jobs' not in subdomainsAccessibility.columns:
239
  print("Error: Column 'jobs' does not exist in the subdomainsAccessibility.")
240
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
241
  livability = accessibilityToLivability(df_dm,AccessibilityInputs,attributeMapperDict,domainsUnique)
242
 
243
 
244
  livability_dictionary = livability.to_dict('index')
245
  LivabilitySubdomainsInputs_dictionary = LivabilitySubdomainsInputs.to_dict('index')
246
  subdomainsAccessibility_dictionary = AccessibilityInputs.to_dict('index')
 
247
  artmatrix = df_art_matrix.to_dict('index')
248
 
249
  # Prepare the output