nastasiasnk commited on
Commit
63a6362
1 Parent(s): c3a87fd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +60 -13
app.py CHANGED
@@ -107,14 +107,44 @@ def test(input_json):
107
 
108
  # ------------------------- Accessing input data from Grasshopper ------------------------- #
109
 
 
 
 
110
 
111
-
112
  useGrasshopperData = inputs['input']["useGrasshopperData"] # fetch grasshoper data or not
113
 
 
114
  if useGrasshopperData == "True": # grasshopper input
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
  matrix = inputs['input']["matrix"]
116
- landuses = inputs['input']["landuse_areas"] # fetch grasshoper data or not
117
-
118
  dfLanduses = pd.DataFrame(landuses).T
119
  dfLanduses = dfLanduses.apply(pd.to_numeric, errors='coerce')
120
  dfLanduses = dfLanduses.replace([np.inf, -np.inf], 0).fillna(0) # cleaning function?
@@ -124,20 +154,33 @@ def test(input_json):
124
  dfMatrix = dfMatrix.apply(pd.to_numeric, errors='coerce')
125
  dfMatrix = dfMatrix.replace([np.inf, -np.inf], 10000).fillna(0)
126
  dfMatrix = dfMatrix.round(0).astype(int)
127
- else:
128
- dfLanduses = df_lu.copy() # fetch speckl data or not
129
- dfMatrix = df_dm.copy()
130
-
131
 
132
- df_lu_filtered_dict = dfLanduses.to_dict('index')
133
- dm_dictionary = dfMatrix.to_dict('index')
134
 
135
- attributeMapperDict_gh = inputs['input']["attributeMapperDict"]
136
- landuseMapperDict_gh = inputs['input']["landuseMapperDict"] # if fetch notion data or not, def
 
137
 
 
 
 
 
 
 
 
 
138
 
139
- from config import alpha as alphaDefault
140
- from config import threshold as thresholdDefault
 
 
 
 
 
 
 
 
141
 
142
  if not inputs['input']["alpha"]:
143
  alpha = alphaDefault
@@ -150,6 +193,8 @@ def test(input_json):
150
  else:
151
  threshold = inputs['input']["threshold"]
152
  threshold = float(threshold)
 
 
153
 
154
  """
155
  valid_indexes = [idx for idx in mask_connected if idx in dfLanduses.index]
@@ -196,6 +241,8 @@ def test(input_json):
196
  subdomainsAccessibility_dictionary = subdomainsAccessibility.to_dict('index')
197
  LivabilitySubdomainsWeights_dictionary = LivabilitySubdomainsWeights.to_dict('index')
198
 
 
 
199
  """
200
  # Prepare the output
201
  output = {
 
107
 
108
  # ------------------------- Accessing input data from Grasshopper ------------------------- #
109
 
110
+ from imports_utils import getDataFromGrasshopper
111
+ from config import alpha as alphaDefault
112
+ from config import threshold as thresholdDefault
113
 
 
114
  useGrasshopperData = inputs['input']["useGrasshopperData"] # fetch grasshoper data or not
115
 
116
+
117
  if useGrasshopperData == "True": # grasshopper input
118
+
119
+ # fetch grasshoper data or not
120
+
121
+ dfMatrix_gh, dfLanduses_gh, attributeMapperDict_gh, landuseMapperDict_gh, alpha, threshold = getDataFromGrasshopper(
122
+ inputNameMatrix = "matrix",
123
+ inputNameLanduse = "landuse_areas",
124
+ inputNameAttributeMapper = "attributeMapperDict",
125
+ inputNameLanduseMapper = "landuseMapperDict",
126
+ inputNameAlpha = "alpha",
127
+ inputNameThreshold = "threshold"
128
+ )
129
+
130
+ dfMatrix = dfMatrix_gh
131
+ dfLanduses = dfLanduses_gh
132
+
133
+ if alpha is None:
134
+ alpha = alphaDefault
135
+
136
+ if threshold is None:
137
+ threshold = thresholdDefault
138
+
139
+ if useNotionData != True:
140
+ attributeMapperDict = attributeMapperDict_gh
141
+ landuseMapperDict = landuseMapperDict_gh
142
+
143
+
144
+ """
145
  matrix = inputs['input']["matrix"]
146
+ landuses = inputs['input']["landuse_areas"]
147
+
148
  dfLanduses = pd.DataFrame(landuses).T
149
  dfLanduses = dfLanduses.apply(pd.to_numeric, errors='coerce')
150
  dfLanduses = dfLanduses.replace([np.inf, -np.inf], 0).fillna(0) # cleaning function?
 
154
  dfMatrix = dfMatrix.apply(pd.to_numeric, errors='coerce')
155
  dfMatrix = dfMatrix.replace([np.inf, -np.inf], 10000).fillna(0)
156
  dfMatrix = dfMatrix.round(0).astype(int)
 
 
 
 
157
 
158
+ attributeMapperDict_gh = inputs['input']["attributeMapperDict"]
159
+ landuseMapperDict_gh = inputs['input']["landuseMapperDict"] # if fetch notion data or not, def
160
 
161
+ """
162
+
163
+ else:
164
 
165
+ dfMatrix_gh, dfLanduses_gh, attributeMapperDict_gh, landuseMapperDict_gh, alpha, threshold = getDataFromGrasshopper(
166
+ inputNameMatrix = None,
167
+ inputNameLanduse = None,
168
+ inputNameAttributeMapper = None,
169
+ inputNameLanduseMapper = None,
170
+ inputNameAlpha = "alpha",
171
+ inputNameThreshold = "threshold"
172
+ )
173
 
174
+ if alpha is None:
175
+ alpha = alphaDefault
176
+
177
+ if threshold is None:
178
+ threshold = thresholdDefault
179
+
180
+ dfLanduses = df_lu.copy() # fetch speckl data or not
181
+ dfMatrix = df_dm.copy()
182
+
183
+ """
184
 
185
  if not inputs['input']["alpha"]:
186
  alpha = alphaDefault
 
193
  else:
194
  threshold = inputs['input']["threshold"]
195
  threshold = float(threshold)
196
+ """
197
+
198
 
199
  """
200
  valid_indexes = [idx for idx in mask_connected if idx in dfLanduses.index]
 
241
  subdomainsAccessibility_dictionary = subdomainsAccessibility.to_dict('index')
242
  LivabilitySubdomainsWeights_dictionary = LivabilitySubdomainsWeights.to_dict('index')
243
 
244
+ df_lu_filtered_dict = dfLanduses.to_dict('index')
245
+ dm_dictionary = dfMatrix.to_dict('index')
246
  """
247
  # Prepare the output
248
  output = {