Six new readers who had seen nothing, two of them well-informed supporters of nuclear power, read the built PDFs, the carousel proposal and the post; a controller tried to refute each finding. 73 findings: 30 confirmed, 42 partly, 1 rejected. No measured number, equation or code was wrong. One sentence in chapter 4 was (interest during the data centre's construction time does not apply equally to Norway and the competitor); clarification 143 corrects it and chapter 8 lists it as not computed. - grid-connected nuclear now stands next to the dedicated plant where the conclusion is drawn; caveats are listed in both directions - what the dedicated plant is in the model; Barakah in chapter 7 and 8 (new entry K28-011) - the direction of the discount rate is explained from S26 instead of "not explained"; what remains unexplained is still said outright - the price rule, the numerator and denominator of the scale target, the state's rate, requirements that hold by construction, the two build-rate caps - the rest from reading rounds 9a and 9b; title of K06-016 corrected - the web page rebuilt (7211 numbers checked against the result files) - report 171 pages, summary 2 pages (set in 10 pt); PDFs rebuilt The carousel is unchanged: its new wording is a proposal until the project owner has approved it. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
583 lines
23 KiB
Python
583 lines
23 KiB
Python
r"""The LinkedIn carousel (rapport/karusell.tex): the numbers it shows and its figure geometry.
|
|
|
|
The carousel restates, in plain words, what chapter 6 and the summaries state. Most of its
|
|
numbers are keys the other modules already give; this module adds only what the carousel shows
|
|
with another rounding or puts together from several values, and it writes the geometry of the
|
|
carousel's figures (dot rows, the bar of the petroleum income, the staircase, the timeline, the
|
|
price bars) to rapport/generert/karusell-*.tex. The figures hold no words: the labels stand in
|
|
karusell.tex and are placed at the named coordinates written here.
|
|
|
|
Reads dommer.json (verdicts, shares, the comparison M7, the paths that cannot be built),
|
|
fordelinger.json (percentiles 0 to 100 of the net present value and of M6), tidslinje.json
|
|
(MW IT in operation per year), eierformer.json (the probability of a loss for the state),
|
|
folsomheter.json (row 16, the state's ordinary discount rate) and terskler.json (the price
|
|
thresholds). Every number shown is returned as a Tall under a key that starts with "karusell.".
|
|
|
|
Standard library only. Coordinates are in millimetres, written with three decimals.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import dataclasses
|
|
import math
|
|
from dataclasses import dataclass
|
|
from typing import TYPE_CHECKING, Any
|
|
|
|
from resultater.felles import LOSNING, MINUS, SCENARIO, Tall, fra_fil, hent, les, norsk
|
|
|
|
if TYPE_CHECKING:
|
|
from collections.abc import Callable
|
|
from pathlib import Path
|
|
|
|
from resultater.felles import Steg
|
|
|
|
DOM = "dommer.json"
|
|
FORD = "fordelinger.json"
|
|
TID = "tidslinje.json"
|
|
EIER = "eierformer.json"
|
|
FOLS = "folsomheter.json"
|
|
TERSK = "terskler.json"
|
|
|
|
FEM = ("A", "B", "C", "T-F", "T-K")
|
|
NORMAL = "normalisering"
|
|
KNAPPHET = "knapphet varer"
|
|
MAAL = ("M1", "M2", "M3", "M4", "M5", "M6")
|
|
MEDIAN = 50
|
|
PERSENTILER = 101
|
|
# Slide 16: the solutions with nuclear power against those with new renewables, five facilities.
|
|
KJERNEKRAFT = ("A", "B", "T-K")
|
|
FORNYBAR = ("C", "T-F")
|
|
# The colour of each solution, defined in karusell.tex.
|
|
FARGE = {"A": "farA", "B": "farB", "C": "farC", "T-F": "farTF", "T-K": "farTK"}
|
|
# Slide 18: the verdict words of the pre-registration as the carousel's table writes them. The
|
|
# conditional verdict has one word for every target, «på vilkår» (M5 has no share of the draws).
|
|
TABELLORD = {"holder": "Ja", "holder ikke": "Nei", "holder under betingelser": "På vilkår"}
|
|
TABELLORD_M5 = {"holder": "Ja", "holder under betingelser": "På vilkår"}
|
|
# Slide 15: the capacity whose first year in the median is marked (MW IT), and the rules of
|
|
# tidslinje.py for the other three marks (clarification 75).
|
|
HALVVEIS_MW = 500.0
|
|
HALV = 0.5
|
|
# The fixed quantities of the pre-registration (slides 5 and 13): the limits of M6 as shares of
|
|
# the state's petroleum income. The bar is drawn at one millimetre per per cent.
|
|
GRENSE_IKKE = 0.05
|
|
GRENSE_NY = 0.25
|
|
MM_PER_PST = 1.0
|
|
OLJE_VENSTRE = 26.0
|
|
BIDRAG_RAD = 6.0
|
|
PRIS_RAD = 22.0
|
|
LIK = 1e-9
|
|
|
|
|
|
def _mm(x: float) -> str:
|
|
return f"{x:.3f}mm"
|
|
|
|
|
|
def _pkt(x: float, y: float) -> str:
|
|
return f"({_mm(x)},{_mm(y)})"
|
|
|
|
|
|
def _sti(scenario: str, trinn: int, *rest: Steg) -> tuple[Steg, ...]:
|
|
return ("per_scenario", ("navn", scenario), "trinn", ("trinn", trinn), *rest)
|
|
|
|
|
|
def _forklar(t: Tall, forklaring: str) -> Tall:
|
|
return dataclasses.replace(t, forklaring=forklaring)
|
|
|
|
|
|
def _andel(verdi: float, desimaler: int, fil: str, forklaring: str) -> Tall:
|
|
"""A derived share, kept as a share and shown in per cent (rounded in decimal, felles.norsk)."""
|
|
return Tall(
|
|
norsk(verdi, desimaler, "100"),
|
|
fil,
|
|
(),
|
|
verdi,
|
|
"avledet",
|
|
desimaler,
|
|
forklaring + "; shown in per cent",
|
|
)
|
|
|
|
|
|
def _hvor(sti: tuple[Steg, ...]) -> str:
|
|
"""A path as text: (field, value) as field[value]."""
|
|
return ".".join(f"{s[0]}[{s[1]}]" if isinstance(s, tuple) else str(s) for s in sti)
|
|
|
|
|
|
def _skriv(ut: Path, navn: str, linjer: list[str]) -> None:
|
|
(ut / navn).write_text("\n".join(linjer) + "\n", encoding="utf-8")
|
|
|
|
|
|
# ------------------------------------------------------------------ numbers
|
|
|
|
|
|
def _m7(d: Any, tall: dict[str, Tall]) -> None: # noqa: ANN401
|
|
"""Slide 16: who comes out best for one facility, and for five."""
|
|
en = _sti(NORMAL, 1, "M7")
|
|
tall["karusell.m7.t1.C.alene"] = fra_fil(d, DOM, (*en, "C", "best_alene"), "pst", 1)
|
|
tall["karusell.m7.t1.A.alene"] = fra_fil(d, DOM, (*en, "A", "best_alene"), "pst", 1)
|
|
fem = _sti(NORMAL, 5, "M7")
|
|
m7 = hent(d, fem)
|
|
hvor = "per_scenario[normalisering].trinn[5].M7"
|
|
tall["karusell.m7.t5.kjernekraft"] = _andel(
|
|
math.fsum(m7[los]["best_alene"] for los in KJERNEKRAFT),
|
|
0,
|
|
DOM,
|
|
f"best_alene of A + B + T-K in {hvor}",
|
|
)
|
|
tall["karusell.m7.t5.fornybar"] = _andel(
|
|
math.fsum(m7[los]["best_alene"] for los in FORNYBAR),
|
|
0,
|
|
DOM,
|
|
f"best_alene of C + T-F in {hvor}",
|
|
)
|
|
tall["karusell.m7.t5.ingen"] = fra_fil(d, DOM, (*fem, "ingen", "andel"), "pst", 0)
|
|
# The shares of a step add up to one: alone, shared, or no solution that can be built.
|
|
helhet = math.fsum(
|
|
[*(m7[los]["best_alene"] for los in FEM), m7["delt"]["andel"], m7["ingen"]["andel"]]
|
|
)
|
|
if abs(helhet - 1.0) > LIK:
|
|
melding = f"M7 på trinn 5 summerer til {helhet!r}, ikke 1"
|
|
raise ValueError(melding)
|
|
|
|
|
|
def _trapp(d: Any, tall: dict[str, Tall]) -> list[tuple[int, float, float]]: # noqa: ANN401
|
|
"""Slide 14: the lowest and highest share of the five solutions that cannot be built."""
|
|
trinnene: list[tuple[int, float, float]] = []
|
|
for trinn in d["stige"]:
|
|
stier = {los: _sti(NORMAL, trinn, "losninger", los, "M1", "ikke_byggbar") for los in FEM}
|
|
verdier = {los: float(hent(d, sti)) for los, sti in stier.items()}
|
|
lav = min(FEM, key=lambda los: verdier[los])
|
|
hoy = max(FEM, key=lambda los: verdier[los])
|
|
for navn, los, hva in (("lav", lav, "lowest"), ("hoy", hoy, "highest")):
|
|
tall[f"karusell.trapp.t{trinn}.{navn}"] = _forklar(
|
|
fra_fil(d, DOM, stier[los], "pst", 0),
|
|
f"the {hva} ikke_byggbar of A, B, C, T-F and T-K on step {trinn} ({los})",
|
|
)
|
|
trinnene.append((trinn, verdier[lav], verdier[hoy]))
|
|
# The slide shows one number for one facility and one for 20 and 40 facilities together.
|
|
vist = {
|
|
(n, h): tall[f"karusell.trapp.t{n}.{h}"].vist for n in d["stige"] for h in ("lav", "hoy")
|
|
}
|
|
if (
|
|
len({vist[1, "lav"], vist[1, "hoy"]}) != 1
|
|
or len({vist[n, h] for n in (20, 40) for h in ("lav", "hoy")}) != 1
|
|
):
|
|
melding = f"trappen viser ett tall der løsningene gir ulike: {vist}"
|
|
raise ValueError(melding)
|
|
return trinnene
|
|
|
|
|
|
def _forste_aar(
|
|
t: Any, # noqa: ANN401
|
|
los: str,
|
|
vilkaar: Callable[[dict[str, Any]], bool],
|
|
) -> int:
|
|
rader = hent(t, ("per_losning", los, ("trinn", 1), "typer", "alle"))
|
|
return int(next(r["aar"] for r in rader if vilkaar(r)))
|
|
|
|
|
|
def _tidslinje(t: Any, tall: dict[str, Tall]) -> dict[str, int]: # noqa: ANN401
|
|
"""Slide 15: the four years, and the key for the first year with 500 MW IT in the median.
|
|
|
|
The other three years are keys of tidslinje.py (median-aar of T-F, halv-1000-aar of C and A);
|
|
they are found again here by the same rules, only to place the marks.
|
|
"""
|
|
halvveis = {
|
|
los: _forste_aar(t, los, lambda r: r["median"] >= HALVVEIS_MW) for los in ("T-F", "T-K")
|
|
}
|
|
if halvveis["T-F"] != halvveis["T-K"]:
|
|
melding = f"T-F og T-K når {HALVVEIS_MW} MW i ulike år: {halvveis}"
|
|
raise ValueError(melding)
|
|
aar = halvveis["T-F"]
|
|
sti: tuple[Steg, ...] = ("per_losning", "T-F", ("trinn", 1), "typer", "alle", ("aar", aar))
|
|
tall["karusell.tid.TF.500-aar"] = Tall(
|
|
str(aar),
|
|
TID,
|
|
(*sti, "aar"),
|
|
aar,
|
|
"tekst",
|
|
0,
|
|
"the first year in per_losning.T-F[trinn=1].typer.alle with median >= 500 (MW IT); "
|
|
"T-K gives the same year",
|
|
)
|
|
return {
|
|
"forste": _forste_aar(t, "T-F", lambda r: r["median"] > 0),
|
|
"halvveis": aar,
|
|
"fornybar": _forste_aar(t, "C", lambda r: r["andel_minst_1000_MW"] >= HALV),
|
|
"kjerne": _forste_aar(t, "A", lambda r: r["andel_minst_1000_MW"] >= HALV),
|
|
}
|
|
|
|
|
|
def _eierformer(e: Any, tall: dict[str, Tall]) -> None: # noqa: ANN401
|
|
"""Slide 24: the lowest and highest probability of a loss for the state, all forms."""
|
|
stier: list[tuple[Steg, ...]] = [
|
|
("per_losning", los, "kriterier", form, "tapssannsynlighet")
|
|
for los in FEM
|
|
for form in e["per_losning"][los]["kriterier"]
|
|
]
|
|
lav = min(stier, key=lambda s: float(hent(e, s)))
|
|
hoy = max(stier, key=lambda s: float(hent(e, s)))
|
|
for navn, sti, hva in (("tap-lav", lav, "lowest"), ("tap-hoy", hoy, "highest")):
|
|
tall[f"karusell.eier.{navn}"] = _forklar(
|
|
fra_fil(e, EIER, sti, "pst", 1),
|
|
f"the {hva} tapssannsynlighet of the four forms and five solutions",
|
|
)
|
|
|
|
|
|
def _krav(d: Any, tall: dict[str, Tall]) -> None: # noqa: ANN401
|
|
"""Slide 18: the verdict per target for one facility in «normalisering», as table words."""
|
|
for los in ("C", "B", "A"):
|
|
lk = LOSNING[los]
|
|
for maal in MAAL:
|
|
if maal == "M5":
|
|
sti = _sti(NORMAL, 1, "losninger", los, "M5")
|
|
ordbok = TABELLORD_M5
|
|
else:
|
|
sti = _sti(NORMAL, 1, "losninger", los, maal, "dom")
|
|
ordbok = TABELLORD
|
|
dom = hent(d, sti)
|
|
if dom not in ordbok:
|
|
melding = f"uventet dom {dom!r} for {los} {maal}"
|
|
raise ValueError(melding)
|
|
tall[f"karusell.krav.{lk}.{maal.lower()}"] = Tall(
|
|
ordbok[dom], DOM, sti, dom, "tekst", 0, f"the verdict {dom!r} as the table word"
|
|
)
|
|
if maal not in ("M1", "M2"):
|
|
continue
|
|
andel = _sti(NORMAL, 1, "losninger", los, maal, "andel_holder")
|
|
if hent(d, andel) == 0:
|
|
tall[f"karusell.krav.{lk}.{maal.lower()}-ingen"] = Tall(
|
|
"ingen",
|
|
DOM,
|
|
andel,
|
|
hent(d, andel),
|
|
"tekst",
|
|
0,
|
|
"andel_holder is exactly 0: the target is met in no draw",
|
|
)
|
|
|
|
|
|
# ------------------------------------------------------------------ dot rows
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class Akse:
|
|
"""A horizontal axis in billions of kroner, drawn from x = 0 to x = bredde millimetres."""
|
|
|
|
xmin: float
|
|
xmax: float
|
|
bredde: float
|
|
|
|
def x(self, mrd: float) -> float:
|
|
"""The position in millimetres of a value in billions of kroner."""
|
|
return (mrd - self.xmin) / (self.xmax - self.xmin) * self.bredde
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class Rad:
|
|
"""One row of 101 dots: the percentiles 0 to 100 of one solution in one scenario."""
|
|
|
|
navn: str
|
|
scenario: str
|
|
losning: str
|
|
fyll: str
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class Prikkfigur:
|
|
"""Rows of dots on one axis, with the parameters of the swarm and the ticks (bn NOK)."""
|
|
|
|
navn: str
|
|
akse: Akse
|
|
rader: tuple[Rad, ...]
|
|
radavstand: float
|
|
radius: float
|
|
baner: int
|
|
hakk: tuple[int, ...]
|
|
nullinje: bool = True
|
|
median: bool = True
|
|
|
|
|
|
def _baner(xs: list[float], radius: float, antall: int) -> list[int]:
|
|
"""A lane per dot (0, +1, -1, +2, ...): the first lane where it does not touch the one before.
|
|
|
|
The dots come in increasing order. When no lane is free, the dot goes in the lane that has
|
|
been free longest and overlaps; the dots are drawn half transparent.
|
|
"""
|
|
rekke = [0]
|
|
for k in range(1, antall + 1):
|
|
rekke += [k, -k]
|
|
siste = dict.fromkeys(rekke, -math.inf)
|
|
baner = []
|
|
for x in xs:
|
|
fri = next((b for b in rekke if x - siste[b] >= 2 * radius * 0.92), None)
|
|
if fri is None:
|
|
fri = min(rekke, key=lambda b: siste[b])
|
|
siste[fri] = x
|
|
baner.append(fri)
|
|
return baner
|
|
|
|
|
|
def _hakk(fig: Prikkfigur, topp: float, bunn: float) -> list[str]:
|
|
linjer = []
|
|
for hakk in fig.hakk:
|
|
x = fig.akse.x(hakk)
|
|
tekst = (MINUS if hakk < 0 else "") + norsk(abs(hakk), 0)
|
|
linjer += [
|
|
f"\\draw[prikkgitter] {_pkt(x, topp)} -- {_pkt(x, bunn)};",
|
|
f"\\draw[prikkakse] {_pkt(x, bunn)} -- ++(0,-1mm) node[below,prikkhakk] {{{tekst}}};",
|
|
]
|
|
return linjer
|
|
|
|
|
|
def _prikkfigur(f: Any, fig: Prikkfigur, tall: dict[str, Tall]) -> list[str]: # noqa: ANN401
|
|
"""The TikZ code of a dot figure; the dots left of the axis get two keys per row."""
|
|
a = fig.akse
|
|
avstand = 1.9 * fig.radius
|
|
halv = fig.baner * avstand + fig.radius
|
|
topp = halv + 1.5
|
|
bunn = -(len(fig.rader) - 1) * fig.radavstand - halv - 1.5
|
|
null = a.x(0.0)
|
|
linjer = [
|
|
f"% Generated by rapport/resultater/karusell.py from {FORD}; do not edit.",
|
|
f"% Axis from {a.xmin} to {a.xmax} bn NOK over {a.bredde} mm.",
|
|
*_hakk(fig, topp, bunn),
|
|
f"\\coordinate ({fig.navn}-null-topp) at {_pkt(null, topp)};",
|
|
f"\\coordinate ({fig.navn}-null-bunn) at {_pkt(null, bunn)};",
|
|
f"\\coordinate ({fig.navn}-venstre-topp) at {_pkt(0, topp)};",
|
|
f"\\coordinate ({fig.navn}-hoyre-topp) at {_pkt(a.bredde, topp)};",
|
|
f"\\coordinate ({fig.navn}-venstre-bunn) at {_pkt(0, bunn)};",
|
|
f"\\coordinate ({fig.navn}-hoyre-bunn) at {_pkt(a.bredde, bunn)};",
|
|
]
|
|
if fig.hakk:
|
|
linjer.append(f"\\draw[prikkakse] {_pkt(0, bunn)} -- {_pkt(a.bredde, bunn)};")
|
|
for nr, rad in enumerate(fig.rader):
|
|
y = -nr * fig.radavstand
|
|
sti = _sti(rad.scenario, 1, "losninger", rad.losning, "NNV", "persentiler")
|
|
verdier = [float(v) / 1e9 for v in hent(f, sti)]
|
|
if len(verdier) != PERSENTILER or verdier != sorted(verdier):
|
|
melding = f"{rad.navn}: ikke {PERSENTILER} stigende persentiler"
|
|
raise ValueError(melding)
|
|
if verdier[-1] > a.xmax:
|
|
melding = f"{fig.navn} {rad.navn}: {verdier[-1]} ligger til høyre for aksen"
|
|
raise ValueError(melding)
|
|
innenfor = [v for i, v in enumerate(verdier) if v >= a.xmin and i != MEDIAN]
|
|
utenfor = sum(1 for v in verdier if v < a.xmin)
|
|
baner = _baner([a.x(v) for v in innenfor], fig.radius, fig.baner)
|
|
linjer += [
|
|
f"% {rad.navn}: {rad.losning}, {rad.scenario}; {utenfor} dots left of the axis",
|
|
f"\\coordinate ({fig.navn}-{rad.navn}-venstre) at {_pkt(0, y + halv)};",
|
|
f"\\coordinate ({fig.navn}-{rad.navn}-hoyre) at {_pkt(a.bredde, y + halv)};",
|
|
f"\\coordinate ({fig.navn}-{rad.navn}-midt) at {_pkt(0, y)};",
|
|
]
|
|
linjer += [
|
|
f"\\fill[prikk,fill={rad.fyll}] {_pkt(a.x(v), y + bane * avstand)} "
|
|
f"circle[radius={_mm(fig.radius)}];"
|
|
for v, bane in zip(innenfor, baner, strict=True)
|
|
]
|
|
if utenfor:
|
|
linjer.append(
|
|
f"\\fill[fill={rad.fyll}] {_pkt(-3.4, y)} -- {_pkt(-0.8, y + 1.5)} -- "
|
|
f"{_pkt(-0.8, y - 1.5)} -- cycle;"
|
|
)
|
|
nokkel = f"karusell.prikker.{fig.navn}.{SCENARIO[rad.scenario]}.{LOSNING[rad.losning]}"
|
|
tall[f"{nokkel}.utenfor"] = Tall(
|
|
str(utenfor),
|
|
FORD,
|
|
(),
|
|
utenfor,
|
|
"avledet",
|
|
0,
|
|
f"how many of the {PERSENTILER} values at {_hvor(sti)} lie below {a.xmin} bn NOK, "
|
|
"the left end of the axis",
|
|
)
|
|
tall[f"{nokkel}.laveste"] = fra_fil(f, FORD, (*sti, 0), "mrd", 1)
|
|
xm = a.x(verdier[MEDIAN])
|
|
linjer.append(f"\\coordinate ({fig.navn}-{rad.navn}-median) at {_pkt(xm, y)};")
|
|
stil = "median" if fig.median else "prikk"
|
|
storrelse = avstand if fig.median else fig.radius
|
|
linjer.append(
|
|
f"\\fill[{stil},fill={rad.fyll}] {_pkt(xm, y)} circle[radius={_mm(storrelse)}];"
|
|
)
|
|
if fig.nullinje:
|
|
linjer.append(f"\\draw[nullinje] ({fig.navn}-null-topp) -- ({fig.navn}-null-bunn);")
|
|
return linjer
|
|
|
|
|
|
def _prikkfigurer() -> tuple[Prikkfigur, ...]:
|
|
c_norm = Rad("C", NORMAL, "C", FARGE["C"])
|
|
return (
|
|
# Slide 8: the cloud; slide 10: how to read a row (one facility, new renewables).
|
|
Prikkfigur(
|
|
"sky",
|
|
Akse(-150.0, 50.0, 72.0),
|
|
(c_norm,),
|
|
0.0,
|
|
1.0,
|
|
9,
|
|
(),
|
|
nullinje=False,
|
|
median=False,
|
|
),
|
|
Prikkfigur("lese", Akse(-150.0, 50.0, 124.0), (c_norm,), 0.0, 1.0, 6, ()),
|
|
# Slide 12: one facility, five solutions, in the order of their medians.
|
|
Prikkfigur(
|
|
"funn1",
|
|
Akse(-600.0, 150.0, 124.0),
|
|
tuple(Rad(LOSNING[x], NORMAL, x, FARGE[x]) for x in ("C", "T-F", "T-K", "B", "A")),
|
|
11.0,
|
|
0.8,
|
|
2,
|
|
(-600, -500, -400, -300, -200, -100, 0, 100),
|
|
),
|
|
# Slide 21: new renewables and a dedicated nuclear plant, normal market and scarcity.
|
|
Prikkfigur(
|
|
"knapphet",
|
|
Akse(-600.0, 800.0, 124.0),
|
|
(
|
|
Rad("Cn", NORMAL, "C", FARGE["C"] + "lys"),
|
|
Rad("Ck", KNAPPHET, "C", FARGE["C"]),
|
|
Rad("An", NORMAL, "A", FARGE["A"] + "lys"),
|
|
Rad("Ak", KNAPPHET, "A", FARGE["A"]),
|
|
),
|
|
13.0,
|
|
0.75,
|
|
2,
|
|
(-600, -400, -200, 0, 200, 400, 600, 800),
|
|
),
|
|
)
|
|
|
|
|
|
# ------------------------------------------------------------------ the other figures
|
|
|
|
|
|
def _olje() -> list[str]:
|
|
"""Slides 5 and 13: the bar of the petroleum income, 0 to 100 %, and the limits 5 and 25 %."""
|
|
x0 = OLJE_VENSTRE
|
|
return [
|
|
"% Generated by rapport/resultater/karusell.py: the limits of the pre-registration.",
|
|
f"\\coordinate (olje-null) at {_pkt(x0, 0)};",
|
|
f"\\coordinate (olje-slutt) at {_pkt(x0 + 100 * MM_PER_PST, 0)};",
|
|
f"\\coordinate (olje-fem) at {_pkt(x0 + GRENSE_IKKE * 100 * MM_PER_PST, 0)};",
|
|
f"\\coordinate (olje-tjuefem) at {_pkt(x0 + GRENSE_NY * 100 * MM_PER_PST, 0)};",
|
|
]
|
|
|
|
|
|
def _bidrag(f: Any) -> list[str]: # noqa: ANN401
|
|
"""Slide 13: the median of M6 per solution as a bar from zero, on the scale of the oil bar."""
|
|
medianer = {
|
|
los: float(hent(f, _sti(NORMAL, 1, "losninger", los, "M6", "persentiler", MEDIAN)))
|
|
for los in FEM
|
|
}
|
|
linjer = [f"% Generated by rapport/resultater/karusell.py from {FORD} (M6, percentile 50)."]
|
|
rekke = sorted(FEM, key=lambda los: -medianer[los])
|
|
for nr, los in enumerate(rekke):
|
|
if medianer[los] >= 0:
|
|
melding = f"M6-medianen for {los} er ikke negativ"
|
|
raise ValueError(melding)
|
|
lk = LOSNING[los]
|
|
y = -nr * BIDRAG_RAD
|
|
x = OLJE_VENSTRE + medianer[los] * 100 * MM_PER_PST
|
|
linjer += [
|
|
f"\\coordinate (bidrag-{lk}) at {_pkt(OLJE_VENSTRE, y)};",
|
|
f"\\coordinate (bidrag-{lk}-ende) at {_pkt(x, y)};",
|
|
(
|
|
f"\\fill[fill={FARGE[los]}] {_pkt(x, y - 2.2)} "
|
|
f"rectangle {_pkt(OLJE_VENSTRE, y + 2.2)};"
|
|
),
|
|
f"\\fill[fill={FARGE[los]}] {_pkt(x, y)} circle[radius=0.9mm];",
|
|
]
|
|
linjer.append(
|
|
f"\\coordinate (bidrag-bunn) at {_pkt(OLJE_VENSTRE, -(len(rekke) - 1) * BIDRAG_RAD - 2.2)};"
|
|
)
|
|
return linjer
|
|
|
|
|
|
def _trapp_figur(trinnene: list[tuple[int, float, float]]) -> list[str]:
|
|
"""Slide 14: one column per step, the lowest share solid and up to the highest share light."""
|
|
hoyde, bredde, mellom = 60.0, 17.0, 25.0
|
|
linjer = [
|
|
"% Generated by rapport/resultater/karusell.py from dommer.json (M1.ikke_byggbar).",
|
|
f"\\draw[trappgrunn] {_pkt(0, 0)} -- {_pkt(len(trinnene) * mellom, 0)};",
|
|
f"\\coordinate (trapp-hel) at {_pkt(0, hoyde)};",
|
|
]
|
|
for nr, (trinn, lav, hoy) in enumerate(trinnene):
|
|
x = nr * mellom + (mellom - bredde) / 2
|
|
if hoy > lav:
|
|
linjer.append(
|
|
f"\\fill[trapphoy] {_pkt(x, lav * hoyde)} "
|
|
f"rectangle {_pkt(x + bredde, hoy * hoyde)};"
|
|
)
|
|
if lav > 0:
|
|
linjer.append(
|
|
f"\\fill[trapplav] {_pkt(x, 0)} rectangle {_pkt(x + bredde, lav * hoyde)};"
|
|
)
|
|
linjer += [
|
|
f"\\coordinate (trapp-{trinn}-topp) at {_pkt(x + bredde / 2, hoy * hoyde)};",
|
|
f"\\coordinate (trapp-{trinn}-bunn) at {_pkt(x + bredde / 2, 0)};",
|
|
]
|
|
return linjer
|
|
|
|
|
|
def _tidslinje_figur(aar: dict[str, int]) -> list[str]:
|
|
"""Slide 15: an axis from 2026 to 2050 and the four years the slide marks."""
|
|
start, slutt, bredde = 2026, 2050, 124.0
|
|
|
|
def x(et: float) -> float:
|
|
return (et - start) / (slutt - start) * bredde
|
|
|
|
linjer = [
|
|
"% Generated by rapport/resultater/karusell.py from tidslinje.json.",
|
|
f"\\draw[tidakse] {_pkt(0, 0)} -- {_pkt(bredde, 0)};",
|
|
]
|
|
for et in range(start, slutt + 1):
|
|
lang = et % 5 == 0 or et in (start, slutt)
|
|
linjer.append(f"\\draw[tidhakk] {_pkt(x(et), 0)} -- ++(0,{'-2mm' if lang else '-1mm'});")
|
|
if lang:
|
|
linjer.append(f"\\node[tidtekst,below] at {_pkt(x(et), -2.0)} {{{et}}};")
|
|
linjer += [f"\\coordinate (tid-{navn}) at {_pkt(x(et), 0)};" for navn, et in aar.items()]
|
|
return linjer
|
|
|
|
|
|
def _pris_figur(ters: Any) -> list[str]: # noqa: ANN401
|
|
"""Slide 23: how far above the model's path the price must be, one bar per solution."""
|
|
linjer = [f"% Generated by rapport/resultater/karusell.py from {TERSK} (pristerskler, k)."]
|
|
for nr, los in enumerate(("C", "B", "A")):
|
|
k = float(hent(ters, ("pristerskler", los, NORMAL, "k")))
|
|
lk = LOSNING[los]
|
|
y = -nr * PRIS_RAD
|
|
lengde = (k - 1) * 100 * MM_PER_PST
|
|
linjer += [
|
|
f"\\fill[fill={FARGE[los]}] {_pkt(0, y - 4)} rectangle {_pkt(lengde, y + 4)};",
|
|
f"\\coordinate (pris-{lk}) at {_pkt(0, y)};",
|
|
f"\\coordinate (pris-{lk}-ende) at {_pkt(lengde, y)};",
|
|
]
|
|
return linjer
|
|
|
|
|
|
def lag(data: Path, ut: Path) -> dict[str, Tall]:
|
|
"""Write the carousel's figure geometry and return the numbers only the carousel shows."""
|
|
d = les(data, DOM)
|
|
f = les(data, FORD)
|
|
tall: dict[str, Tall] = {}
|
|
_m7(d, tall)
|
|
trinnene = _trapp(d, tall)
|
|
aar = _tidslinje(les(data, TID), tall)
|
|
_eierformer(les(data, EIER), tall)
|
|
_krav(d, tall)
|
|
fols = les(data, FOLS)
|
|
for los in ("C", "B"):
|
|
tall[f"karusell.rad16.{LOSNING[los]}.m1-andel"] = fra_fil(
|
|
fols,
|
|
FOLS,
|
|
("rader", "16", "tabell", NORMAL, "losninger", los, "M1", "andel_holder"),
|
|
"pst",
|
|
1,
|
|
)
|
|
for fig in _prikkfigurer():
|
|
_skriv(ut, f"karusell-prikker-{fig.navn}.tex", _prikkfigur(f, fig, tall))
|
|
_skriv(ut, "karusell-olje.tex", _olje())
|
|
_skriv(ut, "karusell-bidrag.tex", _bidrag(f))
|
|
_skriv(ut, "karusell-trapp.tex", _trapp_figur(trinnene))
|
|
_skriv(ut, "karusell-tidslinje.tex", _tidslinje_figur(aar))
|
|
_skriv(ut, "karusell-pris.tex", _pris_figur(les(data, TERSK)))
|
|
return tall
|