Answer architecture round 1: move the base fallback, heading check and seat names into the pure modules, move legacy scores through record-scoring, and read origin as last fetched when a fetch fails
This commit is contained in:
@@ -3,17 +3,19 @@ import os
|
||||
import re
|
||||
import time
|
||||
|
||||
from larv_review.seats import DIMENSIONS, Seat
|
||||
from larv_review.seats import ARCHITECT, DIMENSIONS, MEAN, Seat
|
||||
from failure import Failure
|
||||
from markdown_sections import sections
|
||||
|
||||
DATED = re.compile(r"^[0-9]{4}-[0-9]{2}-[0-9]{2}[^,]*, ")
|
||||
DECIDED_BY = "decided by"
|
||||
HARDEST_FIRST = "hardest first"
|
||||
WOULD_RESTRUCTURE_FIRST = "would restructure first"
|
||||
HEADING = re.compile(r"^([^,]+), (.+) at ([0-9a-f]{7,40})(?:, against ([0-9a-f]{7,40}))?$")
|
||||
RULING = re.compile(r"^Ruling: (better|same|worse)$", re.M)
|
||||
SEAT_PLACES = re.compile(rf"^.+, ({DECIDED_BY}|{HARDEST_FIRST}|{WOULD_RESTRUCTURE_FIRST}):$")
|
||||
# `path:line` or `:line`, then the unit's name where one follows.
|
||||
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}):$")
|
||||
STAMP = "%Y-%m-%dT%H:%M:%SZ"
|
||||
TITLE = "# Comprehension history\n"
|
||||
|
||||
@@ -35,6 +37,14 @@ class Entry:
|
||||
places: list[Place]
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class HistoryChange:
|
||||
"""A merged change on the default branch that touched the history, and the history before and after it."""
|
||||
commit: str
|
||||
before: str
|
||||
after: str
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class ScoringRun:
|
||||
heading: str
|
||||
@@ -98,9 +108,12 @@ def resolved(places: list[Place], tracked: list[str]) -> tuple[list[Place], list
|
||||
return found, dropped
|
||||
|
||||
|
||||
def heading(at: float, read: str) -> str:
|
||||
"""An entry's heading: when the seats finished, in UTC, and what they read."""
|
||||
return f"{time.strftime(STAMP, time.gmtime(at))}, {read}"
|
||||
def heading(at: float, read: str, paired: bool) -> re.Match[str] | Failure:
|
||||
"""An entry's heading, matched by HEADING: when the seats finished, in UTC, and what they read; a read that opens with its own date, as a run moved from a decision entry does, keeps it."""
|
||||
title = read if DATED.match(read) else f"{time.strftime(STAMP, time.gmtime(at))}, {read}"
|
||||
if (named := HEADING.match(title)) and bool(named.group(4)) == paired:
|
||||
return named
|
||||
return Failure(f"the seats file's first line is not `<PR or branch> at <commit>{', against <base>' if paired else ''}`: {read}")
|
||||
|
||||
|
||||
def appended(history: str, entry: str) -> str:
|
||||
@@ -116,8 +129,8 @@ def ruling_entry(title: str, seats: list[Seat], counted: dict[str, str], ruled:
|
||||
|
||||
|
||||
def scoring_entry(title: str, seats: list[Seat], scores: dict[str, list[str]], means: list[str]) -> str:
|
||||
rows = [[seat, *values] for seat, values in scores.items()] + [["Mean", *means]]
|
||||
labels = [(f"{seat.name}, {WOULD_RESTRUCTURE_FIRST if seat.name == 'Inherited architect' else HARDEST_FIRST}:", seat.places) for seat in seats]
|
||||
rows = [[seat, *values] for seat, values in scores.items() if seat != MEAN] + [[MEAN, *means]]
|
||||
labels = [(f"{seat.name}, {RESTRUCTURE_FIRST if seat.name == ARCHITECT else HARDEST_FIRST}:", seat.places) for seat in seats if seat.name != MEAN]
|
||||
return entry_text(title, [], [["Seat", *DIMENSIONS], *rows], labels)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user