-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move figure functions into a separate python file (#57)
* Move figure functions to new file * Add docstring
- Loading branch information
Showing
2 changed files
with
118 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
"""Functions for generating plotly express figures.""" | ||
import pandas as pd | ||
import plotly.express as px # type: ignore | ||
|
||
|
||
def generate_gen_split_fig(df: pd.DataFrame) -> px.pie: | ||
"""Creates Plotly figure for Generation Split graph. | ||
Args: | ||
df: Opal data DataFrame | ||
Returns: | ||
Plotly express figure | ||
""" | ||
if len(df.columns) == 1: | ||
gen_split_fig = px.pie() | ||
else: | ||
gen_split_df = df.iloc[-1, 13:23] | ||
|
||
gen_split_fig = px.pie( | ||
names=[ | ||
"Battery Generation", | ||
"Interconnector Power", | ||
"Offshore Wind Generation", | ||
"Onshore Wind Generation", | ||
"Other Generation", | ||
"Pump Generation", | ||
"Pv Generation", | ||
"Nuclear Generation", | ||
"Hydro Generation", | ||
"Gas Generation", | ||
], | ||
values=gen_split_df, | ||
).update_layout(title_text=df.iloc[-1]["Time"]) | ||
return gen_split_fig | ||
|
||
|
||
def generate_total_gen_fig(df: pd.DataFrame) -> px.line: | ||
"""Creates Plotly figure for Total Generation graph. | ||
Args: | ||
df: Opal data DataFrame | ||
Returns: | ||
Plotly express figure | ||
""" | ||
if len(df.columns) == 1: | ||
total_gen_fig = px.line() | ||
else: | ||
total_gen_fig = px.line( | ||
df, | ||
x="Time", | ||
y=[ | ||
"Total Generation", | ||
"Battery Generation", | ||
"Interconnector Power", | ||
"Offshore Wind Generation", | ||
"Onshore Wind Generation", | ||
"Other Generation", | ||
"Pump Generation", | ||
"Pv Generation", | ||
"Nuclear Generation", | ||
"Hydro Generation", | ||
"Gas Generation", | ||
], | ||
).update_layout(yaxis_title="GW") | ||
return total_gen_fig | ||
|
||
|
||
def generate_total_dem_fig(df: pd.DataFrame) -> px.line: | ||
"""Creates Plotly figure for Total Demand graph. | ||
Args: | ||
df: Opal data DataFrame | ||
Returns: | ||
Plotly express figure | ||
""" | ||
if len(df.columns) == 1: | ||
total_dem_fig = px.line() | ||
else: | ||
total_dem_fig = px.line( | ||
df, | ||
x="Time", | ||
y=[ | ||
"Total Demand", | ||
], | ||
).update_layout(yaxis_title="GW") | ||
return total_dem_fig | ||
|
||
|
||
def generate_system_freq_fig(df: pd.DataFrame) -> px.line: | ||
"""Creates Plotly figure for System Frequency graph. | ||
Args: | ||
df: Opal data DataFrame | ||
Returns: | ||
Plotly express figure | ||
""" | ||
if len(df.columns) == 1: | ||
system_freq_fig = px.line() | ||
else: | ||
system_freq_fig = px.line( | ||
df, | ||
x="Time", | ||
y=[ | ||
"Total Generation", | ||
"Total Demand", | ||
], | ||
).update_layout(yaxis_title="GW") | ||
return system_freq_fig |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters