diff --git a/sample2.py b/sample2.py index 033a633..7829d8e 100644 --- a/sample2.py +++ b/sample2.py @@ -31,6 +31,8 @@ class SystemState(BaseModel): load_forecast: LoadForecast = LoadForecast() pv_forecast: PvForecast = PvForecast() now: datetime = datetime.now() + sell_prices: list[float] = [] + buy_prices: list[float] = [] output: Output | None = None state: SystemState = panel.rx(lambda s: SystemState.model_validate(s) if s else SystemState())(w42_state) @@ -100,6 +102,41 @@ def load_fc_chart(state: SystemState) -> dict: load_fc_chart_rx = panel.rx(load_fc_chart)(state) +def prices_chart(state: SystemState) -> dict: + return { + 'title': { + 'text': 'Electricity Prices' + }, + 'legend': { + 'data': ['Sell Prices', 'Buy Prices'] + }, + 'tooltip': { + 'trigger': 'axis' + }, + 'xAxis': { + 'type': 'category', + 'data': [get_label(state.now, i) for i in range(len(state.sell_prices))] + }, + 'yAxis': { + 'type': 'value' + }, + 'series': [ + { + 'name': 'Sell Prices', + 'data': state.sell_prices, + 'type': 'line', + 'color': 'green' + }, { + 'name': 'Buy Prices', + 'data': state.buy_prices, + 'type': 'line', + 'color': 'red' + } + ] + } + +prices_chart_rx = panel.rx(prices_chart)(state) + datetime_fmt = "%Y-%m-%d %H:%M:%S" value = w42_state.rx.value @@ -114,6 +151,11 @@ _ = panel.template.FastListTemplate( sizing_mode='stretch_width', height=400 ), + panel.pane.ECharts( + prices_chart_rx, + sizing_mode='stretch_width', + height=300 + ), w42_state, panel.pane.Markdown(panel.bind(lambda s: f"State at {s.now.strftime(datetime_fmt)}, Load Forecast Time: {s.load_forecast.at}", state), sizing_mode='stretch_width'), ],