Commit f4f99c49 authored by Eric Duminil's avatar Eric Duminil
Browse files

Starting to tests EnergyGridResults

parent c48aa296
......@@ -8,6 +8,7 @@ import pytest
from simstadt import (
KPI,
EnergyGridResults,
GreenWaterResults,
HeatDemandResults,
LoadProfileResults,
......@@ -19,19 +20,21 @@ from simstadt import (
)
TEST_REPOSITORY = Path(__file__).parent / "data" / "TestRepo"
TEST_PROJECT_PATH = TEST_REPOSITORY / "CGSC.proj"
LOAD_PROFILE_FLOW = TEST_REPOSITORY / "SektorSim.proj" / "LoadProfile.flow"
SOLAR_FLOW = TEST_REPOSITORY / "SektorSim.proj" / "Solar.flow"
PROJECT1_PATH = TEST_REPOSITORY / "CGSC.proj"
PROJECT2_PATH = TEST_REPOSITORY / "SektorSim.proj"
LOAD_PROFILE_FLOW = PROJECT2_PATH / "LoadProfile.flow"
SOLAR_FLOW = PROJECT2_PATH / "Solar.flow"
ENERGY_GRID_FLOW = PROJECT2_PATH / "EnergyGridSimulation.flow"
def kpis_by_name(results: SimStadtResults) -> dict[str, KPI]:
return {kpi.name: kpi for kpi in results.kpis}
def find_output_files(workflow_name: str) -> list[Path]:
def find_output_files(workflow_path: Path) -> list[Path]:
return [
f
for f in (TEST_PROJECT_PATH / workflow_name).glob("*.step/**/*")
for f in workflow_path.glob("*.step/**/*")
if f.is_file() and f.name != "params.xml"
]
......@@ -156,7 +159,7 @@ def test_heating_repr(heating_results):
def heating_and_cooling_results() -> SimStadtResults:
return create_simstadt_results(
"Heating and cooling demand simulation for Grombühl",
find_output_files("104_HeatAndCoolDemand.flow"),
find_output_files(PROJECT1_PATH / "104_HeatAndCoolDemand.flow"),
)
......@@ -170,9 +173,9 @@ def test_heating_and_cooling_kpis(heating_and_cooling_results):
assert "Specific Heating Demand" in kpis
assert "Yearly Cooling demand" in kpis
assert "Specific Cooling Demand" in kpis
assert heating_and_cooling_results.kpi("Specific Cooling Demand").value == pytest.approx(
20, abs=1
)
assert heating_and_cooling_results.kpi(
"Specific Cooling Demand"
).value == pytest.approx(20, abs=1)
assert len(kpis) == 12
......@@ -193,7 +196,7 @@ def test_heating_and_cooling_diagrams(heating_and_cooling_results):
def cooling_results() -> SimStadtResults:
return create_simstadt_results(
"Cooling demand simulation for Grombühl",
find_output_files("105_CoolingDemand.flow"),
find_output_files(PROJECT1_PATH / "105_CoolingDemand.flow"),
)
......@@ -616,6 +619,35 @@ def test_broken_simulation():
results.kpis
# ---------------------------------------------------------------------------
# Energy Grid Simulation
# ---------------------------------------------------------------------------
@pytest.fixture(scope="module")
def energy_grid_results() -> SimStadtResults:
return create_simstadt_results(
"Energy Grid Simulation for MiniBuchwald",
find_output_files(PROJECT2_PATH / "EnergyGridSimulation.flow"),
)
def test_energy_grid_result_type(energy_grid_results):
assert isinstance(energy_grid_results, EnergyGridResults)
def test_energy_grid_output_files_exist(energy_grid_results):
assert all(f.exists() for f in energy_grid_results.output_files)
assert len(energy_grid_results.get_all_by_extension(".json")) == 1
def test_energy_grid_dataframe(energy_grid_results):
df = energy_grid_results.dataframe
assert isinstance(df, pd.DataFrame)
assert df.shape == (8760, 3)
assert list(df.columns) == ["GHI", "DHI", "Ta"]
# ---------------------------------------------------------------------------
# Unknown workflow
# ---------------------------------------------------------------------------
......@@ -623,7 +655,7 @@ def test_broken_simulation():
def test_unknown_workflow_results(caplog):
output_files = [
TEST_PROJECT_PATH / "UnknownWorkflow.flow/output.step/result.log",
PROJECT1_PATH / "UnknownWorkflow.flow/output.step/result.log",
]
with caplog.at_level(logging.WARNING):
results = create_simstadt_results("Unknown workflow test", output_files)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment