add chart for grid buy and sell prices

This commit is contained in:
Chris Oloff 2025-11-20 15:36:32 +02:00
parent 42f9c4a284
commit 09edceb73c

View file

@ -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'),
],