Answer architecture round 2: 0 🔴, 2 🟡; date the Entry docstring's legacy case, test wrapped and empty places, split places into scoring and worse, and recheck origin before the ruling
This commit is contained in:
@@ -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. The places under a scoring seat's label are scored_places; a ruling holds them where the scoring seats' scores are part of it."""
|
||||
"""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 recorded before 2026-10-13 holds them too where a fallen dimension called the scoring seats."""
|
||||
heading: str
|
||||
time: str
|
||||
commit: str
|
||||
@@ -106,17 +106,21 @@ def entries(history: str) -> list[Entry]:
|
||||
def latest_places(history: str) -> str | None:
|
||||
"""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]
|
||||
newest = max((index for index, entry in enumerate(found) if entry.scored_places), default=None)
|
||||
first = [placed(found[newest], labelled_bullets(found[newest].body, SCORED_PLACES))] if newest is not None else []
|
||||
parts = first + [placed(entry, worse_places(entry)) for entry in (found if newest is None else found[newest + 1:])]
|
||||
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)
|
||||
def worse_places(entry: Entry) -> list[tuple[str, list[str]]]:
|
||||
"""Under each of a ruling's seat labels, the bullets that open with a dimension that seat's vote counted as worse; Overall counts as one."""
|
||||
worse = worse_votes(entry.body)
|
||||
return [(label, [bullet for bullet in bullets if worse.get(label.split(",")[0], set()) & set(place_dimensions(bullet.removeprefix("- ")))]) for label, bullets in labelled_bullets(entry.body, RULED_PLACES)]
|
||||
|
||||
|
||||
def placed(entry: Entry, labelled: list[tuple[str, list[str]]]) -> str:
|
||||
"""The entry's heading, then each label with bullets and its bullets; empty when no label has any."""
|
||||
text = "".join(f"\n{label}\n\n" + "".join(f"{bullet}\n" for bullet in bullets) for label, bullets in labelled if bullets)
|
||||
return f"## {entry.heading}\n{text}" if text else ""
|
||||
|
||||
|
||||
@@ -126,11 +130,6 @@ def worse_votes(body: str) -> dict[str, set[str]]:
|
||||
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(", ")
|
||||
|
||||
Reference in New Issue
Block a user