Skip to content

Commit

Permalink
Update Graphers to clean out old graphs
Browse files Browse the repository at this point in the history
  • Loading branch information
ed-p-may committed Nov 22, 2024
1 parent c0b1c97 commit 0f564dc
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
16 changes: 12 additions & 4 deletions honeybee_revive/output/resilience_summer_graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,14 @@ def df_in_kWh(_data: list[Record]) -> pd.DataFrame:
return df


def html_file(_filename: Path) -> Path:
"""Create an HTML file, but remove it if it already exists."""

if os.path.exists(_filename):
os.remove(_filename)
return _filename


if __name__ == "__main__":
# ------------------------------------------------------------------------------------------------------------------
# ------------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -187,7 +195,7 @@ def df_in_kWh(_data: list[Record]) -> pd.DataFrame:
env_fig3 = create_line_plot_figure(pd.DataFrame(env_wind_speed_m3s), "Outdoor Wind Speed [m/s]")
env_fig4 = create_line_plot_figure(pd.DataFrame(env_air_pressure_Pa), "Outdoor Air Pressure [Pa]")

with open(file_paths.graphs / "summer_outdoor_environment.html", "w") as f:
with open(html_file(file_paths.graphs / "summer_outdoor_environment.html"), "w") as f:
f.write(pio.to_html(env_fig1, full_html=False, include_plotlyjs="cdn"))
f.write(pio.to_html(env_fig2, full_html=False, include_plotlyjs=False))
f.write(pio.to_html(env_fig3, full_html=False, include_plotlyjs=False))
Expand Down Expand Up @@ -230,7 +238,7 @@ def df_in_kWh(_data: list[Record]) -> pd.DataFrame:
hi_fig2 = create_line_plot_figure(pd.DataFrame(env_drybulb_C + drybulb_C), "Zone Dry-Bulb Air Temp. [C]")
hi_fig3 = create_line_plot_figure(pd.DataFrame(env_RH + zone_RH), "Zone Air Relative Humidity [%]")

with open(file_paths.graphs / "summer_heat_index.html", "w") as f:
with open(html_file(file_paths.graphs / "summer_heat_index.html"), "w") as f:
f.write(pio.to_html(hi_fig1, full_html=False, include_plotlyjs="cdn"))
f.write(pio.to_html(hi_fig2, full_html=False, include_plotlyjs=False))
f.write(pio.to_html(hi_fig3, full_html=False, include_plotlyjs=False))
Expand All @@ -246,7 +254,7 @@ def df_in_kWh(_data: list[Record]) -> pd.DataFrame:
vent_fig2 = create_line_plot_figure(pd.DataFrame(vent_zone_ach), "Zone Ventilation [ACH]")
vent_fig3 = create_line_plot_figure(pd.DataFrame(vent_mech_ach), "Zone Mechanical Ventilation [ACH]")

with open(file_paths.graphs / "summer_ventilation.html", "w") as f:
with open(html_file(file_paths.graphs / "summer_ventilation.html"), "w") as f:
f.write(pio.to_html(vent_fig1, full_html=False, include_plotlyjs="cdn"))
f.write(pio.to_html(vent_fig2, full_html=False, include_plotlyjs=False))
f.write(pio.to_html(vent_fig3, full_html=False, include_plotlyjs=False))
Expand Down Expand Up @@ -279,7 +287,7 @@ def df_in_kWh(_data: list[Record]) -> pd.DataFrame:
vent_gain_df["Value"] = vent_gain_df["Value"] - vent_loss_df["Value"]
energy_fig7 = create_line_plot_figure(vent_gain_df, "Total Ventilation Heat Gain [kWh]")

with open(file_paths.graphs / "summer_energy_flow.html", "w") as f:
with open(html_file(file_paths.graphs / "summer_energy_flow.html"), "w") as f:
f.write(pio.to_html(energy_fig1, full_html=False, include_plotlyjs="cdn"))
f.write(pio.to_html(energy_fig2, full_html=False, include_plotlyjs=False))
f.write(pio.to_html(energy_fig3, full_html=False, include_plotlyjs=False))
Expand Down
18 changes: 13 additions & 5 deletions honeybee_revive/output/resilience_winter_graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def resolve_paths(_args: list[str]) -> Filepaths:
target_graphs_dir = Path(_args[2])
if not target_graphs_dir.exists():
print(f"\t>> Creating the directory: {target_graphs_dir}")
os.mkdir(target_graphs_dir)
os.makedirs(target_graphs_dir, exist_ok=True)

return Filepaths(results_sql_file, target_graphs_dir)

Expand Down Expand Up @@ -133,6 +133,14 @@ def df_in_kWh(_data: list[Record]) -> pd.DataFrame:
return df


def html_file(_filename: Path) -> Path:
"""Create an HTML file, but remove it if it already exists."""

if os.path.exists(_filename):
os.remove(_filename)
return _filename


if __name__ == "__main__":
print("- " * 50)
print(f"\t>> Using Python: {sys.version}")
Expand Down Expand Up @@ -188,7 +196,7 @@ def df_in_kWh(_data: list[Record]) -> pd.DataFrame:
env_fig3 = create_line_plot_figure(pd.DataFrame(env_wind_speed_m3s), "Outdoor Wind Speed [m/s]")
env_fig4 = create_line_plot_figure(pd.DataFrame(env_air_pressure_Pa), "Outdoor Air Pressure [Pa]")

with open(file_paths.graphs / "winter_outdoor_environment.html", "w") as f:
with open(html_file(file_paths.graphs / "winter_outdoor_environment.html"), "w+") as f:
f.write(pio.to_html(env_fig1, full_html=False, include_plotlyjs="cdn"))
f.write(pio.to_html(env_fig2, full_html=False, include_plotlyjs=False))
f.write(pio.to_html(env_fig3, full_html=False, include_plotlyjs=False))
Expand All @@ -201,7 +209,7 @@ def df_in_kWh(_data: list[Record]) -> pd.DataFrame:
set_fig2 = create_line_plot_figure(pd.DataFrame(env_drybulb_C + drybulb_C), "Dry-Bulb Air Temperature [C]")
set_fig3 = create_line_plot_figure(pd.DataFrame(env_RH + zone_RH), "Air Relative Humidity [%]")

with open(file_paths.graphs / "winter_SET_temperature.html", "w") as f:
with open(html_file(file_paths.graphs / "winter_SET_temperature.html"), "w") as f:
f.write(pio.to_html(set_fig1, full_html=False, include_plotlyjs="cdn"))
f.write(pio.to_html(set_fig2, full_html=False, include_plotlyjs=False))
f.write(pio.to_html(set_fig3, full_html=False, include_plotlyjs=False))
Expand All @@ -217,7 +225,7 @@ def df_in_kWh(_data: list[Record]) -> pd.DataFrame:
vent_fig2 = create_line_plot_figure(pd.DataFrame(vent_zone_ach), "Zone Ventilation [ACH]")
vent_fig3 = create_line_plot_figure(pd.DataFrame(vent_mech_ach), "Zone Mechanical Ventilation [ACH]")

with open(file_paths.graphs / "winter_ventilation.html", "w") as f:
with open(html_file(file_paths.graphs / "winter_ventilation.html"), "w") as f:
f.write(pio.to_html(vent_fig1, full_html=False, include_plotlyjs="cdn"))
f.write(pio.to_html(vent_fig2, full_html=False, include_plotlyjs=False))
f.write(pio.to_html(vent_fig3, full_html=False, include_plotlyjs=False))
Expand Down Expand Up @@ -250,7 +258,7 @@ def df_in_kWh(_data: list[Record]) -> pd.DataFrame:
vent_gain_df["Value"] = vent_gain_df["Value"] - vent_loss_df["Value"]
energy_fig7 = create_line_plot_figure(vent_gain_df, "Total Ventilation Heat Gain [kWh]")

with open(file_paths.graphs / "winter_energy_flow.html", "w") as f:
with open(html_file(file_paths.graphs / "winter_energy_flow.html"), "w") as f:
f.write(pio.to_html(energy_fig1, full_html=False, include_plotlyjs="cdn"))
f.write(pio.to_html(energy_fig2, full_html=False, include_plotlyjs=False))
f.write(pio.to_html(energy_fig3, full_html=False, include_plotlyjs=False))
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "honeybee-REVIVE"
version = "0.0.14"
version = "0.0.15"
description = "A Honeybee Extension for Phius REVIVE Modeling."
readme = "README.md"
requires-python = ">=3.10"
Expand Down Expand Up @@ -28,7 +28,7 @@ keywords = [
dependencies = [
"honeybee-energy>=1.109.17",
"pandas>=2.2.3",
"ph-units>=1.5.15",
"ph-units>=1.5.16",
"plotly>=5.24.1",
"pydantic<=1.10.18",
"rich>=13.8.1",
Expand Down

0 comments on commit 0f564dc

Please sign in to comment.