From c6f91031107b2ef9e34695e8677baeb82b534ba7 Mon Sep 17 00:00:00 2001 From: Tom Bland <tom_bland@hotmail.co.uk> Date: Tue, 12 Dec 2023 15:03:26 +0000 Subject: [PATCH] Terminate updates at end of pre-set data --- app/data.py | 23 +++++++++++++---------- app/pages/control.py | 5 ++--- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/app/data.py b/app/data.py index 67d0612..91a0250 100644 --- a/app/data.py +++ b/app/data.py @@ -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 @@ -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,) diff --git a/app/pages/control.py b/app/pages/control.py index 7ddd74a..709f6ee 100644 --- a/app/pages/control.py +++ b/app/pages/control.py @@ -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__) @@ -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%"}, ), @@ -216,7 +216,6 @@ def get_button(func: str, icon: str) -> html.Button: ], ), data_interval, - empty_output, ], )