Skip to content

Commit

Permalink
button click updates event storage and event table
Browse files Browse the repository at this point in the history
  • Loading branch information
niksirbi committed Apr 3, 2023
1 parent 5d44bbb commit 4636fb1
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 3 deletions.
110 changes: 109 additions & 1 deletion wazp/callbacks/events.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import dash
from dash import Input, Output
from dash import Input, Output, State


def get_callbacks(app: dash.Dash) -> None:
Expand Down Expand Up @@ -87,3 +87,111 @@ def update_event_select_options(
return options, value
else:
return dash.no_update, dash.no_update

@app.callback(
Output("tag-event-button", "disabled"),
Input("event-select", "value"),
)
def disable_tag_event_button(
event_tag: str,
) -> bool:
"""Disable the tag event button if the event tag is empty
Parameters
----------
event_tag : str
Currently selected event tag
Returns
-------
disabled : bool
True if the tag event button should be disabled, False otherwise
"""
if event_tag == "" or event_tag is None:
return True
else:
return False

@app.callback(
Output("events-storage", "data"),
Input("tag-event-button", "n_clicks"),
[
State("frame-index-input", "value"),
State("events-video-select", "value"),
State("event-select", "value"),
State("events-storage", "data"),
],
)
def update_events_storage(
n_clicks: int,
frame_index: int,
video_name: str,
event_tag: str,
events_storage: dict,
) -> dict:
"""Update the events storage with the currently selected event tag
and frame index, when the tag event button is clicked.
Parameters
----------
n_clicks : int
Number of times the tag event button has been clicked
frame_index : int
Currently selected frame index
video_name : str
Currently selected video name
event_tag : str
Currently selected event tag
events_storage : dict
Dictionary storing event tags for each video.
Returns
-------
events_storage : dict
data held in temporary memory storage,
accessible to all tabs in the app
"""
if n_clicks > 0:
if video_name not in events_storage.keys():
events_storage[video_name] = dict()
events_storage[video_name][event_tag] = frame_index
return events_storage

@app.callback(
Output("events-table", "data"),
[
Input("events-video-select", "value"),
Input("events-storage", "data"),
],
)
def update_events_table(
video_name: str,
events_storage: dict,
) -> list[dict]:
"""Update the events table based on the stored events.
Parameters
----------
video_name : str
Currently selected video name
events_storage : dict
Dictionary storing event tags for each video.
Returns
-------
data : list[dict]
list of dictionaries with the following keys and values:
- 'tag': event tag
- 'frame index': frame index
- 'seconds': frame index converted to seconds, based on the
video FPS
"""
fps = 40
rows = []
if video_name in events_storage.keys():
for event, frame_idx in events_storage[video_name].items():
sec = frame_idx / fps
rows.append(
{"tag": event, "frame index": frame_idx, "seconds": sec}
)
return rows
4 changes: 2 additions & 2 deletions wazp/pages/03_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
###############################

# Get initial video
init_videos = ["No videos found yet"]
init_videos = [""]
# Get initial set of event tags to initialize table
init_event_tags = ["start", "end"]
init_event_tags = [""]

# Columns for events table
init_events_table_columns = ["tag", "frame index", "seconds"]
Expand Down

0 comments on commit 4636fb1

Please sign in to comment.