Skip to content

Commit

Permalink
Further Updates to Overview page to replace existing single page view
Browse files Browse the repository at this point in the history
  • Loading branch information
pclemow committed Aug 20, 2024
1 parent 4a54324 commit d1096c2
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 31 deletions.
51 changes: 45 additions & 6 deletions app/figures.py
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ def generate_dsr_fig(df: pd.DataFrame) -> go.Figure:
return dsr_fig


@figure("DSR Commands to Agents")
@figure("Overall Gridlington DSR Action")
@axes(ylabel="MW", yrange=[-8, 8])
def generate_dsr_commands_fig(df: pd.DataFrame) -> px.line:
"""Creates Plotly figure for DSR Commands to Agents graph.
Expand All @@ -757,18 +757,18 @@ def generate_dsr_commands_fig(df: pd.DataFrame) -> px.line:
"Time",
]
].copy()
figure_data["Name"] = ( # TODO: Give this column an appropriate name
figure_data["Home"] = ( # TODO: Give this column an appropriate name
df["Real Gridlington Demand"] - df["Expected Gridlington Demand"]
) + (df["Real Ev Charging Power"] - df["Expected Ev Charging Power"])
figure_data["Name2"] = ( # TODO: Give this column an appropriate name
) - (df["Real Ev Charging Power"] - df["Expected Ev Charging Power"])
figure_data["EV"] = ( # TODO: Give this column an appropriate name
df["Real Ev Charging Power"] - df["Expected Ev Charging Power"]
)
dsr_commands_fig = px.line(
figure_data,
x="Time",
y=[
"Name",
"Name2",
"Home",
"EV",
],
)

Expand All @@ -778,6 +778,45 @@ def generate_dsr_commands_fig(df: pd.DataFrame) -> px.line:
)
return dsr_commands_fig

@figure("EV Charging Demand")
@axes(ylabel="MW", yrange=[-0.5, 4.5])
def generate_ev_demand_fig(df: pd.DataFrame) -> px.line:
"""Creates Plotly figure for EV charging planned vs real.
Args:
df: Opal data DataFrame
Returns:
Plotly express figure
"""
if len(df.columns) == 1:
ev_demand_fig = px.line()
else:
figure_data = df[
[
"Time",
]
].copy()
figure_data["Planned"] = (
df["Expected Ev Charging Power"]
)
figure_data["Actual"] = (
df["Real Ev Charging Power"]
)
ev_demand_fig = px.line(
figure_data,
x="Time",
y=[
"Planned",
"Actual",
],
)

ev_demand_fig.update_layout(
legend_title=None,
legend=dict(font=dict(size=15)),
)
return ev_demand_fig

def sainte_lague_algorithm(votes: list[int], seats: int) -> list[int]:
"""Saint-Lague algorithm for proportional representation in voting.
Expand Down
60 changes: 35 additions & 25 deletions app/pages/overview.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
generate_agent_activity_breakdown_fig,
generate_balancing_market_fig,
generate_dsr_commands_fig,
generate_ev_demand_fig,
generate_energy_deficit_fig,
generate_ev_charging_breakdown_fig,
generate_intraday_market_sys_fig,
Expand All @@ -38,6 +39,7 @@
balancing_market_fig = generate_balancing_market_fig(df)
intraday_market_sys_fig = generate_intraday_market_sys_fig(df)
dsr_commands_fig = generate_dsr_commands_fig(df)
ev_demand_fig = generate_ev_demand_fig(df)
agent_activity_breakdown_fig = generate_agent_activity_breakdown_fig(df)
ev_charging_breakdown_fig = generate_ev_charging_breakdown_fig(df)

Expand All @@ -58,25 +60,17 @@
style={"height": "100%", "width": "100%"},
),
row=0,
col=1,
col=0,
)
# grid.add_element(
# dcc.Graph(
# id="ov-demand",
# figure=total_dem_fig,
# style={"height": "100%", "width": "100%"},
# ),
# row=1,
# col=1,
# )

grid.add_element(
dcc.Graph(
id="ov-energy-deficit",
figure=energy_deficit_fig,
style={"height": "100%", "width": "100%"},
),
row=1,
col=1,
col=0,
)
grid.add_element(
dcc.Graph(
Expand All @@ -85,7 +79,7 @@
style={"height": "100%", "width": "100%"},
),
row=0,
col=2,
col=1,
)
grid.add_element(
dcc.Graph(
Expand All @@ -94,17 +88,29 @@
style={"height": "100%", "width": "100%"},
),
row=1,
col=1,
)

grid.add_element(
dcc.Graph(
id="ov-dsr",
figure=dsr_commands_fig,
style={"height": "100%", "width": "100%"},
),
row=0,
col=2,
)

grid.add_element(
dcc.Graph(
id="ov-ev",
figure=ev_demand_fig,
style={"height": "100%", "width": "100%"},
),
row=1,
col=2,
)
# grid.add_element(
# dcc.Graph(
# id="ov-dsr",
# figure=dsr_commands_fig,
# style={"height": "100%", "width": "100%"},
# ),
# row=2,
# col=2,
# )

grid.add_element(
dcc.Graph(
id="ov-agent-waffle",
Expand Down Expand Up @@ -133,21 +139,23 @@
Output("ov-energy-deficit", "figure"),
Output("ov-bm", "figure"),
Output("ov-id", "figure"),
Output("ov-dsr", "figure"),
Output("ov-ev", "figure"),
Output("ov-agent-waffle", "figure"),
Output("ov-ev-waffle", "figure"),
],
[Input("figure_interval", "data")],
)
def update_figures(
n_intervals: int,
) -> tuple[go.Figure, px.line, px.line, go.Figure, go.Figure, go.Figure, go.Figure]:
) -> tuple[go.Figure, px.line, px.line, go.Figure, go.Figure, px.line, px.line, go.Figure, go.Figure]:
"""Function to update the plots in this page.
Args:
n_intervals (int): The number of times this page has updated.
indexes by 1 every interval.
Returns:
Returns: # TODO check this
tuple[px.line,
px.line,
px.line,
Expand All @@ -166,7 +174,8 @@ def update_figures(
energy_deficit_fig = generate_energy_deficit_fig(DF_OPAL)
balancing_market_fig = generate_balancing_market_fig(DF_OPAL)
intraday_market_sys_fig = generate_intraday_market_sys_fig(DF_OPAL)
# dsr_commands_fig = generate_dsr_commands_fig(DF_OPAL)
dsr_commands_fig = generate_dsr_commands_fig(DF_OPAL)
ev_demand_fig = generate_ev_demand_fig(DF_OPAL)
agent_activity_breakdown_fig = generate_agent_activity_breakdown_fig(DF_OPAL)
ev_charging_breakdown_fig = generate_ev_charging_breakdown_fig(DF_OPAL)

Expand All @@ -178,7 +187,8 @@ def update_figures(
energy_deficit_fig,
balancing_market_fig,
intraday_market_sys_fig,
# dsr_commands_fig,
dsr_commands_fig,
ev_demand_fig,
agent_activity_breakdown_fig,
ev_charging_breakdown_fig,
)

0 comments on commit d1096c2

Please sign in to comment.