Skip to content

Commit 5624c86

Browse files
Merge pull request #86 from flora-hofmann-frequenz/add_reporting_visu
Set up module for reporting plots
2 parents 994dc34 + d4adefb commit 5624c86

File tree

3 files changed

+134
-1
lines changed

3 files changed

+134
-1
lines changed

RELEASE_NOTES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
## New Features
1515

16-
<!-- Here goes the main new features and examples or instructions on how to use them -->
16+
* Add plotter for reporting notebooks.
1717

1818
## Bug Fixes
1919

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# License: MIT
2+
# Copyright © 2025 Frequenz Energy-as-a-Service GmbH
3+
4+
"""Initialise the reporting related modules."""
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
# License: MIT
2+
# Copyright © 2025 Frequenz Energy-as-a-Service GmbH
3+
4+
"""Plotting functions for the reporting module."""
5+
6+
import pandas as pd
7+
import plotly.express as px
8+
import plotly.graph_objects as go
9+
10+
11+
def plot_overview_line_chart(overview_df: pd.DataFrame) -> go.Figure:
12+
"""Plot an overview line chart of all components over time."""
13+
fig = go.Figure()
14+
15+
for col in overview_df.columns:
16+
if col != "Zeitpunkt":
17+
fig.add_trace(
18+
go.Scatter(
19+
x=overview_df["Zeitpunkt"],
20+
y=overview_df[col],
21+
mode="lines",
22+
name=col,
23+
)
24+
)
25+
26+
fig.update_layout(
27+
title="Lastgang Übersicht",
28+
xaxis_title="Zeitpunkt",
29+
yaxis_title="kW",
30+
xaxis={"tickformat": "%Y-%m-%d %H:%M", "title_font": {"size": 14}},
31+
legend={"title": "Komponenten"},
32+
template="plotly_white",
33+
)
34+
fig.show()
35+
36+
37+
def plot_energy_pie_chart(power_df: pd.DataFrame) -> px.pie:
38+
"""Plot a pie chart for energy source contributions."""
39+
fig = px.pie(power_df, names="Energiebezug", values="Energie [kWh]", hole=0.4)
40+
41+
fig.update_traces(
42+
textinfo="label+percent",
43+
textposition="outside",
44+
hovertemplate="%{label}<br>%{percent} (%{value:.2f} kWh)<extra></extra>",
45+
showlegend=True,
46+
)
47+
48+
fig.update_layout(
49+
title="Energiebezug",
50+
legend_title_text="Energiebezug",
51+
template="plotly_white",
52+
width=700,
53+
height=500,
54+
)
55+
fig.show()
56+
57+
58+
def plot_pv_analysis(pv_analyse_df: pd.DataFrame) -> go.Figure:
59+
"""Plot PV Einspeisung and Netzanschluss lines if available."""
60+
fig = go.Figure()
61+
62+
for label in ["PV Einspeisung", "Netzanschluss"]:
63+
if label in pv_analyse_df.columns:
64+
fig.add_trace(
65+
go.Scatter(
66+
x=pv_analyse_df["Zeitpunkt"],
67+
y=pv_analyse_df[label],
68+
mode="lines",
69+
name=label,
70+
)
71+
)
72+
73+
fig.update_layout(
74+
title="PV Leistung",
75+
xaxis_title="Zeitpunkt",
76+
yaxis_title="kW",
77+
xaxis={"tickformat": "%Y-%m-%d %H:%M", "title_font": {"size": 14}},
78+
legend={"title": "Komponenten"},
79+
template="plotly_white",
80+
)
81+
fig.show()
82+
83+
84+
def plot_battery_throughput(bat_analyse_df: pd.DataFrame) -> go.Figure:
85+
"""Plot battery throughput over time."""
86+
fig = go.Figure()
87+
88+
if "Batterie Durchsatz" in bat_analyse_df.columns:
89+
fig.add_trace(
90+
go.Scatter(
91+
x=bat_analyse_df["Zeitpunkt"],
92+
y=bat_analyse_df["Batterie Durchsatz"],
93+
mode="lines",
94+
name="Batterie Durchsatz",
95+
)
96+
)
97+
98+
fig.update_layout(
99+
title="Batterie Durchsatz",
100+
xaxis_title="Zeitpunkt",
101+
yaxis_title="kW",
102+
xaxis={"tickformat": "%Y-%m-%d %H:%M", "title_font": {"size": 14}},
103+
template="plotly_white",
104+
)
105+
fig.show()
106+
107+
108+
def plot_grid_import(master_df: pd.DataFrame) -> go.Figure:
109+
"""Plot Netzbezug over time if the column exists."""
110+
fig = go.Figure()
111+
112+
if "Netzbezug" in master_df.columns:
113+
fig.add_trace(
114+
go.Scatter(
115+
x=master_df["Zeitpunkt"],
116+
y=master_df["Netzbezug"],
117+
mode="lines",
118+
name="Netzbezug",
119+
)
120+
)
121+
122+
fig.update_layout(
123+
title="Netzbezug",
124+
xaxis_title="Zeitpunkt",
125+
yaxis_title="kW",
126+
xaxis={"tickformat": "%Y-%m-%d %H:%M", "title_font": {"size": 14}},
127+
template="plotly_white",
128+
)
129+
fig.show()

0 commit comments

Comments
 (0)