Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
SimStadt
simstadtpy
Commits
6ef9927b
Commit
6ef9927b
authored
May 11, 2026
by
Eric Duminil
Browse files
Added KPIs and tests for EnergyGrid
parent
dfe00f2e
Changes
2
Show whitespace changes
Inline
Side-by-side
src/simstadt/results/energy_grid.py
View file @
6ef9927b
...
@@ -2,6 +2,7 @@ import json
...
@@ -2,6 +2,7 @@ import json
from
dataclasses
import
dataclass
from
dataclasses
import
dataclass
from
typing
import
ClassVar
from
typing
import
ClassVar
import
numpy
as
np
import
pandas
as
pd
import
pandas
as
pd
from
.base
import
SimStadtResults
from
.base
import
SimStadtResults
...
@@ -22,16 +23,30 @@ class EnergyGridResults(SimStadtResults):
...
@@ -22,16 +23,30 @@ class EnergyGridResults(SimStadtResults):
json_output
=
jsons
[
0
]
json_output
=
jsons
[
0
]
with
open
(
json_output
,
encoding
=
"utf-8"
)
as
out
:
with
open
(
json_output
,
encoding
=
"utf-8"
)
as
out
:
content
=
json
.
load
(
out
)
content
=
json
.
load
(
out
)
# TODO: Add infos about buildings. Total consumption for example?
buildings
=
content
[
"buildings"
]
return
pd
.
DataFrame
(
df
=
pd
.
DataFrame
({
{
"ambient_temperature"
:
content
[
"ambient_temperature"
],
"ambient_temperature"
:
content
[
"ambient_temperature"
],
}
"electricity_demand"
:
np
.
sum
([
b
[
"building_electricity_demand"
]
for
b
in
buildings
],
axis
=
0
),
)
"heat_demand"
:
np
.
sum
([
b
[
"th_heat_demand"
]
for
b
in
buildings
],
axis
=
0
),
"pv_production"
:
np
.
sum
([
b
[
"pv_production"
]
for
b
in
buildings
],
axis
=
0
),
})
df
.
attrs
[
"number_of_buildings"
]
=
len
(
buildings
)
df
.
attrs
[
"total_heated_area"
]
=
sum
(
b
[
"heated_area"
]
for
b
in
buildings
)
return
df
@
property
@
property
def
kpis
(
self
)
->
list
[
KPI
]:
def
kpis
(
self
)
->
list
[
KPI
]:
df
=
self
.
dataframe
df
=
self
.
dataframe
total_heated_area
=
df
.
attrs
[
"total_heated_area"
]
total_heat_kwh
=
df
[
"heat_demand"
].
sum
()
total_elec_kwh
=
df
[
"electricity_demand"
].
sum
()
return
[
return
[
KPI
(
"Number of buildings"
,
df
.
attrs
[
"number_of_buildings"
]),
KPI
(
"Total heated area"
,
total_heated_area
,
"m²"
,
precision
=
0
),
KPI
(
"Total electricity demand"
,
total_elec_kwh
/
1000
,
"MWh / a"
,
precision
=
1
),
KPI
(
"Specific electricity demand"
,
total_elec_kwh
/
total_heated_area
,
"kWh / (m² · a)"
,
precision
=
1
),
KPI
(
"Total heat demand"
,
total_heat_kwh
/
1000
,
"MWh / a"
,
precision
=
1
),
KPI
(
"Specific heat demand"
,
total_heat_kwh
/
total_heated_area
,
"kWh / (m² · a)"
,
precision
=
1
),
KPI
(
"Total PV production"
,
df
[
"pv_production"
].
sum
()
/
1000
,
"MWh / a"
,
precision
=
1
),
KPI
(
"Average temperature"
,
float
(
df
[
"ambient_temperature"
].
mean
()),
"°C"
,
precision
=
1
),
KPI
(
"Average temperature"
,
float
(
df
[
"ambient_temperature"
].
mean
()),
"°C"
,
precision
=
1
),
]
]
tests/test_results.py
View file @
6ef9927b
...
@@ -644,13 +644,30 @@ def test_energy_grid_output_files_exist(energy_grid_results):
...
@@ -644,13 +644,30 @@ 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
,
1
)
assert
df
.
shape
==
(
8760
,
4
)
assert
list
(
df
.
columns
)
==
[
"ambient_temperature"
]
assert
list
(
df
.
columns
)
==
[
"ambient_temperature"
,
"electricity_demand"
,
"heat_demand"
,
"pv_production"
]
assert
df
.
attrs
[
"number_of_buildings"
]
==
3
def
test_energy_grid_kpis
(
energy_grid_results
):
def
test_energy_grid_kpis
(
energy_grid_results
):
kpis
=
kpis_by_name
(
energy_grid_results
)
kpis
=
kpis_by_name
(
energy_grid_results
)
assert
kpis
[
"Number of buildings"
].
value
==
3
assert
kpis
[
"Number of buildings"
].
unit
is
None
assert
kpis
[
"Total heated area"
].
value
==
pytest
.
approx
(
1198.1
,
abs
=
0.1
)
assert
kpis
[
"Total heated area"
].
unit
==
"m²"
assert
kpis
[
"Total electricity demand"
].
value
==
pytest
.
approx
(
17.0
,
abs
=
0.1
)
assert
kpis
[
"Total electricity demand"
].
unit
==
"MWh / a"
assert
kpis
[
"Specific electricity demand"
].
value
==
pytest
.
approx
(
14.2
,
abs
=
0.5
)
assert
kpis
[
"Specific electricity demand"
].
unit
==
"kWh / (m² · a)"
assert
kpis
[
"Total heat demand"
].
value
==
pytest
.
approx
(
117.9
,
abs
=
0.1
)
assert
kpis
[
"Total heat demand"
].
unit
==
"MWh / a"
assert
kpis
[
"Specific heat demand"
].
value
==
pytest
.
approx
(
98.4
,
abs
=
0.5
)
assert
kpis
[
"Specific heat demand"
].
unit
==
"kWh / (m² · a)"
assert
kpis
[
"Total PV production"
].
value
==
pytest
.
approx
(
34.5
,
abs
=
0.1
)
assert
kpis
[
"Total PV production"
].
unit
==
"MWh / a"
assert
kpis
[
"Average temperature"
].
value
==
pytest
.
approx
(
9.95
,
abs
=
0.05
)
assert
kpis
[
"Average temperature"
].
value
==
pytest
.
approx
(
9.95
,
abs
=
0.05
)
assert
kpis
[
"Average temperature"
].
unit
==
"°C"
assert
kpis
[
"Average temperature"
].
unit
==
"°C"
assert
len
(
kpis
)
==
8
# ---------------------------------------------------------------------------
# ---------------------------------------------------------------------------
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment