serJD commited on
Commit
3c3cf55
·
verified ·
1 Parent(s): 4bea416

Update utils.py

Browse files
Files changed (1) hide show
  1. utils.py +4 -4
utils.py CHANGED
@@ -92,7 +92,7 @@ def aggregate_data_optimized(df_a, df_b, uuid_col_name, ref_col_name, exclude_co
92
 
93
 
94
 
95
- def updateStreamAnalysisFast(client, new_data, stream_id, branch_name, geometryGroupPath=None, match_by_id="", return_original = False):
96
  if geometryGroupPath is None:
97
  geometryGroupPath = ["@Speckle", "Geometry"]
98
 
@@ -103,7 +103,6 @@ def updateStreamAnalysisFast(client, new_data, stream_id, branch_name, geometryG
103
  res = operations.receive(commit.referencedObject, transport)
104
  objects_raw = res[geometryGroupPath[0]][geometryGroupPath[1]]
105
 
106
- # Assuming objects_raw is a list of dictionaries
107
  # Pre-create a mapping from IDs to objects for faster lookup
108
  id_to_object_map = {obj[match_by_id]: obj for obj in objects_raw} if match_by_id else {i: obj for i, obj in enumerate(objects_raw)}
109
 
@@ -111,11 +110,11 @@ def updateStreamAnalysisFast(client, new_data, stream_id, branch_name, geometryG
111
  if match_by_id:
112
  new_data.set_index(match_by_id, inplace=True)
113
 
114
- # Update objects in a more efficient way
115
  for local_id, updates in new_data.iterrows():
116
  target_object = id_to_object_map.get(str(local_id))
117
  if target_object:
118
- for col_name, value in updates.iteritems():
119
  target_object[col_name] = value
120
 
121
  # Send updated objects back to Speckle
@@ -126,6 +125,7 @@ def updateStreamAnalysisFast(client, new_data, stream_id, branch_name, geometryG
126
  return objects_raw # as back-up
127
 
128
 
 
129
 
130
  def getSpeckleStream(stream_id,
131
  branch_name,
 
92
 
93
 
94
 
95
+ def updateStreamAnalysisFast(client, new_data, stream_id, branch_name, geometryGroupPath=None, match_by_id="", return_original=False):
96
  if geometryGroupPath is None:
97
  geometryGroupPath = ["@Speckle", "Geometry"]
98
 
 
103
  res = operations.receive(commit.referencedObject, transport)
104
  objects_raw = res[geometryGroupPath[0]][geometryGroupPath[1]]
105
 
 
106
  # Pre-create a mapping from IDs to objects for faster lookup
107
  id_to_object_map = {obj[match_by_id]: obj for obj in objects_raw} if match_by_id else {i: obj for i, obj in enumerate(objects_raw)}
108
 
 
110
  if match_by_id:
111
  new_data.set_index(match_by_id, inplace=True)
112
 
113
+ # Update objects in a more efficient way using .items()
114
  for local_id, updates in new_data.iterrows():
115
  target_object = id_to_object_map.get(str(local_id))
116
  if target_object:
117
+ for col_name, value in updates.items():
118
  target_object[col_name] = value
119
 
120
  # Send updated objects back to Speckle
 
125
  return objects_raw # as back-up
126
 
127
 
128
+
129
 
130
  def getSpeckleStream(stream_id,
131
  branch_name,