Answer principles round 1: 0 🔴, 9 🟡; drop a route handed under R + C, validate Route, rank old tables without C, settle item 166, file items 170 and 171
This commit is contained in:
+32
-19
@@ -1,6 +1,7 @@
|
||||
"""A chunk's route: its worker's rung and the plan item that picked it, in the words the archive records each verdict's worker in."""
|
||||
import dataclasses
|
||||
import re
|
||||
import typing
|
||||
|
||||
from todo_table import LEVELS
|
||||
from model_routing.ladder import Rung
|
||||
@@ -12,42 +13,54 @@ ROUTED = re.compile(r"(?P<rung>.+?)(?:, routed by item (?P<item>[0-9]+)'s (?P<le
|
||||
LEVELS_ROUTED = re.compile(r"L of (?P<likelihood>[0-9]+) and E \+ I of (?P<escape_and_impact>[0-9]+)")
|
||||
|
||||
|
||||
class ArchivedWorker(typing.NamedTuple):
|
||||
"""What an archived worker line names, whatever its route says: the worker's rung, and whether an item routed it."""
|
||||
rung: Rung
|
||||
routed: bool
|
||||
|
||||
|
||||
def on_their_scales(likelihood: int, escape_and_impact: int) -> bool:
|
||||
"""Whether L and E + I are levels on the scales todo_table.LEVELS gives; E and I each start at 1."""
|
||||
return 1 <= likelihood <= LEVELS["L"] and 2 <= escape_and_impact <= LEVELS["E"] + LEVELS["I"]
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class Route:
|
||||
"""A chunk's worker rung, and the plan item that picked it, 0 for none, with its L, which picked the worker's rung, and its E + I, which picks its reviewers'.
|
||||
"""A chunk's worker rung, and the plan item that picked it, 0 for none, with its L, which picked the worker's rung, and its E + I, which picks its reviewers'. A route with an item holds levels on their scales, and one without holds none, so no rung is picked from a level off its scale.
|
||||
|
||||
unfinished counts the unfinished verdicts towards the next one-rung step; a reload hands it over with the rung.
|
||||
"""
|
||||
# The fields a loop-claude from before L and E + I replaced R + C hands on reload; the reloaded script drops such a route, and the chunk routes afresh.
|
||||
RETIRED: typing.ClassVar[frozenset[str]] = frozenset({"risk_and_complexity"})
|
||||
rung: Rung
|
||||
item: int = 0
|
||||
likelihood: int = 0
|
||||
escape_and_impact: int = 0
|
||||
unfinished: int = 0
|
||||
|
||||
def __post_init__(self) -> None:
|
||||
if (self.item and not on_their_scales(self.likelihood, self.escape_and_impact)) or (not self.item and (self.likelihood or self.escape_and_impact)):
|
||||
raise ValueError(f"a route by item {self.item} cannot hold an L of {self.likelihood} and an E + I of {self.escape_and_impact}")
|
||||
|
||||
def __str__(self) -> str:
|
||||
"""What the archive records as each verdict's worker; ROUTED reads it back."""
|
||||
return f"{self.rung}, routed by item {self.item}'s L of {self.likelihood} and E + I of {self.escape_and_impact}" if self.item else str(self.rung)
|
||||
|
||||
|
||||
def archived_worker(worker: str) -> ArchivedWorker | None:
|
||||
"""What an archived worker line names; None for a model run off the ladder."""
|
||||
found = ROUTED.fullmatch(worker)
|
||||
rung = Rung.parse(found["rung"]) if found else None
|
||||
return ArchivedWorker(rung, bool(found["item"])) if found and rung else None
|
||||
|
||||
|
||||
def route_from(worker: str) -> Route | None:
|
||||
"""The route an archived worker line names; None for a model run off the ladder, or a route by anything but levels on their scales."""
|
||||
found = ROUTED.fullmatch(worker)
|
||||
rung = Rung.parse(found["rung"]) if found else None
|
||||
if not found or not rung:
|
||||
return None
|
||||
if not found["item"]:
|
||||
return Route(rung)
|
||||
archived = archived_worker(worker)
|
||||
if archived is None or not archived.routed:
|
||||
return Route(archived.rung) if archived else None
|
||||
found = typing.cast(re.Match[str], ROUTED.fullmatch(worker))
|
||||
levels = LEVELS_ROUTED.fullmatch(found["levels"])
|
||||
if not levels:
|
||||
if not levels or not on_their_scales(int(levels["likelihood"]), int(levels["escape_and_impact"])):
|
||||
return None
|
||||
likelihood, escape_and_impact = int(levels["likelihood"]), int(levels["escape_and_impact"])
|
||||
if not 1 <= likelihood <= LEVELS["L"] or not 2 <= escape_and_impact <= LEVELS["E"] + LEVELS["I"]:
|
||||
return None
|
||||
return Route(rung, int(found["item"]), likelihood, escape_and_impact)
|
||||
|
||||
|
||||
def archived_rung(worker: str) -> tuple[Rung, bool] | None:
|
||||
"""The rung an archived worker line names, and whether an item routed it, whatever the route names after the rung; None for a model run off the ladder."""
|
||||
found = ROUTED.fullmatch(worker)
|
||||
rung = Rung.parse(found["rung"]) if found else None
|
||||
return (rung, bool(found["item"])) if found and rung else None
|
||||
return Route(archived.rung, int(found["item"]), int(levels["likelihood"]), int(levels["escape_and_impact"]))
|
||||
|
||||
Reference in New Issue
Block a user