@@ -134,6 +134,20 @@ def login_callback(n_clicks, username, password, user_token, lang):
134134 raise PreventUpdate
135135
136136
137+ from dash import Input , Output , State , callback
138+
139+
140+ @callback (
141+ Output ("detection_fetch_limit" , "data" ),
142+ Input ("detection_fetch_limit_input" , "value" ),
143+ prevent_initial_call = True , # optional, remove if you want it to run on first load
144+ )
145+ def update_fetch_limit (value ):
146+ if value is None :
147+ return 10 # fallback default
148+ return value
149+
150+
137151@app .callback (
138152 Output ("available-stream-sites" , "data" ),
139153 Input ("user_name" , "data" ),
@@ -207,19 +221,19 @@ def api_cameras_watcher(n_intervals, api_cameras, user_token):
207221 [
208222 Input ("main_api_fetch_interval" , "n_intervals" ),
209223 Input ("api_cameras" , "data" ),
210- Input ("my-date-picker-single" , "date" ),
211224 Input ("to_acknowledge" , "data" ),
212225 Input ("unmatched_event_id_table" , "data" ),
226+ Input ("my-date-picker-single" , "date" ),
213227 ],
214228 [State ("api_sequences" , "data" ), State ("user_token" , "data" ), State ("event_id_table" , "data" )],
215229 prevent_initial_call = True ,
216230)
217231def api_watcher (
218232 n_intervals ,
219233 api_cameras ,
220- selected_date ,
221234 to_acknowledge ,
222235 unmatched_event_id_table ,
236+ selected_date ,
223237 local_sequences ,
224238 user_token ,
225239 local_event_id_table ,
@@ -285,19 +299,32 @@ def api_watcher(
285299 api_sequences , event_id_table = compute_overlap (
286300 api_sequences , unmatched_event_table = unmatched_event_id_table
287301 )
302+
303+ print ("event_id_table" )
304+ print (event_id_table )
288305 local_event_id_table = pd .read_json (StringIO (local_event_id_table ), orient = "split" )
289306
290- # Load local sequences safely
291- if local_sequences :
292- local_sequences_df = pd .read_json (StringIO (local_sequences ), orient = "split" )
293- else :
294- local_sequences_df = pd .DataFrame ()
307+ # Load local sequences safely
308+ if local_sequences :
309+ local_sequences_df = pd .read_json (StringIO (local_sequences ), orient = "split" )
310+ else :
311+ local_sequences_df = pd .DataFrame ()
312+
313+ # Ensure valid DataFrames
314+ if not isinstance (local_event_id_table , pd .DataFrame ):
315+ local_event_id_table = pd .DataFrame ()
316+ if not isinstance (event_id_table , pd .DataFrame ):
317+ event_id_table = pd .DataFrame ()
318+
319+ # Check event condition: either empty or sequences match
320+ event_condition = event_id_table .empty or (
321+ "sequences" in local_event_id_table .columns
322+ and "sequences" in event_id_table .columns
323+ and np .array_equal (local_event_id_table ["sequences" ].values , event_id_table ["sequences" ].values )
324+ )
295325
296- if len (local_event_id_table ) == len (event_id_table ):
297- if len (event_id_table ) == 0 or (
298- np .array_equal (local_event_id_table ["sequences" ].values , event_id_table ["sequences" ].values )
299- ):
300- # Skip update if nothing changed
326+ # Now apply sequence comparison only if event condition is true
327+ if event_condition :
301328 if not local_sequences_df .empty and not api_sequences .empty :
302329 if not sequences_have_changed (api_sequences , local_sequences_df ):
303330 logger .info ("Skipping update: no significant change detected" )
@@ -352,7 +379,7 @@ def update_sub_api_sequences(api_sequences, local_sub_sequences):
352379 [Output ("are_detections_loaded" , "data" ), Output ("sequence_on_display" , "data" ), Output ("api_detections" , "data" )],
353380 [
354381 Input ("sequence_id_on_display" , "data" ),
355- Input ("detection_fetch_limit_input " , "value " ),
382+ Input ("detection_fetch_limit " , "data " ),
356383 Input ("detection_fetch_desc" , "value" ),
357384 ],
358385 [
0 commit comments