Skip to content

Commit

Permalink
Create template for Agent view
Browse files Browse the repository at this point in the history
  • Loading branch information
tsmbland committed Nov 3, 2023
1 parent f903f73 commit 74036f3
Show file tree
Hide file tree
Showing 3 changed files with 250 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/core_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
"space": "Hub02",
"app": {
"url": f"{API_URL}/app/html",
"states": {"load": {"url": f"{PLOT_URL}/plot8"}},
"states": {"load": {"url": f"{PLOT_URL}/agent"}},
},
},
}
Expand Down
72 changes: 72 additions & 0 deletions app/figures.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,3 +303,75 @@ def generate_dsr_commands_fig(df: pd.DataFrame) -> px.line:
).update_layout(yaxis_title="MW")

return dsr_commands_fig


def generate_agent_location_fig(df: pd.DataFrame) -> None:
"""XXX.
Args:
df: XXX
Returns:
XXX
"""
return None


def generate_agent_location_sld_fig(df: pd.DataFrame) -> None:
"""XXX.
Args:
df: XXX
Returns:
XXX
"""
return None


def generate_agent_activity_breakdown_fig(df: pd.DataFrame) -> None:
"""XXX.
Args:
df: XXX
Returns:
XXX
"""
return None


def generate_ev_location_fig(df: pd.DataFrame) -> None:
"""XXX.
Args:
df: XXX
Returns:
XXX
"""
return None


def generate_ev_location_sld_fig(df: pd.DataFrame) -> None:
"""XXX.
Args:
df: XXX
Returns:
XXX
"""
return None


def generate_ev_charging_breakdown_fig(df: pd.DataFrame) -> None:
"""XXX.
Args:
df: XXX
Returns:
XXX
"""
return None
177 changes: 177 additions & 0 deletions app/pages/agent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
"""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_agent_location_fig,
generate_agent_location_sld_fig,
generate_agent_activity_breakdown_fig,
generate_ev_location_fig,
generate_ev_location_sld_fig,
generate_ev_charging_breakdown_fig,
generate_dsr_commands_fig
)

dash.register_page(__name__)

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

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

agent_location_fig = generate_agent_location_fig(df)
agent_location_sld_fig = generate_agent_location_sld_fig(df)
agent_activity_breakdown_fig = generate_agent_activity_breakdown_fig(df)
ev_location_fig = generate_ev_location_fig(df)
ev_location_sld_fig = generate_ev_location_sld_fig(df)
ev_charging_breakdown_fig = generate_ev_charging_breakdown_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("Agent Locations"),
dcc.Graph(
id="agent_location_fig",
figure=agent_location_fig,
style={"height": "40vh"},
),
],
),
html.Div(
style={"width": "48%"},
children=[
html.H1("Agent Locations on SLD"),
dcc.Graph(
id="agent_location_sld_fig",
figure=agent_location_sld_fig,
style={"height": "40vh"},
),
],
),
html.Div(
style={"width": "48%"},
children=[
html.H1("Agent Activity Breakdown"),
dcc.Graph(
id="agent_activity_breakdown_fig",
figure=agent_activity_breakdown_fig,
style={"height": "40vh"},
),
],
),
],
),
html.Div(
style={"display": "flex", "justify-content": "space-around"},
children=[
html.Div(
style={"width": "48%"},
children=[
html.H1("Electric Vehicle Location"),
dcc.Graph(
id="ev_location_fig",
figure=ev_location_fig,
style={"height": "40vh"},
),
],
),
html.Div(
style={"width": "48%"},
children=[
html.H1("Electric Vehicle Location on SLD"),
dcc.Graph(
id="ev_location_sld_fig",
figure=ev_location_sld_fig,
style={"height": "40vh"},
),
],
),
html.Div(
style={"width": "48%"},
children=[
html.H1("Electric Vehicle Charging Breakdown"),
dcc.Graph(
id="ev_charging_breakdown_fig",
figure=ev_charging_breakdown_fig,
style={"height": "40vh"},
),
],
),
],
),
html.Div(
style={"display": "flex", "justify-content": "space-around"},
children=[
html.Div(
style={"width": "48%"},
children=[
html.H1("DSR Commands to Agents"),
dcc.Graph(
id="dsr_commands_fig",
figure=dsr_commands_fig,
style={"height": "40vh"},
),
],
)
],
),
dcc.Interval(id="interval", interval=interval),
],
)


@callback(
[
Output("agent_location_fig", "figure"),
Output("agent_location_sld_fig", "figure"),
Output("agent_activity_breakdown_fig", "figure"),
Output("ev_location_fig", "figure"),
Output("ev_location_sld_fig", "figure"),
Output("ev_charging_breakdown_fig", "figure"),
Output("dsr_commands_fig", "figure")
],
[Input("interval", "n_intervals")],
)
def update_data(n_intervals): # type: ignore # noqa
if n_intervals is None:
raise PreventUpdate

data_opal = datahub.get_opal_data()
new_df_opal = pd.DataFrame(**data_opal)

data_dsr = datahub.get_dsr_data()
new_df_dsr = pd.DataFrame(**data_dsr)

agent_location_fig = generate_agent_location_fig(...)
agent_location_sld_fig = generate_agent_location_sld_fig(...)
agent_activity_breakdown_fig = generate_agent_activity_breakdown_fig(...)
ev_location_fig = generate_ev_location_fig(...)
ev_location_sld_fig = generate_ev_location_sld_fig(...)
ev_charging_breakdown_fig = generate_ev_charging_breakdown_fig(...)
dsr_commands_fig = generate_dsr_commands_fig(...)
return (
agent_location_fig,
agent_location_sld_fig,
agent_activity_breakdown_fig,
ev_location_fig,
ev_location_sld_fig,
ev_charging_breakdown_fig,
dsr_commands_fig
)

0 comments on commit 74036f3

Please sign in to comment.