feat(dommer): the step with a single facility cannot be the 25 % step (clarification 104)

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
Kjell Tore Guttormsen 2026-11-13 17:46:37 +01:00
commit 28a0911825
Signed by: ktg
SSH key fingerprint: SHA256:JakMjO6FTBBzN0Bhfj9saOoEjaFxlSdYuZQQpM/lF9Q
2 changed files with 43 additions and 10 deletions

View file

@ -269,9 +269,11 @@ class Trinnvalg:
grunnlag: Grunnlag
def _laveste_trinn(m6: Mapping[int, Mapping[Losning, Utfall]], minst: float) -> int | None:
def _laveste_trinn(
m6: Mapping[int, Mapping[Losning, Utfall]], minst: float, *, over: int = 0
) -> int | None:
for trinn in sorted(m6):
if any(
if trinn > over and any(
andel(m6[trinn][a], minst, minst=True) >= ANDEL_HOLDER
for a in DOMSLOSNINGER
if a in m6[trinn]
@ -285,15 +287,21 @@ def trinn_for_dommene(m6: Mapping[int, Mapping[Losning, Utfall]]) -> Trinnvalg:
``m6[trinn][losning]`` holds M6 per draw in «normalisering» (None where the
path cannot be built or has no year of stable operation). The 25 % step is
the lowest step where at least 80 % of the draws reach 25 % for one of A,
B, C, T-F and T-K; the 5 % step likewise. Without either, the verdicts are
read on the highest step that can be built: the highest where one of the
five has a value in at least 80 % of the draws (chapter 16, clarification
57; chapter 17.1). A step is a number of facilities; in solution T it is
ten times as many modules, the same MW IT.
the lowest step with more than one facility where at least 80 % of the
draws reach 25 % for one of A, B, C, T-F and T-K: the step with a single
facility cannot be the 25 % step (pre-registration, clarification 19;
chapter 16, clarification 104). The 5 % step is the lowest step, also the
one with a single facility, where 80 % reach 5 %. Without either, the
verdicts are read on the highest step that can be built: the highest where
one of the five has a value in at least 80 % of the draws (chapter 16,
clarification 57; chapter 17.1). A step is a number of facilities; in
solution T it is the same MW IT in modules, whatever their size.
"""
for minst, grunnlag in ((M6_MINST, Grunnlag.TRINN_25), (M6_UNDER, Grunnlag.TRINN_5)):
trinn = _laveste_trinn(m6, minst)
for minst, grunnlag, over in (
(M6_MINST, Grunnlag.TRINN_25, 1),
(M6_UNDER, Grunnlag.TRINN_5, 0),
):
trinn = _laveste_trinn(m6, minst, over=over)
if trinn is not None:
return Trinnvalg(trinn=trinn, grunnlag=grunnlag)
for trinn in sorted(m6, reverse=True):

View file

@ -200,6 +200,31 @@ def test_dommene_leses_paa_det_laveste_trinnet_som_gir_25_prosent() -> None:
assert dommer.trinn_for_dommene(stige) == Trinnvalg(10, Grunnlag.TRINN_25)
def test_trinnet_med_ett_anlegg_kan_ikke_vaere_25_prosent_trinnet() -> None:
"""Clarification 104: step 1 reaches 25 % and so does step 10; step 5 only reaches 5 %."""
stige = _stige(n1=(0.3, 10), n5=(0.1, 10), n10=(0.3, 8))
assert dommer.trinn_for_dommene(stige) == Trinnvalg(10, Grunnlag.TRINN_25)
def test_naar_bare_ett_anlegg_naar_25_prosent_leses_dommene_paa_5_prosent_trinnet() -> None:
"""Clarification 104: there is no 25 % step, and step 1 is the lowest that reaches 5 %."""
stige = _stige(n1=(0.3, 10), n5=(0.1, 10), n10=(0.2, 10))
assert dommer.trinn_for_dommene(stige) == Trinnvalg(1, Grunnlag.TRINN_5)
# the single facility reaches 25 % in too few draws to be the 5 % step: the next step is
stige = _stige(n1=(0.3, 7), n5=(0.1, 10))
assert dommer.trinn_for_dommene(stige) == Trinnvalg(5, Grunnlag.TRINN_5)
# a ladder with the single facility only
assert dommer.trinn_for_dommene(_stige(n1=(0.3, 10))) == Trinnvalg(1, Grunnlag.TRINN_5)
def test_regelen_for_trinnet_er_monoton_i_trinnet_med_ett_anlegg() -> None:
"""Clarification 104: a weaker single facility no longer gives another step (103 g)."""
sterk = _stige(n1=(0.3, 10), n5=(0.3, 10))
svak = _stige(n1=(0.03, 10), n5=(0.3, 10))
assert dommer.trinn_for_dommene(sterk) == Trinnvalg(5, Grunnlag.TRINN_25)
assert dommer.trinn_for_dommene(svak) == Trinnvalg(5, Grunnlag.TRINN_25)
def test_ellers_paa_trinnet_som_gir_5_prosent() -> None:
"""25 % is reached in only 7 of 10 draws on the top step; 5 % in 8 of 10 from step 5."""
stige = _stige(n1=(0.03, 10), n5=(0.1, 8), n10=(0.3, 7))