sample2 improvements

This commit is contained in:
Chris Oloff 2025-11-20 08:46:12 +02:00
parent 47b5263874
commit 15e99c9c4a

View file

@ -18,9 +18,17 @@ class LoadForecast(BaseModel):
async def update(self, now: datetime) -> None:
pass
class Output(BaseModel):
target_storage: float
target_geyser_temperature: float
storage: list[float]
grid_sell: list[float]
grid_buy: list[float]
class SystemState(BaseModel):
load_forecast: LoadForecast = LoadForecast()
now: datetime = datetime.now()
output: Output | None = None
state: SystemState = panel.rx(lambda s: SystemState.model_validate(s) if s else SystemState())(w42_state)
@ -39,12 +47,14 @@ def get_label(at: datetime, slot_index: int) -> str:
def load_fc_chart(state: SystemState) -> dict:
slots = state.load_forecast.slots
at = state.load_forecast.at
storage = state.output.storage if state.output else [0] * len(slots)
battery = [storage[ix] - storage[ix-1] if ix > 0 else 0 for ix in range(len(slots))] if state.output else [0] * len(slots)
return {
'title': {
'text': '24hr Forecast'
},
'legend': {
'data': ['Load Forecast']
'data': ['Load Forecast', 'Battery Storage', 'Battery in/out']
},
'tooltip': {
'trigger': 'axis'
@ -56,11 +66,23 @@ def load_fc_chart(state: SystemState) -> dict:
'yAxis': {
'type': 'value'
},
'series': [{
'name': 'Load Forecast',
'data': slots,
'type': 'line'
}]
'series': [
{
'name': 'Load Forecast',
'data': slots,
'type': 'line'
}, {
'name': 'Battery Storage',
'data': storage,
'type': 'line',
'color': 'orange'
}, {
'name': 'Battery in/out',
'data': battery,
'type': 'line',
'color': 'lightblue'
}
]
}
load_fc_chart_rx = panel.rx(load_fc_chart)(state)