Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -25,9 +25,11 @@ from config import domainColumnName
|
|
25 |
|
26 |
|
27 |
if notionToken is None:
|
28 |
-
|
|
|
29 |
else:
|
30 |
-
|
|
|
31 |
if useNotionData:
|
32 |
notion = client_notion(auth=notionToken)
|
33 |
lu_mapperDict, subdomain_mapperDict = getDataFromNotion(
|
@@ -60,9 +62,11 @@ from config import useSpeckleData
|
|
60 |
from imports_utils import getDataFromSpeckle
|
61 |
|
62 |
if speckleToken is None:
|
63 |
-
|
|
|
64 |
else:
|
65 |
-
|
|
|
66 |
if useSpeckleData == True:
|
67 |
CLIENT = SpeckleClient(host="https://speckle.xyz/")
|
68 |
account = get_default_account()
|
@@ -171,7 +175,47 @@ def test(input_json):
|
|
171 |
|
172 |
df_lu_dict = dfLanduses.to_dict('index')
|
173 |
dm_dictionary = dfMatrix.to_dict('index')
|
174 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
175 |
# Prepare the output
|
176 |
output = {
|
177 |
"subdomainsAccessibility_dictionary": subdomainsAccessibility_dictionary,
|
@@ -182,7 +226,8 @@ def test(input_json):
|
|
182 |
"mask_connected": mask_connected,
|
183 |
"dm_an": dm_dictionary,
|
184 |
"landuses":df_lu_dict,
|
185 |
-
"constants": [alpha, threshold]
|
|
|
186 |
}
|
187 |
|
188 |
|
|
|
25 |
|
26 |
|
27 |
if notionToken is None:
|
28 |
+
notionFound = "Notion token not found."
|
29 |
+
raise Exception(notionFound)
|
30 |
else:
|
31 |
+
notionFound = "Notion token found successfully!"
|
32 |
+
print(notionFound)
|
33 |
if useNotionData:
|
34 |
notion = client_notion(auth=notionToken)
|
35 |
lu_mapperDict, subdomain_mapperDict = getDataFromNotion(
|
|
|
62 |
from imports_utils import getDataFromSpeckle
|
63 |
|
64 |
if speckleToken is None:
|
65 |
+
speckleFound = "Speckle token not found."
|
66 |
+
raise Exception(speckleFound)
|
67 |
else:
|
68 |
+
speckleFound = "Speckle token found successfully!"
|
69 |
+
print(speckleFound)
|
70 |
if useSpeckleData == True:
|
71 |
CLIENT = SpeckleClient(host="https://speckle.xyz/")
|
72 |
account = get_default_account()
|
|
|
175 |
|
176 |
df_lu_dict = dfLanduses.to_dict('index')
|
177 |
dm_dictionary = dfMatrix.to_dict('index')
|
178 |
+
|
179 |
+
# generate report string
|
180 |
+
|
181 |
+
|
182 |
+
nan_count = dfMatrix.isna().sum().sum()
|
183 |
+
nan_count_after_inf_replacement = dfMatrix.replace([np.inf, -np.inf], np.nan).isna().sum().sum()
|
184 |
+
inf_count = nan_count_after_inf_replacement - nan_count
|
185 |
+
|
186 |
+
landuseSum = ', '.join([f"{column} = {dfLanduses[column].sum()}" for column in dfLanduses.columns])
|
187 |
+
weightsSum = ', '.join([f"{column} = {LivabilitySubdomainsInputs[column].sum()}" for column in LivabilitySubdomainsInputs.columns])
|
188 |
+
|
189 |
+
|
190 |
+
valid_indexes = [idx for idx in mask_connected if idx in dfLanduses_gh.index]
|
191 |
+
missing_indexes = set(mask_connected) - set(valid_indexes)
|
192 |
+
if missing_indexes:
|
193 |
+
indexError = f"Error: The following indexes were not found in the DataFrame: {missing_indexes}, length: {len(missing_indexes)}"
|
194 |
+
|
195 |
+
|
196 |
+
accessibilityStats = [
|
197 |
+
f"{column} = {df[column].min()}, {df[column].max()}, {df[column].mean()}" for column in subdomainsAccessibility.columns
|
198 |
+
]
|
199 |
+
|
200 |
+
livabilityStats = [
|
201 |
+
f"{column} = {df[column].min()}, {df[column].max()}, {df[column].mean()}" for column in livability.columns
|
202 |
+
]
|
203 |
+
|
204 |
+
outputReport = [
|
205 |
+
notionFound,
|
206 |
+
speckleFound,
|
207 |
+
f"Distance matrix length: {len(dfMatrix)}",
|
208 |
+
f"Number Infinity values: {inf_count}, number NaN values: {nan_count}",
|
209 |
+
f"Activity nodes with landuses number: {len(dfLanduses)}",
|
210 |
+
f"Total area per landuse: {landuseSum}",
|
211 |
+
f"Total area (jobs) per livability category: {weightsSum}",
|
212 |
+
indexError,
|
213 |
+
f"Accessibility parameters used: threshold: {threshold}, alpha: {alpha}",
|
214 |
+
f"Accessibility stats: {accessibilityStats}",
|
215 |
+
f"Livability stats: {livabilityStats}"
|
216 |
+
]
|
217 |
+
|
218 |
+
|
219 |
# Prepare the output
|
220 |
output = {
|
221 |
"subdomainsAccessibility_dictionary": subdomainsAccessibility_dictionary,
|
|
|
226 |
"mask_connected": mask_connected,
|
227 |
"dm_an": dm_dictionary,
|
228 |
"landuses":df_lu_dict,
|
229 |
+
"constants": [alpha, threshold],
|
230 |
+
"report": outputReport
|
231 |
}
|
232 |
|
233 |
|