Skip to content

Commit d412c42

Browse files
fix update
1 parent aff9829 commit d412c42

File tree

5 files changed

+69
-31
lines changed

5 files changed

+69
-31
lines changed

app/callbacks/data_callbacks.py

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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
)
217231
def 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
[

app/callbacks/display_callbacks.py

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,10 @@ def update_fire_markers(smoke_location_str, api_sequences):
550550
Input("confirm-non-wildfire", "n_clicks"),
551551
Input("cancel-confirmation", "n_clicks"),
552552
],
553-
[State("sequence_id_on_display", "data"), State("user_token", "data")],
553+
[
554+
State("sequence_id_on_display", "data"),
555+
State("user_token", "data"),
556+
],
554557
prevent_initial_call=True,
555558
)
556559
def acknowledge_event(
@@ -561,14 +564,13 @@ def acknowledge_event(
561564
logger.info("acknowledge_event")
562565

563566
if not ctx.triggered:
564-
raise dash.exceptions.PreventUpdate
567+
raise PreventUpdate
565568

566569
if user_token is None:
567-
return dash.no_update
570+
raise PreventUpdate
568571

569572
triggered_id = ctx.triggered[0]["prop_id"].split(".")[0]
570573

571-
# Modal styles
572574
modal_visible_style = {
573575
"position": "fixed",
574576
"top": "50%",
@@ -580,29 +582,31 @@ def acknowledge_event(
580582
modal_hidden_style = {"display": "none"}
581583

582584
client = get_client(user_token)
585+
client.token = user_token
583586

584587
if triggered_id == "acknowledge-button":
585-
# Show the modal
586-
if acknowledge_clicks > 0:
587-
return modal_visible_style, dash.no_update
588+
if acknowledge_clicks is None or acknowledge_clicks == 0:
589+
raise PreventUpdate
590+
return modal_visible_style, dash.no_update
588591

589592
elif triggered_id == "confirm-wildfire":
590-
# Send wildfire confirmation to the API
591-
client.token = user_token
593+
if confirm_wildfire is None or confirm_wildfire == 0:
594+
raise PreventUpdate
592595
client.label_sequence(sequence_id_on_display, True)
593596
return modal_hidden_style, sequence_id_on_display
594597

595598
elif triggered_id == "confirm-non-wildfire":
596-
# Send non-wildfire confirmation to the API
597-
client.token = user_token
599+
if confirm_non_wildfire is None or confirm_non_wildfire == 0:
600+
raise PreventUpdate
598601
client.label_sequence(sequence_id_on_display, False)
599602
return modal_hidden_style, sequence_id_on_display
600603

601604
elif triggered_id == "cancel-confirmation":
602-
# Cancel action
605+
if cancel is None or cancel == 0:
606+
raise PreventUpdate
603607
return modal_hidden_style, dash.no_update
604608

605-
raise dash.exceptions.PreventUpdate
609+
raise PreventUpdate
606610

607611

608612
# Modal issue let's add this later
@@ -749,12 +753,15 @@ def update_datepicker(open_clicks, selected_date):
749753
def pick_live_stream_camera(n_clicks, azimuth, camera_label, azimuth_label):
750754
logger.info("pick_live_stream_camera")
751755

756+
if n_clicks is None or n_clicks == 0:
757+
raise PreventUpdate
758+
752759
if not camera_label or not azimuth_label:
753760
raise PreventUpdate
761+
754762
try:
755763
cam_name, _, _ = camera_label.split(" ")
756764
azimuth = int(azimuth.replace("°", ""))
757-
# detection_azimuth = int(azimuth_label.replace("°", "").strip()) Need azimuth refine first
758765
except Exception as e:
759766
logger.warning(f"[pick_live_stream_camera] Failed to parse camera info: {e}")
760767
raise PreventUpdate

app/index.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,11 @@ def display_page(
5858
if triggered == "selected-camera-info" and selected_camera_info:
5959
return live_stream_layout(user_token, api_cameras, available_stream, selected_camera_info, lang=lang)
6060

61-
if (pathname == "/" or pathname is None) or triggered == "my-date-picker-single":
62-
return homepage_layout(user_token, api_cameras, lang=lang)
61+
if triggered == "my-date-picker-single":
62+
return homepage_layout(user_token, api_cameras, lang=lang, descending_order=False)
63+
64+
if pathname in ["/", None]:
65+
return homepage_layout(user_token, api_cameras, lang=lang, descending_order=True)
6366

6467
if pathname == "/cameras-status":
6568
return cameras_status_layout(user_token, api_cameras, lang=lang)

app/layouts/main_layout.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,5 @@ def get_main_layout():
8686
dcc.Store(id="selected-camera-info", storage_type="session"),
8787
dcc.Store(id="language", storage_type="session", data="fr"),
8888
dcc.Store(id="selected_event_id", storage_type="session", data=None),
89+
dcc.Store(id="detection_fetch_limit", storage_type="session", data=10),
8990
])

app/pages/homepage.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from utils.display import build_alerts_map
1313

1414

15-
def homepage_layout(user_token, api_cameras, lang="fr"):
15+
def homepage_layout(user_token, api_cameras, lang="fr", descending_order=True):
1616
return dbc.Container(
1717
[
1818
dbc.Row([
@@ -35,7 +35,7 @@ def homepage_layout(user_token, api_cameras, lang="fr"):
3535
dbc.Checklist(
3636
id="detection_fetch_desc",
3737
options=[{"value": True}],
38-
value=[True],
38+
value=[descending_order],
3939
switch=True,
4040
),
4141
html.Hr(className="my-3"),

0 commit comments

Comments
 (0)