Skip to content

Commit

Permalink
Terminate updates at end of pre-set data
Browse files Browse the repository at this point in the history
  • Loading branch information
tsmbland committed Dec 12, 2023
1 parent fcbb679 commit c6f9103
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
23 changes: 13 additions & 10 deletions app/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,22 @@
WESIM = {"df": pd.DataFrame({"Col": [0]})}

data_interval = dcc.Interval(id="data_interval", interval=interval)
empty_output = dcc.Store(id="empty", data=[])


@callback(
[Output("empty", "data")],
[Output("data_interval", "disabled")],
[Input("data_interval", "n_intervals")],
)
def update_data(n_intervals: int) -> tuple[list[None],]:
"""Function to update the data.
def update_data(n_intervals: int) -> tuple[bool,]:
"""Function to update OPAL data.
Args:
n_intervals (int): The number of times this page has updated.
indexes by 1 every 7 seconds.
n_intervals (int): The number of times the data has updated.
indexes by 1 every interval.
Returns:
Opal data dictionary
tuple[bool,]: Boolean that specifies whether the iterator should
terminate
"""
global DF_OPAL
Expand All @@ -49,12 +49,15 @@ def update_data(n_intervals: int) -> tuple[list[None],]:
raise PreventUpdate

if LIVE_MODEL:
log.debug("Updating plots from live model")
log.debug("Updating data from live model")
data_opal = get_opal_data()
DF_OPAL = pd.DataFrame(**data_opal) # type: ignore[call-overload]
else:
from .pre_set_data import OPAL_DATA

log.debug("Updating plots with pre-set data")
log.debug("Updating pre-set data")
DF_OPAL = OPAL_DATA.loc[:n_intervals]
return ([],)
if n_intervals == len(OPAL_DATA):
log.debug("Reached end of pre-set data")
return (True,)
return (False,)
5 changes: 2 additions & 3 deletions app/pages/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from .. import core_api as core
from .. import log
from ..data import data_interval, empty_output
from ..data import data_interval

dash.register_page(__name__)

Expand Down Expand Up @@ -182,7 +182,7 @@ def get_button(func: str, icon: str) -> html.Button:
min=1,
max=10,
step=1,
value=7,
value=data_interval.interval / 1000,
),
style={"width": "100%"},
),
Expand Down Expand Up @@ -216,7 +216,6 @@ def get_button(func: str, icon: str) -> html.Button:
],
),
data_interval,
empty_output,
],
)

Expand Down

0 comments on commit c6f9103

Please sign in to comment.