add chart for grid buy and sell prices
This commit is contained in:
parent
42f9c4a284
commit
09edceb73c
1 changed files with 42 additions and 0 deletions
42
sample2.py
42
sample2.py
|
|
@ -31,6 +31,8 @@ class SystemState(BaseModel):
|
||||||
load_forecast: LoadForecast = LoadForecast()
|
load_forecast: LoadForecast = LoadForecast()
|
||||||
pv_forecast: PvForecast = PvForecast()
|
pv_forecast: PvForecast = PvForecast()
|
||||||
now: datetime = datetime.now()
|
now: datetime = datetime.now()
|
||||||
|
sell_prices: list[float] = []
|
||||||
|
buy_prices: list[float] = []
|
||||||
output: Output | None = None
|
output: Output | None = None
|
||||||
|
|
||||||
state: SystemState = panel.rx(lambda s: SystemState.model_validate(s) if s else SystemState())(w42_state)
|
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)
|
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"
|
datetime_fmt = "%Y-%m-%d %H:%M:%S"
|
||||||
|
|
||||||
value = w42_state.rx.value
|
value = w42_state.rx.value
|
||||||
|
|
@ -114,6 +151,11 @@ _ = panel.template.FastListTemplate(
|
||||||
sizing_mode='stretch_width',
|
sizing_mode='stretch_width',
|
||||||
height=400
|
height=400
|
||||||
),
|
),
|
||||||
|
panel.pane.ECharts(
|
||||||
|
prices_chart_rx,
|
||||||
|
sizing_mode='stretch_width',
|
||||||
|
height=300
|
||||||
|
),
|
||||||
w42_state,
|
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'),
|
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'),
|
||||||
],
|
],
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue