Skip to content

Commit

Permalink
Synchronise figure updates with data updates
Browse files Browse the repository at this point in the history
  • Loading branch information
tsmbland committed Dec 12, 2023
1 parent ba18de7 commit 5026579
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 13 deletions.
29 changes: 23 additions & 6 deletions app/app.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
"""Sets up the server for the Dash app."""
import dash # type: ignore
from dash import Dash, dcc, html # type: ignore
from dash import Dash, Input, Output, callback, dcc, html # type: ignore

from . import log

##################
interval = 7000
##################

app = Dash(__package__, use_pages=True, update_title=None)

app.layout = html.Div(
Expand All @@ -17,13 +13,34 @@
},
children=[
dash.page_container,
dcc.Interval(id="figure_interval", interval=interval),
dcc.Interval(id="figure_interval"),
],
)

server = app.server
log.info("Gridlington Visualisation System is running...")


@callback(
[Output("figure_interval", "disabled"), Output("figure_interval", "interval")],
[Input("figure_interval", "n_intervals")],
)
def update_interval(
n_intervals: int,
) -> tuple[bool, int]:
"""_summary_.
Args:
n_intervals (int): _description_
Returns:
tuple[bool, int]: _description_
"""
from .data import data_ended
from .pages.control import interval

return (data_ended, interval)


if __name__ == "__main__":
app.run_server(debug=True)
6 changes: 1 addition & 5 deletions app/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
from . import LIVE_MODEL, log
from .datahub_api import get_opal_data, get_wesim_data # , get_dsr_data

##################
interval = 7000
##################

DF_OPAL = pd.DataFrame({"Col": [0]})

WESIM_START_DATE = "2035-01-22 00:00" # corresponding to hour 0 TODO: check
Expand All @@ -24,7 +20,7 @@
else:
WESIM = {"df": pd.DataFrame({"Col": [0]})}

data_interval = dcc.Interval(id="data_interval", interval=interval)
data_interval = dcc.Interval(id="data_interval")
data_ended = False


Expand Down
10 changes: 8 additions & 2 deletions app/pages/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

dash.register_page(__name__)

##################
interval = 7000
##################

options = [key for key in core.INIT_SECTIONS.keys() if key != "Control"]

Expand Down Expand Up @@ -179,10 +182,10 @@ def get_button(func: str, icon: str) -> html.Button:
html.Div(
dcc.Slider(
id="update-interval-slider",
min=1,
min=2,
max=10,
step=1,
value=data_interval.interval / 1000,
value=interval / 1000,
),
style={"width": "100%"},
),
Expand Down Expand Up @@ -333,5 +336,8 @@ def default_button_click(n_clicks: int | None) -> list[str]:
)
def update_interval(value: int) -> list[int]:
"""Returns the update interval value."""
global interval

log.debug(f"Update interval set to {value} seconds.")
interval = value * 1000
return [value * 1000]

0 comments on commit 5026579

Please sign in to comment.