Keep the history's writer beside its reader, read plan rows with rank_todo, and fetch only for commands that read the default branch

This commit is contained in:
2026-10-09 01:10:01 +02:00
parent 77fef49fce
commit 53ed5150be
8 changed files with 189 additions and 162 deletions
+43 -23
View File
@@ -2,15 +2,18 @@ import dataclasses
import decimal
import re
from rank_todo import cells, ITEMS_HEADER, table_rows
from larv_review.seats import DIMENSIONS
from larv_review.history import entries, Entry
from larv_review.seats import DIMENSIONS, Seat
from larv_review.history import entries, Entry, PLACE
from failure import Failure
from rank_todo import Item, ITEMS_HEADER, parse_row, table_rows
CAP = 3
FIRST_SEATS = ("Mid A", "Inherited architect")
FLOOR = decimal.Decimal("7.0")
PASSES = ("architecture", "full scan", "security", "stability", "product-owner", "prose")
ROUND = re.compile(r"^Answer (.+) round ([0-9]+):")
SPLIT_SEATS = ("Maintainability senior", "Junior A")
VOTES = ("better", "same", "worse")
@dataclasses.dataclass(frozen=True)
@@ -21,24 +24,45 @@ class HistoryChange:
after: str
@dataclasses.dataclass(frozen=True)
class PlanItem:
id: int
release: tuple[int, int, int]
tagline: str
def votes(seats: list[Seat]) -> dict[str, str] | Failure:
"""Each seat's vote as it counts: a better or worse vote naming no `path:line` place counts as same."""
names = [seat.name for seat in seats]
if names[:2] != list(FIRST_SEATS) or names[2:] not in ([], list(SPLIT_SEATS)):
return Failure(f"a paired ruling's seats are {' and '.join(FIRST_SEATS)}, then, when their votes differ, {' and '.join(SPLIT_SEATS)}, in that order; the file has {', '.join(names) or 'none'}")
if unknown := [seat for seat in seats if seat.said not in VOTES]:
return Failure(f"{unknown[0].name}'s vote {unknown[0].said!r} is not better, same or worse")
return {seat.name: seat.said if names_a_place(seat) else "same" for seat in seats}
def names_a_place(seat: Seat) -> bool:
return any(PLACE.search(place) for place in seat.places)
def ruling(counted: list[str]) -> str | None:
"""The vote that leads each other vote by two or more, else same; None when only the first two seats voted and they differ, so two more must vote."""
if len(counted) == 2 and counted[0] != counted[1]:
return None
for vote in VOTES:
if all(counted.count(vote) >= counted.count(other) + 2 for other in VOTES if other != vote):
return vote
return "same"
def means(scores: dict[str, list[str]]) -> list[decimal.Decimal]:
"""The seats' mean of each score, in DIMENSIONS' order, rounded half up to two decimals."""
return [(sum((decimal.Decimal(seat[index]) for seat in scores.values()), decimal.Decimal(0)) / len(scores)).quantize(decimal.Decimal("0.01"), decimal.ROUND_HALF_UP) for index in range(len(DIMENSIONS))]
"""The seats' mean of each score, in the order each seat's scores are, rounded half up to two decimals."""
return [mean([decimal.Decimal(score) for score in column]) for column in zip(*scores.values())]
def mean(values: list[decimal.Decimal]) -> decimal.Decimal:
return (sum(values, decimal.Decimal(0)) / len(values)).quantize(decimal.Decimal("0.01"), decimal.ROUND_HALF_UP)
def under_floor(found: list[decimal.Decimal]) -> list[str]:
return [f"{name} {mean}" for name, mean in zip(DIMENSIONS, found) if mean < FLOOR]
return [f"{name} {value}" for name, value in zip(DIMENSIONS, found) if value < FLOOR]
def round_counts(titles: list[str]) -> dict[str, int]:
"""Each pass's highest round among the branch's `Answer <pass> round <n>:` commit titles; a pass with none has 0."""
"""Each pass's highest round among the branch's `Answer <pass> round <n>:` commit titles; a pass with none has 0, and a title naming no known pass adds its name."""
counts = dict.fromkeys(PASSES, 0)
for title in titles:
if named := ROUND.match(title):
@@ -62,8 +86,8 @@ def first_ruling(history: str) -> Entry | None:
return rulings[0] if rulings else None
def plan_items(todo: str) -> list[PlanItem] | Failure:
"""The ID, release and tagline of each row in a todo.md's items table, in the shape `rank_todo.py --help` shows; a plan with no table has no items."""
def plan_items(todo: str) -> list[Item] | Failure:
"""Each row of a todo.md's items table, read as `rank_todo.py` reads it; a plan with no table has no items."""
lines = todo.splitlines()
if ITEMS_HEADER not in lines:
return []
@@ -72,18 +96,14 @@ def plan_items(todo: str) -> list[PlanItem] | Failure:
return table
items = []
for row in table.rows:
found = cells(row, 10)
if isinstance(found, Failure):
return found
id_, release, _, tagline, *_ = found
if not re.fullmatch(r"[0-9]+", id_) or not re.fullmatch(r"[0-9]+\.[0-9]+\.[0-9]+", release):
return Failure(f"a todo.md row has no whole-number ID or no semver release: {row}")
major, minor, patch = (int(part) for part in release.split("."))
items.append(PlanItem(int(id_), (major, minor, patch), tagline))
item = parse_row(row)
if isinstance(item, Failure):
return item
items.append(item)
return items
def scoring_run_due(before: list[PlanItem], after: list[PlanItem], ships: list[int], landed: bool) -> list[str]:
def scoring_run_due(before: list[Item], after: list[Item], ships: list[int], landed: bool) -> list[str]:
"""Why the chunk takes a scoring run, empty when it does not. before is the default branch's plan, after the chunk's, ships the IDs it ships, and landed whether the default branch holds a commit after the newest release tag. A release has work landed towards it when the chunk ships one of its items, or when it is the earliest release before names and landed holds."""
plan = {item.id: item for item in before + after}
shipped = [plan[id_] for id_ in ships]