Skip to content

Commit 9c4247e

Browse files
display label
1 parent f807cf7 commit 9c4247e

File tree

3 files changed

+38
-24
lines changed

3 files changed

+38
-24
lines changed

app/callbacks/data_callbacks.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,14 +193,15 @@ def api_cameras_watcher(n_intervals, api_cameras, user_token):
193193
Input("main_api_fetch_interval", "n_intervals"),
194194
Input("api_cameras", "data"),
195195
Input("my-date-picker-single", "date"), # NEW: date picker input
196+
Input("to_acknowledge", "data"),
196197
],
197198
[
198199
State("api_sequences", "data"),
199200
State("user_token", "data"),
200201
],
201202
prevent_initial_call=True,
202203
)
203-
def api_watcher(n_intervals, api_cameras, selected_date, local_sequences, user_token):
204+
def api_watcher(n_intervals, api_cameras, selected_date, to_acknowledge, local_sequences, user_token):
204205
"""
205206
Callback to periodically fetch alerts data from the API or after date change.
206207
@@ -242,8 +243,17 @@ def api_watcher(n_intervals, api_cameras, selected_date, local_sequences, user_t
242243

243244
# Skip update if nothing changed
244245
if not local_sequences_df.empty and not api_sequences.empty:
245-
aligned_api, aligned_local = api_sequences["id"].align(local_sequences_df["id"])
246-
if all(aligned_api == aligned_local):
246+
# Merge both DataFrames on 'id' to compare annotations
247+
merged = pd.merge(
248+
api_sequences[["id", "is_wildfire"]],
249+
local_sequences_df[["id", "is_wildfire"]],
250+
on="id",
251+
how="inner",
252+
suffixes=("", "_local"),
253+
)
254+
255+
# If the annotations haven't changed, skip update
256+
if merged["is_wildfire"].equals(merged["is_wildfire_local"]):
247257
return dash.no_update
248258

249259
return api_sequences.to_json(orient="split")

app/callbacks/display_callbacks.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from utils.display import (
2727
build_vision_polygon,
2828
convert_dt_to_local_tz,
29-
create_event_list_from_alerts,
29+
create_sequence_list,
3030
filter_bboxes_dict,
3131
)
3232

@@ -83,17 +83,16 @@ def update_language_store(selected_lang):
8383
Output("sequence-list-container", "children"),
8484
[
8585
Input("api_sequences", "data"),
86-
Input("to_acknowledge", "data"),
8786
],
8887
State("api_cameras", "data"),
88+
State("my-date-picker-single", "date"),
8989
)
90-
def update_event_list(api_sequences, to_acknowledge, cameras):
90+
def update_event_list(api_sequences, cameras, selected_date):
9191
"""
92-
Updates the event list based on changes in the events data or acknowledgement actions.
92+
Updates the event list based on changes in the events data
9393
9494
Parameters:
9595
- api_detections (json): JSON formatted data containing current alerts information.
96-
- to_acknowledge (int): Event ID that is being acknowledged.
9796
9897
Returns:
9998
- html.Div: A Div containing the updated list of alerts.
@@ -103,11 +102,7 @@ def update_event_list(api_sequences, to_acknowledge, cameras):
103102
api_sequences = pd.read_json(StringIO(api_sequences), orient="split")
104103
cameras = pd.read_json(StringIO(cameras), orient="split")
105104

106-
if len(api_sequences):
107-
# Drop acknowledge event for faster update
108-
api_sequences = api_sequences[~api_sequences["id"].isin([to_acknowledge])]
109-
110-
return create_event_list_from_alerts(api_sequences, cameras)
105+
return create_sequence_list(api_sequences, cameras)
111106

112107

113108
# Select the event id

app/utils/display.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -226,38 +226,47 @@ def build_alerts_map(api_cameras, id_suffix=""):
226226
return map_object
227227

228228

229-
def create_event_list_from_alerts(api_events, cameras):
229+
def create_sequence_list(api_sequences, cameras):
230230
"""
231-
This function build the list of events on the left based on event data
231+
This function builds the list of sequences on the left based on sequence data
232232
"""
233-
if api_events.empty:
233+
if api_sequences.empty:
234234
return []
235235

236-
filtered_events = api_events.sort_values("started_at").drop_duplicates("id", keep="last")[::-1]
236+
filtered_sequences = api_sequences.sort_values("started_at").drop_duplicates("id", keep="last")[::-1]
237+
238+
def get_annotation_emoji(value):
239+
if value == 1.0:
240+
return "🔥"
241+
elif value == 0.0:
242+
return "🚫"
243+
else:
244+
return ""
237245

238246
return [
239247
html.Button(
240-
id={"type": "event-button", "index": event["id"]},
248+
id={"type": "event-button", "index": sequence["id"]},
241249
children=[
242250
html.Div(
243251
(
244-
f"{cameras[cameras['id'] == event['camera_id']]['name'].values[0][:-3].replace('_', ' ')}"
245-
f" : {int(event['azimuth'])}°"
252+
f"{cameras[cameras['id'] == sequence['camera_id']]['name'].values[0][:-3].replace('_', ' ')}"
253+
f" : {int(sequence['azimuth'])}°"
254+
f" {get_annotation_emoji(sequence.get('is_wildfire'))}"
246255
),
247256
style={"fontWeight": "bold"},
248257
),
249258
html.Div(
250259
convert_dt_to_local_tz(
251-
lat=cameras[cameras["id"] == event["camera_id"]]["lat"].values[0],
252-
lon=cameras[cameras["id"] == event["camera_id"]]["lon"].values[0],
253-
str_utc_timestamp=event["started_at"],
260+
lat=cameras[cameras["id"] == sequence["camera_id"]]["lat"].values[0],
261+
lon=cameras[cameras["id"] == sequence["camera_id"]]["lon"].values[0],
262+
str_utc_timestamp=sequence["started_at"],
254263
)
255264
),
256265
],
257266
n_clicks=0,
258267
className="pyronear-card alert-card",
259268
)
260-
for _, event in filtered_events.iterrows()
269+
for _, sequence in filtered_sequences.iterrows()
261270
]
262271

263272

0 commit comments

Comments
 (0)