Skip to content

Commit b5978a2

Browse files
author
RobinsonBeaucour
committed
cli: show plotly flag + date filter
1 parent 30b7aa2 commit b5978a2

2 files changed

Lines changed: 44 additions & 2 deletions

File tree

heatpro/cli/__init__.py

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from pathlib import Path
33

44
import click
5+
import plotly.graph_objects as go
56
from rich.logging import RichHandler
67

78
from .cold import cold_cli, import_weather, ColdConfig, Repartition
@@ -65,7 +66,10 @@ def validate_float_between_0_and_1(ctx, param, value):
6566
default=1 / 2,
6667
help="Share of cold energy within consumption associated to low activity on weekend profile consummed in a temperature sensitive manner",
6768
)
69+
@click.option("-start", "--date-start", default=None, help="date start")
70+
@click.option("-end", "--date-end", default=None, help="date end")
6871
@click.option("-v", "--verbose", is_flag=True, help="Enable debug logging")
72+
@click.option("-s", "--show", is_flag=True, help="Show graphs of the result")
6973
def cold(
7074
weather_csv,
7175
output_csv,
@@ -75,14 +79,18 @@ def cold(
7579
full_week_share,
7680
full_week_temperature_sensitivity,
7781
week_end_temperature_sensitivity,
82+
date_start,
83+
date_end,
7884
verbose,
85+
show,
7986
):
8087
logging.basicConfig(
8188
level=logging.DEBUG if verbose else logging.INFO,
8289
format="%(message)s",
8390
handlers=[RichHandler(rich_tracebacks=True)],
8491
)
85-
weather = import_weather(Path(weather_csv))
92+
weather = import_weather(Path(weather_csv)).loc[date_start:date_end]
93+
logging.debug(weather.index.max())
8694
cold_config = ColdConfig(
8795
set_temperature,
8896
loss,
@@ -110,6 +118,40 @@ def cold(
110118
result = cold_cli(weather, year_energy_reference, cold_config)
111119
result.to_csv(Path(output_csv), sep=";", float_format="%.2f")
112120

121+
if show:
122+
daily_temperature = weather.resample("d").mean()
123+
go.Figure(
124+
[
125+
go.Scattergl(
126+
x=weather.index,
127+
y=result["total_consumption_kW"],
128+
name="Total cold consumption",
129+
yaxis="y1",
130+
),
131+
go.Scattergl(
132+
x=daily_temperature.index,
133+
y=daily_temperature,
134+
name="Daily outdoor temperature",
135+
yaxis="y2",
136+
marker_color="#1f77b4",
137+
marker_opacity=0.5,
138+
line_dash="dash",
139+
),
140+
],
141+
).update_layout(
142+
hovermode="x unified",
143+
yaxis=dict(
144+
title_text="Power (<b>kW</b>)",
145+
),
146+
yaxis2=dict(
147+
title_text="Temperature (<b>°C</b>)",
148+
anchor="x",
149+
overlaying="y",
150+
side="right",
151+
range=[-5, 40],
152+
),
153+
).show()
154+
113155

114156
if __name__ == "__main__":
115157
cli()

heatpro/cli/cold.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ def __post_init__(self):
7474

7575

7676
def cold_cli(weather: pd.Series, year_energy_reference: float, config: ColdConfig) -> pd.DataFrame:
77-
weather = weather.loc[:"2022"]
7877
logging.debug(f"weather series description:\n{weather.describe()}")
7978
logging.debug(
8079
f"weather series index:\n - start : {weather.index.min()}\n - end : {weather.index.max()}"
@@ -171,6 +170,7 @@ def cold_cli(weather: pd.Series, year_energy_reference: float, config: ColdConfi
171170
),
172171
axis=1,
173172
)
173+
result["total_consumption_kW"] = result.loc[:, result.columns != weather.name].sum(axis=1)
174174
result.index = weather.index.astype("int64") // 10**9 # 10**9 convert nanoseconde to second
175175

176176
return result

0 commit comments

Comments
 (0)