serJD commited on
Commit
73151d8
·
verified ·
1 Parent(s): 3ee0941

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -45
app.py CHANGED
@@ -65,7 +65,7 @@ def filter_activityNodeAnalysis(objDict):
65
 
66
 
67
  # load config to variables
68
- def mainFunc(STREAM_ID, SOURCE_BRANCH, TARGET_BRANCH, UUID_COL, ATTR_METADATA, KPI_METADATA, DEFAULT_ATTRIBUTES, DATASET_NAME):
69
  print("SOURCE_BRANCH",SOURCE_BRANCH)
70
  print("TARGET_BRANCH",TARGET_BRANCH)
71
  if type(TARGET_BRANCH) == type([]):
@@ -97,7 +97,7 @@ def mainFunc(STREAM_ID, SOURCE_BRANCH, TARGET_BRANCH, UUID_COL, ATTR_METADATA, K
97
  # get speckle data
98
  # get stream
99
  print("getting source branch, from branch: ",SOURCE_BRANCH)
100
- stream = getSpeckleStream(STREAM_ID,
101
  SOURCE_BRANCH,
102
  CLIENT,
103
  commit_id = "")
@@ -128,22 +128,6 @@ def mainFunc(STREAM_ID, SOURCE_BRANCH, TARGET_BRANCH, UUID_COL, ATTR_METADATA, K
128
  # to filter conditions defined yet
129
  pass
130
 
131
- """
132
- tot_sqm =0
133
- for k, v in objDict.items():
134
- if k.startswith("lu+"):
135
- tot_sqm += float(v)
136
- if tot_sqm <= 0:
137
- pass_flag = False
138
-
139
- # COND B: remove non connected
140
- if "isConnected" in objDict.keys():
141
- if objDict["isConnected"] == False:
142
- pass_flag == False
143
- else:
144
- pass_flag == False
145
-
146
- """
147
 
148
  if pass_flag == False :
149
  log["removedDatapoints"] +=1
@@ -198,7 +182,7 @@ def mainFunc(STREAM_ID, SOURCE_BRANCH, TARGET_BRANCH, UUID_COL, ATTR_METADATA, K
198
  commit_id = CLIENT.commit.create(
199
  STREAM_ID,
200
  object_id= object_id,
201
- message="auto commit, removed datapoints: " + str( log["removedDatapoints"]) + "; avg. removed attributes: "+ str(int(log["avg_attrRemoved"])),
202
  branch_name=TARGET_BRANCH,
203
  )
204
 
@@ -223,39 +207,49 @@ async def update_streams(request: Request):
223
 
224
  payload = payload["payload"]
225
 
 
 
 
 
 
 
 
226
 
 
227
 
228
 
229
- # Check if the payload structure matches the expected format
230
- # Assuming payload["event"]["event_name"] gives you the event type
231
- event_name = payload["event"]["event_name"]
232
- streamName = payload.get("stream", {}).get("name")
233
-
234
- # Extract branchName for commit_update events from the "old" commit data
235
- if event_name == "commit_update":
236
- branchName = payload.get("event", {}).get("data", {}).get("old", {}).get("branchName")
237
-
238
  else:
239
- branchName = payload.get("event", {}).get("data", {}).get("commit", {}).get("branchName")
240
-
241
-
242
- # List of valid event types
243
- valid_event_types = ["commit_create", "commit_delete", "commit_update"]
244
-
245
- if event_name in valid_event_types:
246
- if streamName in config:
247
- if branchName in config[streamName]:
248
- stream_config = config[streamName][branchName]
249
- should_continue = True
 
 
 
 
 
 
 
 
 
 
 
 
 
250
  else:
251
- print(f"Branch name {branchName} not found in config for stream {streamName}.")
252
  else:
253
- print(f"Stream name {streamName} not found in config.")
254
- else:
255
- print(f"Event type {event_name} is not one of the specified types.")
256
 
257
  print("payload branchname", branchName)
258
-
259
  # If the flag is True, continue running the main part of the code
260
  if should_continue:
261
  config_entry = config[streamName][branchName]
@@ -270,5 +264,5 @@ async def update_streams(request: Request):
270
  DATASET_NAME = config_entry.get("DATASET_NAME")
271
 
272
  # main
273
- mainFunc(STREAM_ID, SOURCE_BRANCH, TARGET_BRANCH, UUID_COL, ATTR_METADATA, KPI_METADATA, DEFAULT_ATTRIBUTES, DATASET_NAME)
274
 
 
65
 
66
 
67
  # load config to variables
68
+ def mainFunc(STREAM_ID, SOURCE_BRANCH, TARGET_BRANCH, UUID_COL, ATTR_METADATA, KPI_METADATA, DEFAULT_ATTRIBUTES, DATASET_NAME, UPDATE_SRC):
69
  print("SOURCE_BRANCH",SOURCE_BRANCH)
70
  print("TARGET_BRANCH",TARGET_BRANCH)
71
  if type(TARGET_BRANCH) == type([]):
 
97
  # get speckle data
98
  # get stream
99
  print("getting source branch, from branch: ",SOURCE_BRANCH)
100
+ stream, inputCommitID = getSpeckleStream(STREAM_ID,
101
  SOURCE_BRANCH,
102
  CLIENT,
103
  commit_id = "")
 
128
  # to filter conditions defined yet
129
  pass
130
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
131
 
132
  if pass_flag == False :
133
  log["removedDatapoints"] +=1
 
182
  commit_id = CLIENT.commit.create(
183
  STREAM_ID,
184
  object_id= object_id,
185
+ message="auto commit from HF; Triggerd by:" + UPDATE_SRC + ", removed datapoints: " + str( log["removedDatapoints"]) + "; avg. removed attributes: "+ str(int(log["avg_attrRemoved"]) + "#+SourceCommit: " + inputCommitID ),
186
  branch_name=TARGET_BRANCH,
187
  )
188
 
 
207
 
208
  payload = payload["payload"]
209
 
210
+ if payload.get('source') == 'notionTrigger':
211
+ action = payload.get('action')
212
+ streamName = payload.get('streamName')
213
+ branchName = payload.get('branchName')
214
+ update_source = "notionTrigger"
215
+
216
+
217
 
218
+
219
 
220
 
 
 
 
 
 
 
 
 
 
221
  else:
222
+ # Check if the payload structure matches the expected format
223
+ # Assuming payload["event"]["event_name"] gives you the event type
224
+ update_source = "SpeckleWebhook"
225
+ event_name = payload["event"]["event_name"]
226
+ streamName = payload.get("stream", {}).get("name")
227
+
228
+ # Extract branchName for commit_update events from the "old" commit data
229
+ if event_name == "commit_update":
230
+ branchName = payload.get("event", {}).get("data", {}).get("old", {}).get("branchName")
231
+
232
+ else:
233
+ branchName = payload.get("event", {}).get("data", {}).get("commit", {}).get("branchName")
234
+
235
+
236
+ # List of valid event types
237
+ valid_event_types = ["commit_create", "commit_delete", "commit_update"]
238
+
239
+ if event_name in valid_event_types:
240
+ if streamName in config:
241
+ if branchName in config[streamName]:
242
+ stream_config = config[streamName][branchName]
243
+ should_continue = True
244
+ else:
245
+ print(f"Branch name {branchName} not found in config for stream {streamName}.")
246
  else:
247
+ print(f"Stream name {streamName} not found in config.")
248
  else:
249
+ print(f"Event type {event_name} is not one of the specified types.")
 
 
250
 
251
  print("payload branchname", branchName)
252
+
253
  # If the flag is True, continue running the main part of the code
254
  if should_continue:
255
  config_entry = config[streamName][branchName]
 
264
  DATASET_NAME = config_entry.get("DATASET_NAME")
265
 
266
  # main
267
+ mainFunc(STREAM_ID, SOURCE_BRANCH, TARGET_BRANCH, UUID_COL, ATTR_METADATA, KPI_METADATA, DEFAULT_ATTRIBUTES, DATASET_NAME, update_source)
268