Spaces:
Sleeping
Sleeping
nastasiasnk
commited on
Commit
•
962d621
1
Parent(s):
eda0b1c
Rename imports_utils to imports_utils.py
Browse files- imports_utils → imports_utils.py +98 -94
imports_utils → imports_utils.py
RENAMED
@@ -133,15 +133,8 @@ def get_page_by_id(notion_db_pages, page_id):
|
|
133 |
|
134 |
|
135 |
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
notion = client_notion(auth=userdata.get('notion_token'))
|
141 |
-
|
142 |
-
|
143 |
-
stream_id="ebcfc50abe"
|
144 |
-
|
145 |
|
146 |
# MAIN DISTANCE MATRIX
|
147 |
branch_name_dm = "graph_geometry/distance_matrix"
|
@@ -157,94 +150,105 @@ commit_id_lu = "13ae6cdd30"
|
|
157 |
# LIVABILITY DOMAINS ATTRIBUTES
|
158 |
notion_lu_domains = "407c2fce664f4dde8940bb416780a86d"
|
159 |
notion_domain_attributes = "01401b78420f4296a2449f587d4ed9c9"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
160 |
|
161 |
|
162 |
|
163 |
-
lu_attributes = fetch_all_database_pages(notion, notion_lu_domains)
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
domain_attributes = fetch_all_database_pages(notion, notion_domain_attributes)
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
lu_domain_mapper ={}
|
172 |
-
|
173 |
-
subdomains_unique = []
|
174 |
-
|
175 |
-
for page in lu_attributes:
|
176 |
-
value_landuse = get_property_value(page, "LANDUSE")
|
177 |
-
value_subdomain = get_property_value(page, "SUBDOMAIN_LIVEABILITY")
|
178 |
-
if value_subdomain and value_landuse:
|
179 |
-
lu_domain_mapper[value_landuse] = value_subdomain
|
180 |
-
if value_subdomain != "":
|
181 |
-
subdomains_unique.append(value_subdomain)
|
182 |
-
|
183 |
-
subdomains_unique = list(set(subdomains_unique))
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
attribute_mapper ={}
|
190 |
-
|
191 |
-
domains_unique = []
|
192 |
-
|
193 |
-
for page in domain_attributes:
|
194 |
-
subdomain = get_property_value(page, "SUBDOMAIN_UNIQUE")
|
195 |
-
sqm_per_employee = get_property_value(page, "SQM PER EMPL")
|
196 |
-
thresholds = get_property_value(page, "MANHATTAN THRESHOLD")
|
197 |
-
max_points = get_property_value(page, "LIVABILITY MAX POINT")
|
198 |
-
domain = get_property_value(page, "DOMAIN")
|
199 |
-
if thresholds: #domain !="Transportation" and
|
200 |
-
attribute_mapper[subdomain] = {
|
201 |
-
'sqmPerEmpl': [sqm_per_employee if sqm_per_employee != "" else 0],
|
202 |
-
'thresholds': thresholds,
|
203 |
-
'max_points': max_points,
|
204 |
-
'domain': [domain if domain != "" else 0]
|
205 |
-
}
|
206 |
-
|
207 |
-
if domain != "":
|
208 |
-
domains_unique.append(domain)
|
209 |
-
|
210 |
-
domains_unique = list(set(domains_unique))
|
211 |
-
|
212 |
-
|
213 |
-
attribute_mapper[subdomain] = [sqm_per_employee if sqm_per_employee != "" else 0, thresholds,max_points,domain if domain != "" else 0 ]
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
stream_distance_matrice = speckle_utils.getSpeckleStream(stream_id,
|
222 |
-
branch_name_dm,
|
223 |
-
CLIENT,
|
224 |
-
commit_id = commit_id_dm)
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
# navigate to list with speckle objects of interest
|
230 |
-
distance_matrices = {}
|
231 |
-
for distM in stream_distance_matrice["@Data"]['@{0}']:
|
232 |
-
for kk in distM.__dict__.keys():
|
233 |
-
try:
|
234 |
-
if kk.split("+")[1].startswith("distance_matrix"):
|
235 |
-
distance_matrix_dict = json.loads(distM[kk])
|
236 |
-
origin_ids = distance_matrix_dict["origin_uuid"]
|
237 |
-
destination_ids = distance_matrix_dict["destination_uuid"]
|
238 |
-
distance_matrix = distance_matrix_dict["matrix"]
|
239 |
-
# Convert the distance matrix to a DataFrame
|
240 |
-
df_distances = pd.DataFrame(distance_matrix, index=origin_ids, columns=destination_ids)
|
241 |
-
|
242 |
-
# i want to add the index & colum names to dist_m_csv
|
243 |
-
#distance_matrices[kk] = dist_m_csv[kk]
|
244 |
-
distance_matrices[kk] = df_distances
|
245 |
-
except:
|
246 |
-
pass
|
247 |
-
|
248 |
|
249 |
df_dm_transport = distance_matrices[dm_transportStops]
|
250 |
|
|
|
133 |
|
134 |
|
135 |
|
136 |
+
"""
|
137 |
+
# define variables
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
138 |
|
139 |
# MAIN DISTANCE MATRIX
|
140 |
branch_name_dm = "graph_geometry/distance_matrix"
|
|
|
150 |
# LIVABILITY DOMAINS ATTRIBUTES
|
151 |
notion_lu_domains = "407c2fce664f4dde8940bb416780a86d"
|
152 |
notion_domain_attributes = "01401b78420f4296a2449f587d4ed9c9"
|
153 |
+
"""
|
154 |
+
|
155 |
+
|
156 |
+
#def streamNotionDatabases (notionToken, landuseDatabaseId, subdomainAttributesDatabaseId):
|
157 |
+
if notionToken:
|
158 |
+
notion = client_notion(auth=userdata.get(notionToken))
|
159 |
+
lu_attributes = fetch_all_database_pages(notion, landuseDatabaseId)
|
160 |
+
livability_attributes = fetch_all_database_pages(notion, subdomainAttributesDatabaseId)
|
161 |
+
else:
|
162 |
+
print ("Notion token is not provided")
|
163 |
+
|
164 |
+
|
165 |
+
|
166 |
+
def streamMatrices (speckleToken, stream_id, branch_name_dm, commit_id):
|
167 |
+
CLIENT = SpeckleClient(host="https://speckle.xyz/")
|
168 |
+
CLIENT.authenticate_with_token(token=userdata.get(speckleToken))
|
169 |
+
|
170 |
+
#stream_id="ebcfc50abe"
|
171 |
+
stream_distance_matrices = speckle_utils.getSpeckleStream(stream_id,
|
172 |
+
branch_name_dm,
|
173 |
+
CLIENT,
|
174 |
+
commit_id = commit_id_dm)
|
175 |
+
|
176 |
+
return stream_distance_matrices
|
177 |
+
|
178 |
+
|
179 |
+
|
180 |
+
def fetchDomainMapper (luAttributePages):
|
181 |
+
|
182 |
+
lu_domain_mapper ={}
|
183 |
+
subdomains_unique = []
|
184 |
+
|
185 |
+
for page in lu_attributes:
|
186 |
+
value_landuse = get_property_value(page, "LANDUSE")
|
187 |
+
value_subdomain = get_property_value(page, "SUBDOMAIN_LIVEABILITY")
|
188 |
+
if value_subdomain and value_landuse:
|
189 |
+
lu_domain_mapper[value_landuse] = value_subdomain
|
190 |
+
if value_subdomain != "":
|
191 |
+
subdomains_unique.append(value_subdomain)
|
192 |
+
|
193 |
+
#subdomains_unique = list(set(subdomains_unique))
|
194 |
+
return lu_domain_mapper
|
195 |
+
|
196 |
+
|
197 |
+
|
198 |
+
def fetchSubdomainMapper (livability_attributes):
|
199 |
+
|
200 |
+
attribute_mapper ={}
|
201 |
+
domains_unique = []
|
202 |
+
|
203 |
+
for page in domain_attributes:
|
204 |
+
subdomain = get_property_value(page, "SUBDOMAIN_UNIQUE")
|
205 |
+
sqm_per_employee = get_property_value(page, "SQM PER EMPL")
|
206 |
+
thresholds = get_property_value(page, "MANHATTAN THRESHOLD")
|
207 |
+
max_points = get_property_value(page, "LIVABILITY MAX POINT")
|
208 |
+
domain = get_property_value(page, "DOMAIN")
|
209 |
+
if thresholds:
|
210 |
+
attribute_mapper[subdomain] = {
|
211 |
+
'sqmPerEmpl': [sqm_per_employee if sqm_per_employee != "" else 0],
|
212 |
+
'thresholds': thresholds,
|
213 |
+
'max_points': max_points,
|
214 |
+
'domain': [domain if domain != "" else 0]
|
215 |
+
}
|
216 |
+
if domain != "":
|
217 |
+
domains_unique.append(domain)
|
218 |
+
|
219 |
+
#domains_unique = list(set(domains_unique))
|
220 |
+
return attribute_mapper
|
221 |
+
|
222 |
+
|
223 |
+
|
224 |
+
|
225 |
+
|
226 |
+
|
227 |
+
def fetchDistanceMatrices (stream_distance_matrices):
|
228 |
+
|
229 |
+
# navigate to list with speckle objects of interest
|
230 |
+
distance_matrices = {}
|
231 |
+
for distM in stream_distance_matrice["@Data"]['@{0}']:
|
232 |
+
for kk in distM.__dict__.keys():
|
233 |
+
try:
|
234 |
+
if kk.split("+")[1].startswith("distance_matrix"):
|
235 |
+
distance_matrix_dict = json.loads(distM[kk])
|
236 |
+
origin_ids = distance_matrix_dict["origin_uuid"]
|
237 |
+
destination_ids = distance_matrix_dict["destination_uuid"]
|
238 |
+
distance_matrix = distance_matrix_dict["matrix"]
|
239 |
+
# Convert the distance matrix to a DataFrame
|
240 |
+
df_distances = pd.DataFrame(distance_matrix, index=origin_ids, columns=destination_ids)
|
241 |
+
|
242 |
+
# i want to add the index & colum names to dist_m_csv
|
243 |
+
#distance_matrices[kk] = dist_m_csv[kk]
|
244 |
+
distance_matrices[kk] = df_distances
|
245 |
+
except:
|
246 |
+
pass
|
247 |
+
|
248 |
+
return distance_matrices
|
249 |
|
250 |
|
251 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
252 |
|
253 |
df_dm_transport = distance_matrices[dm_transportStops]
|
254 |
|