feat(grunnlag): the approved EEA assessment as a fixed table, and M7 rejects a net present value that is not a number (clarifications 136 and 139)
fra_frys takes the assessment of clarification 136 («usikker» for all four ownership forms) and has no guard any more; it is still not called before part 6. beste_per_trekning raises on NaN, where the best would depend on the order of the solutions. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
parent
9b6e65c512
commit
6a51c4f4d2
6 changed files with 75 additions and 37 deletions
|
|
@ -263,7 +263,9 @@ def beste_per_trekning(nnv: Mapping[Losning, Utfall]) -> list[tuple[Losning, ...
|
|||
T-K. One is best alone; several with exactly the same value share the
|
||||
place; an empty tuple is a draw in which none can be built. The rule is the
|
||||
same for all five; a solution that is not passed in is not compared (a run
|
||||
without it). The reference run R and B' are not part of M7.
|
||||
without it). The reference run R and B' are not part of M7. A net present
|
||||
value that is not a number is rejected (clarification 139): the comparison
|
||||
would depend on the order.
|
||||
"""
|
||||
ukjent = [a for a in nnv if a not in DOMSLOSNINGER]
|
||||
if not nnv or ukjent:
|
||||
|
|
@ -271,8 +273,11 @@ def beste_per_trekning(nnv: Mapping[Losning, Utfall]) -> list[tuple[Losning, ...
|
|||
raise ValueError(msg)
|
||||
losninger = [a for a in DOMSLOSNINGER if a in nnv]
|
||||
beste: list[tuple[Losning, ...]] = []
|
||||
for rad in zip(*(nnv[a] for a in losninger), strict=True):
|
||||
for omega, rad in enumerate(zip(*(nnv[a] for a in losninger), strict=True)):
|
||||
byggbare = [(v, a) for v, a in zip(rad, losninger, strict=True) if v is not None]
|
||||
if any(math.isnan(v) for v, _ in byggbare):
|
||||
msg = f"M7: net present value that is not a number in draw {omega} (clarification 139)"
|
||||
raise ValueError(msg)
|
||||
hoyest = max((v for v, _ in byggbare), default=None)
|
||||
beste.append(tuple(a for v, a in byggbare if v == hoyest))
|
||||
return beste
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ import json
|
|||
import math
|
||||
from dataclasses import dataclass, replace
|
||||
from pathlib import Path
|
||||
from types import MappingProxyType
|
||||
from typing import TYPE_CHECKING, Final, NoReturn, cast
|
||||
|
||||
from tokenfabrikker import inndata as ind
|
||||
|
|
@ -67,11 +68,21 @@ to make new draws from a changed file (clarification 132): the basis of such a
|
|||
copy is then still marked «endret». A test holds the two equal in the project.
|
||||
"""
|
||||
|
||||
EOS_MANGLER: Final = (
|
||||
"EØS-vurderingen per eierform er ikke fastsatt (avklaring 127): den er kvalitativ og står "
|
||||
"ikke skrevet ned for de fire eierformene med kilde. Til den står i teksten, kan grunnlaget "
|
||||
"fra frysen ikke lages; bruk en oppdiktet grunnlagsfil (--grunnlag)."
|
||||
EOS_VURDERING: Final[Mapping[str, str]] = MappingProxyType(
|
||||
{
|
||||
"direkte": "usikker",
|
||||
"heleid_selskap": "usikker",
|
||||
"majoritet_boers": "usikker",
|
||||
"petroleumsmodell": "usikker",
|
||||
}
|
||||
)
|
||||
"""The EEA assessment per ownership form (clarification 136, approved by the operator 2026-11-14).
|
||||
|
||||
The source bank says what the test is (terms a comparable private investor would
|
||||
give: K10-051, K10-052, K14-032, K14-007) and assesses none of the four forms,
|
||||
so none can get «består» and none «består ikke». The assessment therefore takes
|
||||
no form out and does not tell them apart; the report says the question is open.
|
||||
"""
|
||||
|
||||
|
||||
class GrunnlagError(ValueError):
|
||||
|
|
@ -516,22 +527,22 @@ def fra_fil(sti: Path) -> Grunnlag:
|
|||
|
||||
|
||||
def fra_frys(
|
||||
eos: Mapping[str, str] | None,
|
||||
eos: Mapping[str, str] | None = None,
|
||||
*,
|
||||
parametere: Path | None = None,
|
||||
data: Path | None = None,
|
||||
) -> Grunnlag:
|
||||
"""The basis from the freeze: the parameter file, the stored draws and the stored stream.
|
||||
|
||||
``eos`` is the EEA assessment per ownership form. It is not written down
|
||||
anywhere yet (clarification 127): with None the function stops at once,
|
||||
before any file is read. The mark is «frosset» when the parameter file has
|
||||
the frozen checksum, else «endret», and the basis carries the checksums of
|
||||
the parameter file, the draws and the stream. The draws must be made from
|
||||
this parameter file.
|
||||
``eos`` is the EEA assessment per ownership form; None gives the one fixed
|
||||
in the text (``EOS_VURDERING``, clarification 136). The mark is «frosset»
|
||||
when the parameter file has the frozen checksum, else «endret», and the
|
||||
basis carries the checksums of the parameter file, the draws and the
|
||||
stream. The draws must be made from this parameter file. Not called before
|
||||
part 6: until then nothing is computed from the freeze.
|
||||
"""
|
||||
if eos is None:
|
||||
raise GrunnlagError(EOS_MANGLER)
|
||||
eos = EOS_VURDERING
|
||||
# Imported here: only the freeze needs the loaders, and they read nothing until called.
|
||||
from tokenfabrikker import hendelser, kjoring, miljo, trekninger # noqa: PLC0415
|
||||
from tokenfabrikker import parametere as par # noqa: PLC0415
|
||||
|
|
|
|||
|
|
@ -11,10 +11,10 @@ tests, the parameter file, the draws, the stream, the specification and the
|
|||
map to a folder the user owns (132).
|
||||
|
||||
Every command that computes takes the basis from exactly one of
|
||||
``--grunnlag FIL`` (a made-up basis file) or ``--frys`` (the freeze). Until
|
||||
the EEA assessment per ownership form is written down (clarification 127),
|
||||
``--frys`` stops before anything is read. The number of processes is a choice
|
||||
on the command line and changes no figure.
|
||||
``--grunnlag FIL`` (a made-up basis file) or ``--frys`` (the freeze, with the
|
||||
EEA assessment of clarification 136; not used before part 6, when the results
|
||||
are computed). The number of processes is a choice on the command line and
|
||||
changes no figure.
|
||||
|
||||
What the tools write for the user is Norwegian. An input file is read
|
||||
strictly: an unknown field, a missing field, a value of the wrong type, and an
|
||||
|
|
@ -229,7 +229,7 @@ def verktoyfelt(kommando: str, inngang: object) -> dict[str, object]:
|
|||
def hent_grunnlag(valg: argparse.Namespace) -> Grunnlag:
|
||||
"""The basis from ``--grunnlag`` or ``--frys`` (clarification 127)."""
|
||||
if valg.frys:
|
||||
return gl.fra_frys(None)
|
||||
return gl.fra_frys()
|
||||
return gl.fra_fil(Path(valg.grunnlag))
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -119,6 +119,15 @@ def test_m7_hvem_som_er_best_blant_a_b_og_c() -> None:
|
|||
# ------------------------------------------------------------------ M3 and M4
|
||||
|
||||
|
||||
def test_M7_avviser_en_netto_naaverdi_som_ikke_er_et_tall() -> None:
|
||||
"""Clarification 139: with NaN the best would depend on the order of the solutions."""
|
||||
with pytest.raises(ValueError, match="not a number in draw 1"):
|
||||
dommer.beste_per_trekning({Losning.A: [1.0, math.nan], Losning.B: [2.0, 0.0]})
|
||||
with pytest.raises(ValueError, match="not a number in draw 0"):
|
||||
dommer.beste_per_trekning({Losning.B: [0.0], Losning.C: [math.nan]})
|
||||
assert dommer.beste_per_trekning({Losning.A: [-math.inf], Losning.B: [None]}) == [(Losning.A,)]
|
||||
|
||||
|
||||
def test_m3_verste_prisvirkning_i_R(oppdiktet: LagInndata) -> None:
|
||||
"""One facility in R takes 3.942 TWh from the balance: 39.42 kr/MWh on a price of 600.
|
||||
|
||||
|
|
|
|||
|
|
@ -99,12 +99,22 @@ def test_faste_verdier_settes_etter_trekningen_i_filas_enhet(grunnlag: gl.Grunnl
|
|||
grunnlag.med_verdier({"finnes_ikke": 1.0})
|
||||
|
||||
|
||||
def test_grunnlaget_fra_frysen_stanser_foer_noe_leses_uten_EOS_vurderingen() -> None:
|
||||
"""Clarification 127, «Mangler før del 6»: the guard comes before any file is read."""
|
||||
with pytest.raises(gl.GrunnlagError, match=r"EØS-vurderingen per eierform er ikke fastsatt"):
|
||||
gl.fra_frys(None, parametere=Path("/finnes/ikke.json"), data=Path("/finnes/ikke"))
|
||||
with pytest.raises(gl.GrunnlagError, match=r"avklaring 127"):
|
||||
gl.fra_frys(None)
|
||||
def test_EOS_vurderingen_er_usikker_for_alle_fire_eierformene(grunnlag: gl.Grunnlag) -> None:
|
||||
"""Clarification 136, approved 2026-11-14: no form is taken out and none is told apart."""
|
||||
assert dict(gl.EOS_VURDERING) == {
|
||||
"direkte": "usikker",
|
||||
"heleid_selskap": "usikker",
|
||||
"majoritet_boers": "usikker",
|
||||
"petroleumsmodell": "usikker",
|
||||
}
|
||||
assert set(gl.EOS_VURDERING) == set(grunnlag.eos)
|
||||
assert set(gl.EOS_VURDERING.values()) <= set(gl.EOS_VURDERINGER)
|
||||
|
||||
|
||||
def test_grunnlaget_fra_frysen_har_ingen_sperre_og_leser_filene_det_faar() -> None:
|
||||
"""The guard of clarification 127 is gone; with files that do not exist nothing is read."""
|
||||
with pytest.raises(FileNotFoundError):
|
||||
gl.fra_frys(parametere=Path("/finnes/ikke.json"), data=Path("/finnes/ikke"))
|
||||
|
||||
|
||||
def test_den_frosne_sjekksummen_er_den_i_parameterkoden() -> None:
|
||||
|
|
|
|||
|
|
@ -390,18 +390,21 @@ def test_inngangsfila_leses_strengt_og_stanser_foer_noe_regnes(
|
|||
assert not ut.exists()
|
||||
|
||||
|
||||
def test_frysen_stanser_ved_vakten(tmp_path: Path, capsys: pytest.CaptureFixture[str]) -> None:
|
||||
"""Clarification 127: until the EEA assessment is written down, --frys stops at once."""
|
||||
sti = _skriv_inngang(tmp_path, {"navn": "x"})
|
||||
for argumenter in (
|
||||
["scenario", sti, "--frys", "--ut", str(tmp_path / "ut")],
|
||||
["hovedkjoring", "--frys", "--ut", str(tmp_path / "ut")],
|
||||
):
|
||||
assert vt.main(argumenter) == 2
|
||||
assert (
|
||||
"EØS-vurderingen per eierform er ikke fastsatt (avklaring 127)"
|
||||
in capsys.readouterr().err
|
||||
)
|
||||
def test_frysen_henter_grunnlaget_fra_frysen(
|
||||
tmp_path: Path, monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
|
||||
) -> None:
|
||||
"""--frys asks for the basis from the freeze; the freeze itself is not read before part 6."""
|
||||
kalt: list[tuple[object, ...]] = []
|
||||
|
||||
def fra_frys(*args: object) -> gl.Grunnlag:
|
||||
kalt.append(args)
|
||||
msg = "ikke lest i testen"
|
||||
raise gl.GrunnlagError(msg)
|
||||
|
||||
monkeypatch.setattr(gl, "fra_frys", fra_frys)
|
||||
assert vt.main(["hovedkjoring", "--frys", "--ut", str(tmp_path / "ut")]) == 2
|
||||
assert "ikke lest i testen" in capsys.readouterr().err
|
||||
assert kalt == [()]
|
||||
assert not (tmp_path / "ut").exists()
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue