Skip to content
Merged

Dev #14

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 66 additions & 1 deletion peakshaving_analyzer/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down