Spaces:
Sleeping
Sleeping
nastasiasnk
commited on
Commit
•
725afdf
1
Parent(s):
6bbc16e
Update app.py
Browse files
app.py
CHANGED
@@ -32,19 +32,14 @@ if notionToken is None:
|
|
32 |
raise Exception("Notion token not found. Please check the environment variables.")
|
33 |
else:
|
34 |
print("Notion token found successfully!")
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
notion=notion,
|
44 |
-
notionToken=notionToken,
|
45 |
-
landuseDatabaseID=landuseDatabaseId,
|
46 |
-
subdomainDatabaseID=subdomainAttributesDatabaseId
|
47 |
-
)
|
48 |
|
49 |
|
50 |
|
@@ -74,54 +69,29 @@ if speckleToken is None:
|
|
74 |
raise Exception("Speckle token not found")
|
75 |
else:
|
76 |
print("Speckle token found successfully!")
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
account = get_default_account()
|
82 |
-
CLIENT.authenticate_with_token(token=speckleToken)
|
83 |
-
|
84 |
-
landuses, matrices = getDataFromSpeckle(speckleClient = CLIENT, streamID=streamId,matrixBranchName=dmBranchName, landuseBranchName=luBranchName)
|
85 |
-
|
86 |
-
#streamDistanceMatrices = speckle_utils.getSpeckleStream(streamId,dmBranchName,CLIENT, dmCommitId)
|
87 |
-
#matrices = fetchDistanceMatrices (streamDistanceMatrices)
|
88 |
-
#streamLanduses = speckle_utils.getSpeckleStream(streamId,luBranchName,CLIENT, luCommitId)
|
89 |
-
#streamData = streamLanduses["@Data"]["@{0}"]
|
90 |
-
|
91 |
-
#df_speckle_lu = speckle_utils.get_dataframe(streamData, return_original_df=False)
|
92 |
-
#df_lu = df_speckle_lu.copy()
|
93 |
-
#df_lu = df_lu.astype(str)
|
94 |
-
#df_lu = df_lu.set_index("uuid", drop=False) # variable, uuid as default
|
95 |
-
|
96 |
-
df_dm = matrices[distanceMatrixActivityNodes]
|
97 |
-
df_dm_dict = df_dm.to_dict('index')
|
98 |
-
|
99 |
-
# Replace infinity with 10000 and NaN values with 0, then convert to integers
|
100 |
-
df_dm = df_dm.replace([np.inf, -np.inf], 10000).fillna(0)
|
101 |
-
df_dm = df_dm.apply(pd.to_numeric, errors='coerce')
|
102 |
-
df_dm = df_dm.round(0).astype(int)
|
103 |
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
|
|
|
|
|
|
114 |
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
df_lu.columns = [col.replace('ASSETS+', '') for col in df_lu.columns]
|
120 |
-
|
121 |
-
df_lu = df_lu.replace([np.inf, -np.inf], 10000).fillna(0)
|
122 |
-
df_lu = df_lu.apply(pd.to_numeric, errors='coerce')
|
123 |
-
df_lu = df_lu.astype(int)
|
124 |
-
df_lu = df_lu.T.groupby(level=0).sum().T
|
125 |
|
126 |
|
127 |
|
@@ -232,8 +202,8 @@ def test(input_json):
|
|
232 |
#"subdomainsAccessibility_dictionary": subdomainsAccessibility_dictionary,
|
233 |
#"livability_dictionary": livability_dictionary,
|
234 |
#"subdomainsWeights_dictionary": LivabilitySubdomainsInputs_dictionary,
|
235 |
-
|
236 |
-
|
237 |
"mask_connected": mask_connected,
|
238 |
"dm_an": df_dm_dict,
|
239 |
"landuses":df_lu_filtered_dict,
|
|
|
32 |
raise Exception("Notion token not found. Please check the environment variables.")
|
33 |
else:
|
34 |
print("Notion token found successfully!")
|
35 |
+
if useNotionData == True:
|
36 |
+
notion = client_notion(auth=notionToken)
|
37 |
+
landuseMapperDict, livabilityMapperDict = getDataFromNotion(
|
38 |
+
notion=notion,
|
39 |
+
notionToken=notionToken,
|
40 |
+
landuseDatabaseID=landuseDatabaseId,
|
41 |
+
subdomainDatabaseID=subdomainAttributesDatabaseId
|
42 |
+
)
|
|
|
|
|
|
|
|
|
|
|
43 |
|
44 |
|
45 |
|
|
|
69 |
raise Exception("Speckle token not found")
|
70 |
else:
|
71 |
print("Speckle token found successfully!")
|
72 |
+
if useSpeckleData == True:
|
73 |
+
CLIENT = SpeckleClient(host="https://speckle.xyz/")
|
74 |
+
account = get_default_account()
|
75 |
+
CLIENT.authenticate_with_token(token=speckleToken)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
|
77 |
+
landuses, matrices = getDataFromSpeckle(speckleClient = CLIENT, streamID=streamId,matrixBranchName=dmBranchName, landuseBranchName=luBranchName)
|
78 |
+
|
79 |
+
df_dm = matrices[distanceMatrixActivityNodes]
|
80 |
+
df_dm_dict = df_dm.to_dict('index')
|
81 |
+
df_dm = df_dm.replace([np.inf, -np.inf], 10000).fillna(0)
|
82 |
+
df_dm = df_dm.apply(pd.to_numeric, errors='coerce')
|
83 |
+
df_dm = df_dm.round(0).astype(int)
|
84 |
+
mask_connected = df_dm.index.tolist()
|
85 |
+
df_lu = landuses.loc[mask_connected]
|
86 |
+
|
87 |
+
mergeAssetNonAssetLanduse = True
|
88 |
+
if mergeAssetNonAssetLanduse:
|
89 |
+
df_lu.columns = [col.replace('ASSETS+', '') for col in df_lu.columns]
|
90 |
|
91 |
+
df_lu = df_lu.replace([np.inf, -np.inf], 10000).fillna(0)
|
92 |
+
df_lu = df_lu.apply(pd.to_numeric, errors='coerce')
|
93 |
+
df_lu = df_lu.astype(int)
|
94 |
+
df_lu = df_lu.T.groupby(level=0).sum().T
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
|
96 |
|
97 |
|
|
|
202 |
#"subdomainsAccessibility_dictionary": subdomainsAccessibility_dictionary,
|
203 |
#"livability_dictionary": livability_dictionary,
|
204 |
#"subdomainsWeights_dictionary": LivabilitySubdomainsInputs_dictionary,
|
205 |
+
"luDomainMapper": landuseMapperDict,
|
206 |
+
"attributeMapper": livabilityMapperDict,
|
207 |
"mask_connected": mask_connected,
|
208 |
"dm_an": df_dm_dict,
|
209 |
"landuses":df_lu_filtered_dict,
|