Skip to content

Commit

Permalink
Initial attempt at new figures
Browse files Browse the repository at this point in the history
  • Loading branch information
tsmbland committed Nov 2, 2023
1 parent eddd6bf commit 0727b15
Show file tree
Hide file tree
Showing 3 changed files with 340 additions and 0 deletions.
11 changes: 11 additions & 0 deletions app/core_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@
"states": {"load": {"url": f"{PLOT_URL}/supplydemand"}},
},
},
"Market IN PROGRESS": {
"x": 0,
"y": 0,
"w": 1920,
"h": 1080,
"space": "PC01-Left",
"app": {
"url": f"{API_URL}/app/html",
"states": {"load": {"url": f"{PLOT_URL}/market"}},
},
},
"Markets and Reserve": {
"x": 0,
"y": 0,
Expand Down
181 changes: 181 additions & 0 deletions app/figures.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""Functions for generating plotly express figures."""
import pandas as pd
import plotly.express as px # type: ignore
import plotly.graph_objects as go # type: ignore
from plotly.subplots import make_subplots # type: ignore


def generate_gen_split_fig(df: pd.DataFrame) -> px.pie:
Expand Down Expand Up @@ -110,3 +112,182 @@ def generate_system_freq_fig(df: pd.DataFrame) -> px.line:
],
).update_layout(yaxis_title="GW")
return system_freq_fig


def generate_intraday_market_sys_fig(df: pd.DataFrame) -> go:
"""Creates Plotly figure for Intra-day Market System graph.
Args:
df: Opal data DataFrame
Returns:
Plotly graph_objects figure
"""
intraday_market_sys_fig = make_subplots(specs=[[{"secondary_y": True}]])

if len(df.columns) == 1:
return intraday_market_sys_fig

intraday_market_sys_fig_left = px.line(
df,
x="Time",
y=[
"Intra-day Market Generation",
"Intra-day Market Storage",
"Intra-day Market Demand",
],
).update_layout(yaxis_title="Power")

intraday_market_sys_fig_right = (
px.line(
df,
x="Time",
y=[
"Intra-day Market Value",
],
)
.update_layout(yaxis_title="Cost")
.update_traces(yaxis="y2")
)

intraday_market_sys_fig.add_traces(
intraday_market_sys_fig_left.data + intraday_market_sys_fig_right.data
)

return intraday_market_sys_fig


def generate_balancing_market_fig(df: pd.DataFrame) -> go:
"""Creates Plotly figure for Balancing Market graph.
Args:
df: Opal data DataFrame
Returns:
Plotly graph_objects figure
"""
balancing_market_fig = make_subplots(specs=[[{"secondary_y": True}]])

if len(df.columns) == 1:
return balancing_market_fig

balancing_market_fig_left = px.line(
df,
x="Time",
y=[
"Balancing Mechanism Generation",
"Balancing Mechanism Storage",
"Balancing Mechanism Deman",
],
).update_layout(yaxis_title="Power")

balancing_market_fig_right = (
px.line(
df,
x="Time",
y=[
"Balancing Mechanism Value",
],
)
.update_layout(yaxis_title="Cost")
.update_traces(yaxis="y2")
)

balancing_market_fig.add_traces(
balancing_market_fig_left.data + balancing_market_fig_right.data
)

return balancing_market_fig


def generate_energy_deficit_fig(df: pd.DataFrame) -> px.line:
"""Creates Plotly figure for Energy Deficit graph.
Args:
df: Opal data DataFrame
Returns:
Plotly express figure
"""
if len(df.columns) == 1:
energy_deficit_fig = px.line()
else:
energy_deficit_fig = px.line(
df, x="Time", y=df.offwind_exp - df.offwind_real
).update_layout(yaxis_title="GW")

return energy_deficit_fig


def generate_intraday_market_bids_fig(df: pd.DataFrame) -> go.Figure:
"""Creates plotly Figure object for Intraday Market Bids and Offers table.
Args:
df: Opal data DataFrame
Returns:
Plotly graph_objects figure
"""
if len(df.columns) == 1:
intraday_market_bids_fig = go.Figure()

else:
intraday_market_bids_fig = go.Figure(
data=[
go.Table(
header=dict(values=list(df.columns), align="left"),
cells=dict(values=[df.total_gen, df.total_dem], align="left"),
)
]
)

return intraday_market_bids_fig


def generate_dsr_bids_fig(df: pd.DataFrame) -> go.Figure:
"""Creates plotly Figure object for DSR Bids and Offers table.
Args:
df: Opal data DataFrame
Returns:
Plotly graph_objects figure
"""
if len(df.columns) == 1:
dsr_bids_fig = go.Figure()

else:
dsr_bids_fig = go.Figure(
data=[
go.Table(
header=dict(values=list(df.columns), align="left"),
cells=dict(values=[df.total_gen, df.total_dem], align="left"),
)
]
)

return dsr_bids_fig


def generate_dsr_commands_fig(df: pd.DataFrame) -> px.line:
"""Creates Plotly figure for DSR Commands to Agents graph.
Args:
df: Opal data DataFrame
Returns:
Plotly express figure
"""
if len(df.columns) == 1:
dsr_commands_fig = px.line()
else:
dsr_commands_fig = px.line(
df,
x="Time",
y=[
df.real_dem - df.exp_dem + (df.real_ev - df.exp_ev),
df.real_ev - df.exp_ev,
],
).update_layout(yaxis_title="XXXXXXX")

return dsr_commands_fig
148 changes: 148 additions & 0 deletions app/pages/market.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
"""Page in dash app."""


import dash # type: ignore
import pandas as pd
from dash import Input, Output, callback, dcc, html # type: ignore
from dash.exceptions import PreventUpdate # type: ignore

from .. import datahub_api as datahub
from ..figures import (
generate_intraday_market_sys_fig,
generate_balancing_market_fig,
generate_energy_deficit_fig,
generate_intraday_market_bids_fig,
generate_dsr_bids_fig,
generate_dsr_commands_fig,
)

dash.register_page(__name__)

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

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

intraday_market_sys_fig = generate_intraday_market_sys_fig(df)
balancing_market_fig = generate_balancing_market_fig(df)
energy_deficit_fig = generate_energy_deficit_fig(df)
intraday_market_bids_fig = generate_intraday_market_bids_fig(df)
dsr_bids_fig = generate_dsr_bids_fig(df)
dsr_commands_fig = generate_dsr_commands_fig(df)

layout = html.Div(
style={
"display": "flex",
"flex-direction": "column",
"justify-content": "space-around",
},
children=[
html.Div(
style={"display": "flex", "justify-content": "space-around"},
children=[
html.Div(
style={"width": "48%"},
children=[
html.H1("Intra-day Market System"),
dcc.Graph(
id="graph-intraday-market-sys",
figure=intraday_market_sys_fig,
style={"height": "40vh"},
),
],
),
html.Div(
style={"width": "48%"},
children=[
html.H1("Balancing Market"),
dcc.Graph(
id="graph-balancing-market",
figure=balancing_market_fig,
style={"height": "40vh"},
),
],
),
html.Div(
style={"width": "48%"},
children=[
html.H1("Energy Deficit"),
dcc.Graph(
id="graph-energy-deficit",
figure=energy_deficit_fig,
style={"height": "40vh"},
),
],
),
],
),
html.Div(
style={"display": "flex", "justify-content": "space-around"},
children=[
html.Div(
style={"width": "48%"},
children=[
html.H1("Intraday Market Bids and Offers"),
dcc.Graph(
id="table-intraday-market-bids",
figure=intraday_market_bids_fig,
style={"height": "40vh"},
),
],
),
html.Div(
style={"width": "48%"},
children=[
html.H1("DSR Bids and Offers"),
dcc.Graph(
id="table-dsr-bids",
figure=dsr_bids_fig,
style={"height": "40vh"},
),
],
),
html.Div(
style={"width": "48%"},
children=[
html.H1("DSR Commands to Agents"),
dcc.Graph(
id="graph-dsr-commands",
figure=dsr_commands_fig,
style={"height": "40vh"},
),
],
),
],
),
dcc.Interval(id="interval", interval=interval),
],
)


@callback(
[
Output("graph-intraday-market-sys", "figure"),
Output("graph-balancing-market", "figure"),
Output("graph-energy-deficit", "figure"),
Output("table-intraday-market-bids", "figure"),
Output("table-dsr-bids", "figure"),
Output("graph-dsr-commands", "figure"),
],
[Input("interval", "n_intervals")],
)
def update_data(n_intervals): # type: ignore # noqa
if n_intervals is None:
raise PreventUpdate

data = datahub.get_opal_data()

new_df = pd.DataFrame(**data)

intraday_market_sys_fig = generate_intraday_market_sys_fig(new_df)
balancing_market_fig = generate_balancing_market_fig(new_df)
energy_deficit_fig = generate_energy_deficit_fig(new_df)
intraday_market_bids_fig = generate_intraday_market_bids_fig(new_df)
dsr_bids_fig = generate_dsr_bids_fig(new_df)
dsr_commands_fig = generate_dsr_commands_fig(new_df)
return (intraday_market_sys_fig, balancing_market_fig, energy_deficit_fig,
intraday_market_bids_fig, dsr_bids_fig, dsr_commands_fig)

0 comments on commit 0727b15

Please sign in to comment.