Spaces:
Sleeping
Sleeping
nastasiasnk
commited on
Commit
•
91d17a9
1
Parent(s):
166b945
Update app.py
Browse files
app.py
CHANGED
@@ -51,10 +51,10 @@ import imports_utils
|
|
51 |
import speckle_utils
|
52 |
import data_utils
|
53 |
|
54 |
-
from config import landuseDatabaseId , streamId, dmBranchName, dmCommitId, luBranchName, luCommitId
|
55 |
from imports_utils import speckleToken
|
56 |
from imports_utils import fetchDistanceMatrices
|
57 |
-
from config import
|
58 |
#from config import distanceMatrixTransportStops
|
59 |
|
60 |
|
@@ -62,41 +62,53 @@ 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 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
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("uuid", drop=False) # variable, uuid as default
|
79 |
|
80 |
df_dm = matrices[distanceMatrixActivityNodes]
|
81 |
-
|
82 |
df_dm_dict = df_dm.to_dict('index')
|
83 |
-
|
84 |
-
|
85 |
# Replace infinity with 10000 and NaN values with 0, then convert to integers
|
86 |
df_dm = df_dm.replace([np.inf, -np.inf], 10000).fillna(0)
|
87 |
df_dm = df_dm.apply(pd.to_numeric, errors='coerce')
|
88 |
df_dm = df_dm.round(0).astype(int)
|
89 |
|
90 |
mask_connected = df_dm.index.tolist()
|
91 |
-
|
|
|
92 |
lu_columns = [] # provided by user? or prefix
|
93 |
for name in df_lu.columns:
|
94 |
if name.startswith("lu+"):
|
95 |
lu_columns.append(name)
|
|
|
|
|
|
|
96 |
|
97 |
-
df_lu_filtered =
|
98 |
-
|
99 |
-
|
|
|
|
|
100 |
|
101 |
df_lu_filtered = df_lu_filtered.replace([np.inf, -np.inf], 10000).fillna(0)
|
102 |
df_lu_filtered = df_lu_filtered.apply(pd.to_numeric, errors='coerce')
|
@@ -106,8 +118,6 @@ else:
|
|
106 |
|
107 |
|
108 |
|
109 |
-
|
110 |
-
|
111 |
def test(input_json):
|
112 |
print("Received input")
|
113 |
# Parse the input JSON string
|
@@ -121,6 +131,8 @@ def test(input_json):
|
|
121 |
|
122 |
from config import useGrasshopperData
|
123 |
|
|
|
|
|
124 |
if useGrasshopperData == True: # grasshopper input
|
125 |
matrix = inputs['input']["matrix"]
|
126 |
landuses = inputs['input']["landuse_areas"] # fetch grasshoper data or not
|
|
|
51 |
import speckle_utils
|
52 |
import data_utils
|
53 |
|
54 |
+
from config import landuseDatabaseId , streamId, dmBranchName, dmCommitId, luBranchName, luCommitId, distanceMatrixActivityNodes
|
55 |
from imports_utils import speckleToken
|
56 |
from imports_utils import fetchDistanceMatrices
|
57 |
+
from config import useSpeckleData
|
58 |
#from config import distanceMatrixTransportStops
|
59 |
|
60 |
|
|
|
62 |
raise Exception("Speckle token not found")
|
63 |
else:
|
64 |
print("Speckle token found successfully!")
|
65 |
+
|
66 |
+
if useSpeckleData:
|
67 |
|
68 |
CLIENT = SpeckleClient(host="https://speckle.xyz/")
|
69 |
account = get_default_account()
|
70 |
CLIENT.authenticate_with_token(token=speckleToken)
|
71 |
|
72 |
+
landuses, matrices = getDataFromSpeckle(
|
73 |
+
speckleToken,
|
74 |
+
streamId,
|
75 |
+
dmBranchName,
|
76 |
+
luBranchName)
|
77 |
+
|
78 |
+
#streamDistanceMatrices = speckle_utils.getSpeckleStream(streamId,dmBranchName,CLIENT, dmCommitId)
|
79 |
+
#matrices = fetchDistanceMatrices (streamDistanceMatrices)
|
80 |
+
#streamLanduses = speckle_utils.getSpeckleStream(streamId,luBranchName,CLIENT, luCommitId)
|
81 |
+
#streamData = streamLanduses["@Data"]["@{0}"]
|
82 |
|
83 |
+
#df_speckle_lu = speckle_utils.get_dataframe(streamData, return_original_df=False)
|
84 |
+
#df_lu = df_speckle_lu.copy()
|
85 |
+
#df_lu = df_lu.astype(str)
|
86 |
+
#df_lu = df_lu.set_index("uuid", drop=False) # variable, uuid as default
|
87 |
|
88 |
df_dm = matrices[distanceMatrixActivityNodes]
|
|
|
89 |
df_dm_dict = df_dm.to_dict('index')
|
90 |
+
|
|
|
91 |
# Replace infinity with 10000 and NaN values with 0, then convert to integers
|
92 |
df_dm = df_dm.replace([np.inf, -np.inf], 10000).fillna(0)
|
93 |
df_dm = df_dm.apply(pd.to_numeric, errors='coerce')
|
94 |
df_dm = df_dm.round(0).astype(int)
|
95 |
|
96 |
mask_connected = df_dm.index.tolist()
|
97 |
+
|
98 |
+
"""
|
99 |
lu_columns = [] # provided by user? or prefix
|
100 |
for name in df_lu.columns:
|
101 |
if name.startswith("lu+"):
|
102 |
lu_columns.append(name)
|
103 |
+
|
104 |
+
"""
|
105 |
+
df_lu_filtered = df_lu.loc[mask_connected]
|
106 |
|
107 |
+
#df_lu_filtered.columns = [col.replace('lu+', '') for col in df_lu_filtered.columns]
|
108 |
+
|
109 |
+
mergeAssetNonAssetLanduse = True
|
110 |
+
if mergeAssetNonAssetLanduse:
|
111 |
+
df_lu_filtered.columns = [col.replace('ASSETS+', '') for col in df_lu_filtered.columns]
|
112 |
|
113 |
df_lu_filtered = df_lu_filtered.replace([np.inf, -np.inf], 10000).fillna(0)
|
114 |
df_lu_filtered = df_lu_filtered.apply(pd.to_numeric, errors='coerce')
|
|
|
118 |
|
119 |
|
120 |
|
|
|
|
|
121 |
def test(input_json):
|
122 |
print("Received input")
|
123 |
# Parse the input JSON string
|
|
|
131 |
|
132 |
from config import useGrasshopperData
|
133 |
|
134 |
+
useGrasshopperData = inputs['input']["useGrasshopper"] # fetch grasshoper data or not
|
135 |
+
|
136 |
if useGrasshopperData == True: # grasshopper input
|
137 |
matrix = inputs['input']["matrix"]
|
138 |
landuses = inputs['input']["landuse_areas"] # fetch grasshoper data or not
|