Section 8.4 of chapter 8 holds the four analyses made after the results (expected net present value, half the construction time for small units with the free choice of unit size, no displacement in the grid queue, net present value by term), outside the verdicts, each with its reservation and a list of what is not checked. Every number is a tillegg. key from the new module rapport/resultater/tillegg.py, which reads data/tillegg/ and stops the build if the files do not agree with the main run's. Section 8.3 now lists ten calculations not done, the row in appendix C says the analyses are done, one sentence in chapter 10 and one in each of three files of chapter 6 point to the section, and the README names the analyses and the commands that made them. The report is 177 pages and is copied to pdf/. The operator approved the wording 2026-11-24. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
97 lines
3.6 KiB
Python
97 lines
3.6 KiB
Python
# ruff: noqa: INP001
|
|
r"""Write what chapter 6 of the report reads: numbers, tables and figure data from the result files.
|
|
|
|
Reads the eight files in ``data/resultater/`` (and, for the module ``tillegg``, the additional
|
|
analyses in ``data/tillegg/``) and writes to ``rapport/generert/``. Each module in
|
|
``rapport/resultater/`` has ``lag(data: Path, ut: Path) -> dict[str, Tall]``: it writes its own
|
|
tables (``.tex``) and figure data (``.dat``) to ``ut`` and returns every number it shows, under
|
|
keys that start with the module's name and a full stop. This script collects them and writes
|
|
``tall.tex`` (``\tall{key}`` in the prose) and ``tall.json`` (key, shown string, file, path, raw
|
|
value: the list a reader checks against the files).
|
|
|
|
Standard library only. Same result files, same bytes. Run from anywhere:
|
|
``python3 rapport/lag_resultater.py`` (all modules) or ``python3 rapport/lag_resultater.py
|
|
--bare dommer`` (one module, while it is being written; then ``tall-dommer.tex`` and
|
|
``tall-dommer.json`` are written instead).
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import importlib
|
|
import json
|
|
import re
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
HER = Path(__file__).resolve().parent
|
|
ROT = HER.parent
|
|
DATA = ROT / "data" / "resultater"
|
|
UT = HER / "generert"
|
|
|
|
MODULER = (
|
|
"dommer",
|
|
"tidslinje",
|
|
"miljo",
|
|
"eierformer",
|
|
"terskler",
|
|
"folsomheter",
|
|
"karusell",
|
|
"tillegg",
|
|
)
|
|
NOKKEL = re.compile(r"^[a-z0-9]+(?:[.-][A-Za-z0-9]+)*$")
|
|
|
|
|
|
def main(argv: list[str]) -> int:
|
|
"""Run the modules and write the two lists of numbers."""
|
|
sys.path.insert(0, str(HER))
|
|
from resultater.felles import OMREGNINGER, Tall # noqa: PLC0415
|
|
|
|
moduler = MODULER
|
|
endelse = ""
|
|
if len(argv) == 2 and argv[0] == "--bare" and argv[1] in MODULER: # noqa: PLR2004
|
|
moduler = (argv[1],)
|
|
endelse = "-" + argv[1]
|
|
elif argv:
|
|
sys.stderr.write(f"bruk: lag_resultater.py [--bare {'|'.join(MODULER)}]\n")
|
|
return 2
|
|
UT.mkdir(exist_ok=True)
|
|
alle: dict[str, Tall] = {}
|
|
for navn in moduler:
|
|
modul = importlib.import_module(f"resultater.{navn}")
|
|
for nokkel, tall in modul.lag(DATA, UT).items():
|
|
if not nokkel.startswith(navn + ".") or not NOKKEL.match(nokkel):
|
|
sys.stderr.write(f"FEIL: ugyldig nokkel {nokkel!r} fra {navn}\n")
|
|
return 1
|
|
if nokkel in alle:
|
|
sys.stderr.write(f"FEIL: nokkelen {nokkel!r} finnes to ganger\n")
|
|
return 1
|
|
if tall.omregning not in OMREGNINGER or (tall.omregning == "avledet") != (not tall.sti):
|
|
sys.stderr.write(f"FEIL: {nokkel!r} har ugyldig omregning eller sti\n")
|
|
return 1
|
|
alle[nokkel] = tall
|
|
linjer = [
|
|
f"\\expandafter\\def\\csname tall@{nokkel}\\endcsname{{{tall.vist}}}%"
|
|
for nokkel, tall in sorted(alle.items())
|
|
]
|
|
(UT / f"tall{endelse}.tex").write_text("\n".join(linjer) + "\n", encoding="utf-8")
|
|
liste = {
|
|
nokkel: {
|
|
"vist": tall.vist,
|
|
"fil": tall.fil,
|
|
"sti": [list(s) if isinstance(s, tuple) else s for s in tall.sti],
|
|
"raa": tall.raa,
|
|
"omregning": tall.omregning,
|
|
"desimaler": tall.desimaler,
|
|
"forklaring": tall.forklaring,
|
|
}
|
|
for nokkel, tall in sorted(alle.items())
|
|
}
|
|
(UT / f"tall{endelse}.json").write_text(
|
|
json.dumps(liste, ensure_ascii=False, indent=1) + "\n", encoding="utf-8"
|
|
)
|
|
sys.stdout.write(f"OK: {len(alle)} tall fra {', '.join(moduler)} skrevet til {UT}\n")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main(sys.argv[1:]))
|