Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intercept KeyError on navigation straight to the metadata tab without adding a config. #95

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
16 changes: 5 additions & 11 deletions tests/test_integration/test_common_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,12 @@ def test_components_created(

# wait for sidebar to be rendered
try:
dash_duo.wait_for_text_to_equal(
"#sidebar h2", "WAZP 🐝", timeout=timeout
)
dash_duo.wait_for_text_to_equal("#sidebar h2", "WAZP 🐝", timeout=timeout)
except selenium.common.exceptions.TimeoutException:
pytest.fail("Sidebar component not generated")

# check there are no errors in browser console
assert (
dash_duo.get_logs() == []
), f"There are {len(dash_duo.get_logs())} errors"
assert dash_duo.get_logs() == [], f"There are {len(dash_duo.get_logs())} errors"
" in the browser console!"


Expand All @@ -70,8 +66,8 @@ def test_components_created(
pytest.param(fx, marks=mark)
for fx, mark in [
("home_page_name_and_title", []),
("metadata_page_name_and_title", unloaded_config_xfail),
("roi_page_name_and_title", unloaded_config_xfail),
("metadata_page_name_and_title", []),
("roi_page_name_and_title", []),
("pose_estimation_page_name_and_title", []),
("dashboard_page_name_and_title", unloaded_config_xfail),
]
Expand Down Expand Up @@ -133,6 +129,4 @@ def test_sidebar_links(
# ...

# NOTE: this is expected to fail for a few pages (hence the marked xfails)
assert (
dash_duo.get_logs() == []
), "There are errors in the browser console!"
assert dash_duo.get_logs() == [], "There are errors in the browser console!"
2 changes: 1 addition & 1 deletion wazp/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
storage = dcc.Store(
id="session-storage",
storage_type="session",
data=tuple(),
data={},
)

###############
Expand Down
8 changes: 8 additions & 0 deletions wazp/callbacks/_common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from dash import html

NO_CONFIG_MESSAGE = html.Div(
children="No configuration loaded. Please add a "
"configuration file from the 'Home' page."
)

VIDEO_TYPES = [".avi", ".mp4"]
21 changes: 17 additions & 4 deletions wazp/callbacks/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import io
import pathlib as pl
import re
import warnings
from typing import Union

import dash
import dash_bootstrap_components as dbc
Expand All @@ -10,9 +12,7 @@
from dash import Input, Output, State, dash_table, dcc, html

from wazp import utils

# TODO: other video extensions? have this in project config file instead?
VIDEO_TYPES = [".avi", ".mp4"]
from wazp.callbacks._common import NO_CONFIG_MESSAGE, VIDEO_TYPES


##########################
Expand Down Expand Up @@ -215,7 +215,7 @@ def get_callbacks(app: dash.Dash) -> None:
)
def create_metadata_table_and_buttons(
metadata_output_children: list, app_storage: dict
) -> html.Div:
) -> Union[html.Div, None]:
"""Generate html component with a table holding the
metadata per video and with auxiliary buttons for
common table manipulations.
Expand All @@ -237,8 +237,20 @@ def create_metadata_table_and_buttons(
html.Div
html component holding the metadata dash_table and
the auxiliary buttons for common table manipulations

Warns
-----
UserWarning
If no configuration is found (from navigating directly
to the ROI tab, for example).
"""

if not app_storage:
# we've likely navigated to the metadata page without an input
# config yaml file... not necessarily an error
warnings.warn("Configuration not yet loaded.")
return NO_CONFIG_MESSAGE

if not metadata_output_children:
metadata_table = create_metadata_table_component_from_df(
utils.df_from_metadata_yaml_files(
Expand Down Expand Up @@ -367,6 +379,7 @@ def create_metadata_table_and_buttons(
generate_yaml_tooltip,
]
)
return None
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if we ever get into this situation? Should I throw an error? Or return an empty Div?


@app.callback(
Output("metadata-table", "data"),
Expand Down
5 changes: 3 additions & 2 deletions wazp/callbacks/roi.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@
from PIL import Image

from wazp import utils
from wazp.callbacks._common import VIDEO_TYPES

# TODO: other video extensions? have this in project config file instead?
VIDEO_TYPES = [".avi", ".mp4"]
ROI_CMAP = px.colors.qualitative.Dark24


Expand Down Expand Up @@ -521,6 +520,8 @@ def update_frame_graph(
int
Maximum frame index (num_frames - 1)
"""
if not roi_color_mapping:
return dash.no_update, "", "light", False

# If a negative frame index is passed, it means that the video
# could not be read correctly. So don't update the frame,
Expand Down