Answer architecture round 8: refuse a scoring run the plan does not call and a second entry on one read, keep a fall's scoring places apart for metric-bench, let the history format write the Ruling line, decide the fall step in a pure function, and state the base rule as the code holds it

This commit is contained in:
2026-10-09 12:29:37 +02:00
parent e694e4154e
commit 2630291af2
12 changed files with 160 additions and 111 deletions
+24 -14
View File
@@ -1,4 +1,5 @@
import dataclasses
import decimal
import re
import time
@@ -18,7 +19,8 @@ MID = "Mid A"
PLACE = re.compile(r"`([^`\s]*):\d+`(?: `(\w+)`)?")
RESTRUCTURE_FIRST = "would restructure first"
RULING = re.compile(r"^Ruling: (better|same|worse)$", re.M)
SEAT_PLACES = re.compile(rf"^.+, ({DECIDED_BY}|{HARDEST_FIRST}|{RESTRUCTURE_FIRST}):$")
RULED_PLACES = re.compile(rf"^.+, {DECIDED_BY}:$")
SCORED_PLACES = re.compile(rf"^.+, ({HARDEST_FIRST}|{RESTRUCTURE_FIRST}):$")
SENIOR = "Maintainability senior"
STAMP = "%Y-%m-%dT%H:%M:%SZ"
TITLE = "# Comprehension history\n"
@@ -39,13 +41,14 @@ 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."""
"""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."""
heading: str
time: str
commit: str
against: str | None
ruling: str | None
places: list[Place]
ruled_places: list[Place]
scored_places: list[Place]
@property
def paired(self) -> bool:
@@ -55,6 +58,7 @@ class Entry:
@dataclasses.dataclass(frozen=True)
class Heading:
title: str
label: str
commit: str
against: str | None
@@ -64,7 +68,7 @@ class Scoring:
"""The four scoring seats' lines, their scores as written and the means, in DIMENSIONS' order."""
seats: list[Seat]
scores: dict[str, list[str]]
means: list[str]
means: list[decimal.Decimal]
def entries(history: str) -> list[Entry]:
@@ -74,15 +78,21 @@ 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)))
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)))
return found
def seat_places(body: str) -> list[Place]:
def recorded(history: str, read: str) -> bool:
"""Whether the history holds an entry on what a seats file's first line says the seats read."""
return any(entry.heading.partition(", ")[2] == read for entry in entries(history))
def seat_places(body: str, labels: re.Pattern[str]) -> list[Place]:
"""The places under each seat label labels matches."""
places = []
listing = False
for line in body.splitlines():
if SEAT_PLACES.match(line):
if labels.match(line):
listing = True
elif listing and line.startswith("- "):
places += bullet_places(line)
@@ -106,7 +116,7 @@ def heading(at: float, read: str, paired: bool) -> Heading | Failure:
"""An entry's heading, matched by HEADING: when the seats finished, in UTC, and what they read."""
title = f"{time.strftime(STAMP, time.gmtime(at))}, {read}"
if (named := HEADING.match(title)) and bool(named.group(4)) == paired:
return Heading(title, named.group(3), named.group(4))
return Heading(title, named.group(2), named.group(3), named.group(4))
return Failure(f"the seats file's first line is not `<PR or branch> at <commit>{', against <base>' if paired else ''}`: {read}")
@@ -116,12 +126,12 @@ def appended(history: str, entry: str) -> str:
return f"{text}\n{entry}"
def ruling_entry(title: str, seats: list[Seat], said: dict[str, list[str]], counted: dict[str, list[str]], lines: list[str], scoring: Scoring | None) -> str:
"""A paired ruling's entry, with the scoring run that decided a fall; a seat's vote that counted as same for want of a place says so."""
def ruling_entry(title: str, seats: list[Seat], said: dict[str, list[str]], counted: dict[str, list[str]], ruled: str, notes: list[str], scoring: Scoring | None) -> str:
"""A paired ruling's entry, with any notes, such as why a fall decided it, and the scores that decided a fall; a seat's vote that counted as same for want of a place says so."""
votes = [[seat.name, *map(vote_text, DIMENSIONS, said[seat.name], counted[seat.name])] for seat in seats]
tables = [[["Seat", *DIMENSIONS], *votes]] + ([scores_table(scoring)] if scoring else [])
labels = [(f"{seat.name}, {DECIDED_BY}:", seat.places) for seat in seats] + (scoring_labels(scoring.seats) if scoring else [])
return entry_text(title, lines, tables, labels)
return entry_text(title, [f"Ruling: {ruled}", *notes], tables, labels)
def vote_text(dimension: str, said: str, counted: str) -> str:
@@ -130,12 +140,12 @@ def vote_text(dimension: str, said: str, counted: str) -> str:
return f"same (voted {said}, naming no place)" if dimension == DIMENSIONS[-1] else f"same (voted {said}, no place naming {dimension})"
def scoring_entry(title: str, lines: list[str], scoring: Scoring) -> str:
return entry_text(title, lines, [scores_table(scoring)], scoring_labels(scoring.seats))
def scoring_entry(title: str, scoring: Scoring) -> str:
return entry_text(title, [], [scores_table(scoring)], scoring_labels(scoring.seats))
def scores_table(scoring: Scoring) -> list[list[str]]:
return [["Seat", *DIMENSIONS], *([seat, *values] for seat, values in scoring.scores.items()), [MEAN, *scoring.means]]
return [["Seat", *DIMENSIONS], *([seat, *values] for seat, values in scoring.scores.items()), [MEAN, *map(str, scoring.means)]]
def scoring_labels(seats: list[Seat]) -> list[tuple[str, list[str]]]: