Answer architecture round 5: return the heading as a dataclass, read the Mean line as its own field, mark an entry paired explicitly, move metric-bench's path resolution back to metric_bench, and split the scoring trigger into named steps

This commit is contained in:
2026-10-09 01:44:53 +02:00
parent efed78bf5e
commit c1133edf39
9 changed files with 143 additions and 92 deletions
+29 -15
View File
@@ -15,7 +15,7 @@ SENIOR = "Maintainability senior"
FIRST_SEATS = (MID, ARCHITECT)
SCORING_SEATS = (JUNIOR, MID, SENIOR, ARCHITECT)
SEAT_LINE = re.compile(rf"^({'|'.join((*SCORING_SEATS, MEAN))}): (.+)$")
SEAT_LINE = re.compile(rf"^({'|'.join(SCORING_SEATS)}): (.+)$")
SPLIT_SEATS = (SENIOR, JUNIOR)
@@ -28,9 +28,10 @@ class Seat:
@dataclasses.dataclass(frozen=True)
class Report:
"""A seats file: what the seats read, `<PR or branch> at <commit>`, with `, against <base>` for a paired ruling, then each seat's line and its places."""
"""A seats file: what the seats read, `<PR or branch> at <commit>`, with `, against <base>` for a paired ruling, then each seat's line and its places, or, for a run moved from a decision entry, its Mean line alone."""
read: str
seats: list[Seat]
moved_mean: str | None
def report(text: str) -> Report | Failure:
@@ -38,8 +39,13 @@ def report(text: str) -> Report | Failure:
if not lines:
return Failure("the seats file is empty; its first line names what the seats read: <PR or branch> at <commit>")
seats: list[Seat] = []
moved_mean = None
for line in lines[1:]:
if seat := SEAT_LINE.match(line):
if line.startswith(f"{MEAN}: ") and not seats and moved_mean is None:
moved_mean = line[len(MEAN) + 2:].strip()
elif moved_mean is not None:
return Failure(f"a {MEAN} line stands alone in its seats file: {line}")
elif seat := SEAT_LINE.match(line):
if seat.group(1) in [known.name for known in seats]:
return Failure(f"{seat.group(1)} appears twice in the seats file")
seats.append(Seat(seat.group(1), seat.group(2).strip(), []))
@@ -48,22 +54,30 @@ def report(text: str) -> Report | Failure:
elif seats and seats[-1].places and line.startswith(" "):
seats[-1].places[-1] += " " + line.strip()
else:
return Failure(f"the seats file has a line that is neither a seat's line, opening with one of {', '.join((*SCORING_SEATS, MEAN))} and a colon, nor one of its places: {line}")
return Report(lines[0].strip(), seats)
return Failure(f"the seats file has a line that is neither a seat's line, opening with one of {', '.join(SCORING_SEATS)} and a colon, nor one of its places: {line}")
return Report(lines[0].strip(), seats, moved_mean)
def scores(seats: list[Seat]) -> dict[str, list[str]] | Failure:
"""Each seat's five scores as written, in DIMENSIONS' order: the four seats', or the Mean line's alone."""
if [seat.name for seat in seats] not in (list(SCORING_SEATS), [MEAN]):
"""Each seat's five scores as written, in DIMENSIONS' order."""
if [seat.name for seat in seats] != list(SCORING_SEATS):
return Failure(f"a scoring run's seats are {', '.join(SCORING_SEATS)}, in that order, or a {MEAN} line alone; the file has {', '.join(seat.name for seat in seats) or 'none'}")
found = {}
for seat in seats:
if not (written := SCORES.fullmatch(seat.said)):
return Failure(f"{seat.name}'s line is not {', '.join(name + ' <score>' for name in DIMENSIONS)}: {seat.said}")
values = [decimal.Decimal(value) for value in written.groups()]
if not all(1 <= value <= 10 for value in values):
return Failure(f"{seat.name}'s scores are not each from 1 to 10: {seat.said}")
if values[-1] > min(values[:-1]) + 1:
return Failure(f"{seat.name}'s overall exceeds their lowest dimension by more than 1; ask the seat to rescore: {seat.said}")
found[seat.name] = list(written.groups())
values = score_line(seat.name, seat.said)
if isinstance(values, Failure):
return values
found[seat.name] = values
return found
def score_line(name: str, said: str) -> list[str] | Failure:
"""A line's five scores as written, each from 1 to 10 and the overall at most 1 above the lowest dimension."""
if not (written := SCORES.fullmatch(said)):
return Failure(f"{name}'s line is not {', '.join(score + ' <score>' for score in DIMENSIONS)}: {said}")
values = [decimal.Decimal(value) for value in written.groups()]
if not all(1 <= value <= 10 for value in values):
return Failure(f"{name}'s scores are not each from 1 to 10: {said}")
if values[-1] > min(values[:-1]) + 1:
return Failure(f"{name}'s overall exceeds the lowest dimension by more than 1; ask the seat to rescore: {said}")
return list(written.groups())