nastasiasnk commited on
Commit
725afdf
1 Parent(s): 6bbc16e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -61
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
- landuse_attributes = fetch_all_database_pages(notion, landuseDatabaseId)
37
- livability_attributes = fetch_all_database_pages(notion, subdomainAttributesDatabaseId)
38
- landuseMapperDict = fetchDomainMapper (landuse_attributes)
39
- livabilityMapperDict = fetchSubdomainMapper (livability_attributes)
40
- """
41
- if useNotionData:
42
- landuseMapperDict, livabilityMapperDict = getDataFromNotion(
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
- if useSpeckleData == True:
79
-
80
- CLIENT = SpeckleClient(host="https://speckle.xyz/")
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
- mask_connected = df_dm.index.tolist()
105
-
106
- """
107
- lu_columns = [] # provided by user? or prefix
108
- for name in df_lu.columns:
109
- if name.startswith("lu+"):
110
- lu_columns.append(name)
111
-
112
- """
113
- df_lu = landuses.loc[mask_connected]
 
 
 
114
 
115
- #df_lu_filtered.columns = [col.replace('lu+', '') for col in df_lu_filtered.columns]
116
-
117
- mergeAssetNonAssetLanduse = True
118
- if mergeAssetNonAssetLanduse:
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
- #"luDomainMapper": landuseMapperDict,
236
- #"attributeMapper": livabilityMapperDict,
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,