Commit 938d0069 authored by Eric Duminil's avatar Eric Duminil
Browse files

Extremely basic example for energy grid results

parent f4f99c49
import json
from dataclasses import dataclass from dataclasses import dataclass
from typing import ClassVar from typing import ClassVar
...@@ -10,19 +11,27 @@ from .providers import Providers ...@@ -10,19 +11,27 @@ from .providers import Providers
@dataclass(repr=False) @dataclass(repr=False)
class EnergyGridResults(SimStadtResults): class EnergyGridResults(SimStadtResults):
"""Results for EnergyGrid workflows. """Results for EnergyGrid workflows."""
"""
supported_providers: ClassVar[list[str]] = [Providers.ENERGY_GRID] supported_providers: ClassVar[list[str]] = [Providers.ENERGY_GRID]
csv_identifier = "json_only" csv_identifier = "json_only"
def _parse_results(self) -> pd.DataFrame: def _parse_results(self) -> pd.DataFrame:
# TODO: Actually parse JSON jsons = self.get_all_by_extension(".json")
_json_output = self.get_all_by_extension('.json') assert len(jsons) == 1
return pd.DataFrame() json_output = jsons[0]
with open(json_output, encoding="utf-8") as out:
content = json.load(out)
# TODO: Add infos about buildings. Total consumption for example?
return pd.DataFrame(
{
"ambient_temperature": content["ambient_temperature"],
}
)
@property @property
def kpis(self) -> list[KPI]: def kpis(self) -> list[KPI]:
# TODO: Actually output KPIs df = self.dataframe
return [ return [
KPI("Average temperature", float(df["ambient_temperature"].mean()), "°C", precision=1),
] ]
...@@ -644,8 +644,13 @@ def test_energy_grid_output_files_exist(energy_grid_results): ...@@ -644,8 +644,13 @@ def test_energy_grid_output_files_exist(energy_grid_results):
def test_energy_grid_dataframe(energy_grid_results): def test_energy_grid_dataframe(energy_grid_results):
df = energy_grid_results.dataframe df = energy_grid_results.dataframe
assert isinstance(df, pd.DataFrame) assert isinstance(df, pd.DataFrame)
assert df.shape == (8760, 3) assert df.shape == (8760, 1)
assert list(df.columns) == ["GHI", "DHI", "Ta"] assert list(df.columns) == ["ambient_temperature"]
def test_energy_grid_kpis(energy_grid_results):
kpis = kpis_by_name(energy_grid_results)
assert kpis["Average temperature"].value == pytest.approx(9.95, abs=0.05)
assert kpis["Average temperature"].unit == "°C"
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
......
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