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
ea70243c
Commit
ea70243c
authored
May 11, 2026
by
Eric Duminil
Browse files
Archetype counts too
parent
9933780e
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/simstadt/results/energy_grid.py
View file @
ea70243c
import
json
from
collections
import
Counter
from
dataclasses
import
dataclass
from
typing
import
ClassVar
...
...
@@ -34,6 +35,7 @@ class EnergyGridResults(SimStadtResults):
df
.
attrs
[
"number_of_households"
]
=
sum
(
b
[
"number_of_households"
]
for
b
in
buildings
)
df
.
attrs
[
"number_of_people"
]
=
sum
(
sum
(
b
[
"people_in_units"
])
for
b
in
buildings
)
df
.
attrs
[
"total_heated_area"
]
=
sum
(
b
[
"heated_area"
]
for
b
in
buildings
)
df
.
attrs
[
"archetype_counts"
]
=
Counter
(
b
[
"quarter_archetype"
]
for
b
in
buildings
)
return
df
@
property
...
...
@@ -42,10 +44,13 @@ class EnergyGridResults(SimStadtResults):
total_heated_area
=
df
.
attrs
[
"total_heated_area"
]
total_heat_kwh
=
df
[
"heat_demand"
].
sum
()
total_elec_kwh
=
df
[
"electricity_demand"
].
sum
()
most_common_archetype
,
most_common_count
=
df
.
attrs
[
"archetype_counts"
].
most_common
(
1
)[
0
]
archetype_share
=
100
*
most_common_count
/
df
.
attrs
[
"number_of_buildings"
]
return
[
KPI
(
"Number of buildings"
,
df
.
attrs
[
"number_of_buildings"
],
precision
=
0
),
KPI
(
"Number of households"
,
df
.
attrs
[
"number_of_households"
],
precision
=
0
),
KPI
(
"Number of people"
,
df
.
attrs
[
"number_of_people"
],
precision
=
0
),
KPI
(
"Number of inhabitants"
,
df
.
attrs
[
"number_of_people"
],
precision
=
0
),
KPI
(
"Most common archetype"
,
archetype_share
,
f
"% (
{
most_common_archetype
}
)"
,
precision
=
0
),
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
),
...
...
@@ -54,3 +59,7 @@ class EnergyGridResults(SimStadtResults):
KPI
(
"Total PV production"
,
df
[
"pv_production"
].
sum
()
/
1000
,
"MWh / a"
,
precision
=
1
),
KPI
(
"Average temperature"
,
float
(
df
[
"ambient_temperature"
].
mean
()),
"°C"
,
precision
=
1
),
]
@
property
def
more_info
(
self
)
->
dict
:
return
self
.
dataframe
.
attrs
[
"archetype_counts"
]
tests/test_results.py
View file @
ea70243c
...
...
@@ -655,8 +655,8 @@ def test_energy_grid_kpis(energy_grid_results):
assert
kpis
[
"Number of buildings"
].
unit
is
None
assert
kpis
[
"Number of households"
].
value
==
8
assert
kpis
[
"Number of households"
].
unit
is
None
assert
kpis
[
"Number of
people
"
].
value
==
13
assert
kpis
[
"Number of
people
"
].
unit
is
None
assert
kpis
[
"Number of
inhabitants
"
].
value
==
13
assert
kpis
[
"Number of
inhabitants
"
].
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
)
...
...
@@ -671,7 +671,14 @@ def test_energy_grid_kpis(energy_grid_results):
assert
kpis
[
"Total PV production"
].
unit
==
"MWh / a"
assert
kpis
[
"Average temperature"
].
value
==
pytest
.
approx
(
9.95
,
abs
=
0.05
)
assert
kpis
[
"Average temperature"
].
unit
==
"°C"
assert
len
(
kpis
)
==
10
assert
kpis
[
"Most common archetype"
].
value
==
pytest
.
approx
(
66.7
,
abs
=
0.1
)
assert
kpis
[
"Most common archetype"
].
unit
==
"% (QA_2)"
assert
len
(
kpis
)
==
11
def
test_energy_grid_more_info
(
energy_grid_results
):
info
=
energy_grid_results
.
more_info
assert
info
==
{
"QA_2"
:
2
,
"QA_4"
:
1
}
# ---------------------------------------------------------------------------
...
...
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