Answer architecture round 1: 1 🔴, 6 🟡; feed later rulings' worse places to places, base each ruling on the last entry, merge origin before the gate, test a second record, and drop stale ratchet wording

This commit is contained in:
2026-10-13 12:28:18 +02:00
parent 459df0a7cc
commit 79cf337936
13 changed files with 131 additions and 108 deletions
+46 -14
View File
@@ -40,7 +40,7 @@ class Place:
@dataclasses.dataclass(frozen=True)
class Entry:
"""One paired ruling, which names the commit it was against and its ruling, or one scoring run, which names neither. A scoring run's places, or those of the scores a fall called into a ruling, are scored_places."""
"""One paired ruling, which names the commit it was against and its ruling, or one scoring run, which names neither. The places under a scoring seat's label are scored_places; a ruling holds them where the scoring seats' scores are part of it."""
heading: str
time: str
commit: str
@@ -48,6 +48,7 @@ class Entry:
ruling: str | None
ruled_places: list[Place]
scored_places: list[Place]
body: str
@property
def paired(self) -> bool:
@@ -98,19 +99,42 @@ def entries(history: str) -> list[Entry]:
if named := HEADING.match(heading):
body = "\n".join(bodies)
ruling = RULING.search(body)
found.append(Entry(heading, named.group(1), named.group(3), named.group(4), ruling.group(1) if ruling else None, seat_places(body, RULED_PLACES), seat_places(body, SCORED_PLACES)))
found.append(Entry(heading, named.group(1), named.group(3), named.group(4), ruling.group(1) if ruling else None, seat_places(body, RULED_PLACES), seat_places(body, SCORED_PLACES), body))
return found
def latest_places(history: str) -> str | None:
"""The heading and the seats' places of the newest entry, by its time, whose seats scored the project: a scoring run, or a ruling whose fall called the scoring seats. None when no entry did."""
scored = [(named.group(1), heading, "\n".join(bodies)) for heading, bodies in sections(history).items() if (named := HEADING.match(heading)) and seat_places("\n".join(bodies), SCORED_PLACES)]
if not scored:
return None
_, heading, body = max(scored)
lines = body.splitlines()
start = next(index for index, line in enumerate(lines) if SCORED_PLACES.match(line))
return f"## {heading}\n" + "".join(f"\n{line}\n\n" if SCORED_PLACES.match(line) else f"{line}\n" for line in lines[start:])
"""The places seats found hard since the newest entry, by time, that holds scoring seats' places: all of that entry's scoring places, then, in each later paired ruling, each place opening with a dimension its seat's vote counted as worse. Each entry's places come under its heading, oldest first; with no such entry, every ruling's count. None when no place counts."""
found = sorted(entries(history), key=lambda entry: entry.time)
start = max((index for index, entry in enumerate(found) if entry.scored_places), default=0)
parts = [entry_places(entry, scored=index == start and bool(entry.scored_places)) for index, entry in enumerate(found) if index >= start]
return "\n".join(part for part in parts if part) or None
def entry_places(entry: Entry, scored: bool) -> str:
"""An entry's heading and the places latest_places counts in it, each under its seat's label; empty when none counts."""
worse = {} if scored else worse_votes(entry.body)
labelled = labelled_bullets(entry.body, SCORED_PLACES if scored else RULED_PLACES)
kept = [(label, bullets if scored else [bullet for bullet in bullets if moves_worse(bullet, worse.get(label.split(",")[0], set()))]) for label, bullets in labelled]
text = "".join(f"\n{label}\n\n" + "".join(f"{bullet}\n" for bullet in bullets) for label, bullets in kept if bullets)
return f"## {entry.heading}\n{text}" if text else ""
def worse_votes(body: str) -> dict[str, set[str]]:
"""Each seat's dimensions, Overall included, whose vote in the ruling's table counted as worse; `same (voted worse, …)` counted as same."""
rows = [[cell.strip() for cell in line.strip("|").split("|")] for line in body.splitlines() if line.startswith("| ")]
return {name: {dimension for dimension, vote in zip(DIMENSIONS, votes) if vote == "worse"} for name, *votes in rows if len(votes) == len(DIMENSIONS)}
def moves_worse(bullet: str, worse: set[str]) -> bool:
"""Whether a ruled place opens with a dimension its seat counted worse; Overall counts as one."""
return bool(worse & set(place_dimensions(bullet.removeprefix("- "))))
def place_dimensions(place: str) -> list[str]:
"""The dimensions a place opens with, as in `Locality, Shape: `path:line` ...`; empty when any name before the first `: ` is no dimension."""
named = place.partition(": ")[0].split(", ")
return named if all(name in DIMENSIONS for name in named) else []
def recorded(history: str, read: str) -> bool:
@@ -119,17 +143,25 @@ def recorded(history: str, read: str) -> bool:
def seat_places(body: str, labels: re.Pattern[str]) -> list[Place]:
"""The places under each seat label labels matches."""
places = []
"""The places on the first line of each bullet under a seat label labels matches."""
return [place for _, bullets in labelled_bullets(body, labels) for bullet in bullets for place in bullet_places(bullet.splitlines()[0])]
def labelled_bullets(body: str, labels: re.Pattern[str]) -> list[tuple[str, list[str]]]:
"""Each seat label labels matches, with its bullets, each with its indented continuation lines."""
found: list[tuple[str, list[str]]] = []
listing = False
for line in body.splitlines():
if labels.match(line):
found.append((line, []))
listing = True
elif listing and line.startswith("- "):
places += bullet_places(line)
found[-1][1].append(line)
elif listing and line.startswith(" ") and found[-1][1]:
found[-1][1][-1] += f"\n{line}"
elif not line.startswith(" "):
listing = False
return places
return found
def bullet_places(bullet: str) -> list[Place]: