Spaces:
Sleeping
Sleeping
nastasiasnk
commited on
Commit
•
f6965f4
1
Parent(s):
bc59653
Update app.py
Browse files
app.py
CHANGED
@@ -10,13 +10,6 @@ import os
|
|
10 |
|
11 |
|
12 |
from notion_client import Client as client_notion
|
13 |
-
|
14 |
-
notionToken = os.getenv('notionToken')
|
15 |
-
if notionToken is None:
|
16 |
-
raise Exception("Notion token not found. Please check the environment variables.")
|
17 |
-
else:
|
18 |
-
print("Notion token found successfully!")
|
19 |
-
|
20 |
from config import landuseDatabaseId , subdomainAttributesDatabaseId
|
21 |
from imports_utils import fetch_all_database_pages
|
22 |
from imports_utils import get_property_value
|
@@ -30,10 +23,16 @@ from config import domainColumnName
|
|
30 |
from imports_utils import fetchDomainMapper
|
31 |
from imports_utils import fetchSubdomainMapper
|
32 |
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
|
38 |
|
39 |
|
@@ -58,41 +57,46 @@ from imports_utils import fetchDistanceMatrices
|
|
58 |
from config import distanceMatrixActivityNodes
|
59 |
from config import distanceMatrixTransportStops
|
60 |
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
df_lu_filtered =
|
94 |
-
|
95 |
-
|
|
|
|
|
|
|
|
|
|
|
96 |
|
97 |
|
98 |
|
|
|
10 |
|
11 |
|
12 |
from notion_client import Client as client_notion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
from config import landuseDatabaseId , subdomainAttributesDatabaseId
|
14 |
from imports_utils import fetch_all_database_pages
|
15 |
from imports_utils import get_property_value
|
|
|
23 |
from imports_utils import fetchDomainMapper
|
24 |
from imports_utils import fetchSubdomainMapper
|
25 |
|
26 |
+
from imports_utils import notionToken
|
27 |
+
|
28 |
+
if notionToken is None:
|
29 |
+
raise Exception("Notion token not found. Please check the environment variables.")
|
30 |
+
else:
|
31 |
+
print("Notion token found successfully!")
|
32 |
+
landuse_attributes = fetch_all_database_pages(notion, landuseDatabaseId)
|
33 |
+
livability_attributes = fetch_all_database_pages(notion, subdomainAttributesDatabaseId)
|
34 |
+
landuseMapperDict = fetchDomainMapper (landuse_attributes)
|
35 |
+
attributeMapperDict = fetchSubdomainMapper (livability_attributes)
|
36 |
|
37 |
|
38 |
|
|
|
57 |
from config import distanceMatrixActivityNodes
|
58 |
from config import distanceMatrixTransportStops
|
59 |
|
60 |
+
|
61 |
+
if speckleToken is None:
|
62 |
+
raise Exception("Speckle token not found")
|
63 |
+
else:
|
64 |
+
print("Speckle token found successfully!")
|
65 |
+
|
66 |
+
CLIENT = SpeckleClient(host="https://speckle.xyz/")
|
67 |
+
account = get_default_account()
|
68 |
+
CLIENT.authenticate_with_token(token=speckleToken)
|
69 |
+
|
70 |
+
streamDistanceMatrices = speckle_utils.getSpeckleStream(streamId,dmBranchName,CLIENT, dmCommitId)
|
71 |
+
matrices = fetchDistanceMatrices (streamDistanceMatrices)
|
72 |
+
streamLanduses = speckle_utils.getSpeckleStream(streamId,luBranchName,CLIENT, luCommitId)
|
73 |
+
streamData = streamLanduses["@Data"]["@{0}"]
|
74 |
+
|
75 |
+
df_speckle_lu = speckle_utils.get_dataframe(streamData, return_original_df=False)
|
76 |
+
df_lu = df_speckle_lu.copy()
|
77 |
+
df_lu = df_lu.astype(str)
|
78 |
+
df_lu = df_lu.set_index("ids", drop=False)
|
79 |
+
|
80 |
+
df_dm = matrices[distanceMatrixActivityNodes]
|
81 |
+
df_dm_transport = matrices[distanceMatrixTransportStops]
|
82 |
+
dm_dictionary = df_dm.to_dict('index')
|
83 |
+
df_dm_transport_dictionary = df_dm_transport.to_dict('index')
|
84 |
+
|
85 |
+
# filter activity nodes attributes
|
86 |
+
mask_connected = df_dm.index.tolist()
|
87 |
+
lu_columns = []
|
88 |
+
for name in df_lu.columns:
|
89 |
+
if name.startswith("lu+"):
|
90 |
+
lu_columns.append(name)
|
91 |
+
|
92 |
+
df_lu_filtered = df_lu[lu_columns].loc[mask_connected]
|
93 |
+
df_lu_filtered.columns = [col.replace('lu+', '') for col in df_lu_filtered.columns]
|
94 |
+
df_lu_filtered.columns = [col.replace('ASSETS+', '') for col in df_lu_filtered.columns]
|
95 |
+
df_lu_filtered = df_lu_filtered.astype(int)
|
96 |
+
df_lu_filtered = df_lu_filtered.T.groupby(level=0).sum().T
|
97 |
+
|
98 |
+
df_lu_filtered_dict = df_lu_filtered.to_dict('index')
|
99 |
+
|
100 |
|
101 |
|
102 |
|