diff --git a/peakshaving_analyzer/input.py b/peakshaving_analyzer/input.py index eb47184..c437805 100644 --- a/peakshaving_analyzer/input.py +++ b/peakshaving_analyzer/input.py @@ -7,9 +7,12 @@ import pandas as pd import pgeocode +import plotly.express as px +import plotly.graph_objects as go import requests import sqlalchemy import yaml +from statsmodels.tsa import seasonal from peakshaving_analyzer.common import IOHandler @@ -78,10 +81,72 @@ def timeseries_to_df(self): df["consumption_kw"] = self.consumption_timeseries df["energy_price_eur"] = self.price_timeseries["grid"] - df["new_pv_generation_kw"] = self.new_pv_generation_timeseries["consumption_site"] + + if self.new_pv_generation_timeseries is not None: + df["new_pv_generation_kw"] = self.new_pv_generation_timeseries["consumption_site"] return df + def plot_load_duration_curve(self): + ts_df = self.timeseries_to_df() + + fig = px.line( + data_frame=ts_df.sort_values("consumption_kw", ascending=False, ignore_index=True), + x=ts_df.index, + y="consumption_kw", + title="Load duration curve", + ) + fig.update_layout(xaxis_title="Number of times", yaxis_title="Load in kW") + + fig.show() + + def plot_load_histogram(self): + ts_df = self.timeseries_to_df() + + fig = px.histogram(data_frame=ts_df, x="consumption_kw", title="Histogram of load") + fig.update_layout(xaxis_title="Load in kW") + + fig.show() + + def plot_load_box(self): + ts_df = self.timeseries_to_df() + + fig = px.box( + data_frame=ts_df, + x="consumption_kw", + title="Boxplot of load", + ) + fig.update_layout(xaxis_title="Load in kW") + + fig.show() + + def seasonal_decompose(self) -> seasonal.DecomposeResult: + ts_df = self.timeseries_to_df() + ts_df.index = self.timestamps.copy() + + decompose_result = seasonal.seasonal_decompose(x=ts_df["consumption_kw"]) + + return decompose_result + + def plot_seasonal_decompose(self): + decompose_result = self.seasonal_decompose() + + fig = go.Figure() + for var in ["seasonal", "trend", "resid"]: + fig.add_scatter( + x=self.timestamps, + y=getattr(decompose_result, var), + name=var, + ) + + fig.update_layout( + title="Seasonal decomposition", + xaxis_title="Time", + yaxis_title="Load in kW", + ) + + fig.show() + def load_yaml_config(config_file_path: Path | str, test_mode: bool = False) -> Config: config_path = Path(config_file_path)