Answer architecture round 2: keep the judge's rules beside its verdicts, name record_ruling's steps, file HistoryChange with the history, give read_utf8 its own module, count a mis-cased round title, and repair the tracked_places docstring
This commit is contained in:
@@ -2,8 +2,7 @@ import re
|
||||
import subprocess
|
||||
|
||||
from failure import Failure
|
||||
from comprehension_history import HISTORY
|
||||
from larv_review.ruling_base import HistoryChange
|
||||
from comprehension_history import HISTORY, HistoryChange
|
||||
|
||||
|
||||
def git(*args: str) -> str | Failure:
|
||||
|
||||
+29
-28
@@ -20,7 +20,7 @@ one change against its first parent. With none, the base is the one the history'
|
||||
ruling names; with no ruling either, it is the merge base of HEAD and the default branch.
|
||||
|
||||
round-count prints each pass's count: the highest <n> among the titles opening `Answer <pass> round
|
||||
<n>:` of commits the default branch does not hold. It marks each pass at the cap of {cap} rounds,
|
||||
<n>:`, in any case, of commits the default branch does not hold. It marks each pass at the cap of {cap} rounds,
|
||||
and each name in such a title that is not a pass. It only reports: larv-review asks the human in
|
||||
place of a further round.
|
||||
|
||||
@@ -90,7 +90,7 @@ from comprehension_history import appended, DIMENSIONS, heading, Heading, HISTOR
|
||||
from larv_review.ruling_base import base
|
||||
from larv_review.rounds import CAP, PASSES, round_counts
|
||||
from larv_review.git import commit_exists, default_branch, file_at, git, history_changes, landed_since_release, top
|
||||
from larv_review.ruling import counted, fallen, ruling, split, votes
|
||||
from larv_review.ruling import counted, fallen, overall, ruling, split, votes
|
||||
from failure import Failure
|
||||
from larv_review.scoring import fall_ruling, FLOOR, means, under_floor
|
||||
from todo_table import items, ITEMS_HEADER
|
||||
@@ -107,7 +107,7 @@ def main(argv: list[str]) -> int:
|
||||
return 0
|
||||
command, *given = argv or [""]
|
||||
if command == "ruling-base" and not given:
|
||||
done = with_default_branch(ruling_base, stale_ok=False)
|
||||
done = with_default_branch(show_ruling_base, stale_ok=False)
|
||||
elif command == "round-count" and not given:
|
||||
done = with_default_branch(round_count, stale_ok=True)
|
||||
elif command == "needs-scoring-run" and all(re.fullmatch(r"[0-9]+", id_) for id_ in given):
|
||||
@@ -142,7 +142,7 @@ def with_default_branch(command: typing.Callable[[str], Failure | None], stale_o
|
||||
return command(branch)
|
||||
|
||||
|
||||
def ruling_base(default: str) -> Failure | None:
|
||||
def show_ruling_base(default: str) -> Failure | None:
|
||||
changes = history_changes(default)
|
||||
if isinstance(changes, Failure):
|
||||
return changes
|
||||
@@ -205,34 +205,35 @@ def record_ruling(votes_file: pathlib.Path, scores_file: pathlib.Path | None = N
|
||||
read = read_seats(votes_file, paired=True)
|
||||
if isinstance(read, Failure):
|
||||
return read
|
||||
named, given = read
|
||||
said = votes(given.seats)
|
||||
if isinstance(said, Failure):
|
||||
return said
|
||||
count = counted(given.seats, said)
|
||||
tally = ", ".join(f"{seat.name} {vote_text(DIMENSIONS[-1], said[seat.name][-1], count[seat.name][-1])}" for seat in given.seats)
|
||||
overall = [each[-1] for each in count.values()]
|
||||
if split(overall):
|
||||
heading_read, seats_read = read
|
||||
written = votes(seats_read.seats)
|
||||
if isinstance(written, Failure):
|
||||
return written
|
||||
counts = counted(seats_read.seats, written)
|
||||
tally = ", ".join(f"{seat.name} {vote_text(DIMENSIONS[-1], overall(written[seat.name]), overall(counts[seat.name]))}" for seat in seats_read.seats)
|
||||
overall_votes = [overall(each) for each in counts.values()]
|
||||
if split(overall_votes):
|
||||
print(f"Split: {tally}. Launch the maintainability senior and Junior A together, add their lines to the votes file, and run this again.")
|
||||
return None
|
||||
ruled = ruling(overall)
|
||||
fell = fallen(count) if ruled != "worse" else []
|
||||
if fell and not scores_file:
|
||||
print(f"Fell: {', '.join(fell)}, in a {ruled} ruling. Launch the four scoring seats on {named.label} at {named.commit}, write their lines to a scores file, and run this again with both files.")
|
||||
ruled = ruling(overall_votes)
|
||||
fell = fallen(counts) if ruled != "worse" else []
|
||||
if not fell:
|
||||
if scores_file:
|
||||
return Failure(f"no dimension fell in this {ruled} ruling, so it takes no scores file")
|
||||
return recorded_ruling(heading_read, seats_read, written, counts, ruled, tally, [], None)
|
||||
if not scores_file:
|
||||
print(f"Fell: {', '.join(fell)}, in a {ruled} ruling. Launch the four scoring seats on {heading_read.label} at {heading_read.commit}, write their lines to a scores file, and run this again with both files.")
|
||||
return None
|
||||
if scores_file and not fell:
|
||||
return Failure(f"no dimension fell in this {ruled} ruling, so it takes no scores file")
|
||||
scoring = None
|
||||
notes = []
|
||||
if scores_file:
|
||||
scored = read_fall_scores(scores_file, named)
|
||||
if isinstance(scored, Failure):
|
||||
return scored
|
||||
scoring = scored
|
||||
ruled, why = fall_ruling(ruled, fell, scoring.means)
|
||||
notes = [why]
|
||||
scoring = read_fall_scores(scores_file, heading_read)
|
||||
if isinstance(scoring, Failure):
|
||||
return scoring
|
||||
ruled, why = fall_ruling(ruled, fell, scoring.means)
|
||||
return recorded_ruling(heading_read, seats_read, written, counts, ruled, tally, [why], scoring)
|
||||
|
||||
|
||||
def recorded_ruling(heading_read: Heading, seats_read: SeatsFile, written: dict[str, list[str]], counts: dict[str, list[str]], ruled: str, tally: str, notes: list[str], scoring: ScoringRun | None) -> Failure | None:
|
||||
print(f"Ruling: {ruled}. {' '.join(notes + [f'Overall votes as counted: {tally}.'])}")
|
||||
return append(given.read, ruling_entry(named.title, given.seats, said, count, ruled, notes, scoring))
|
||||
return append(seats_read.read, ruling_entry(heading_read.title, seats_read.seats, written, counts, ruled, notes, scoring))
|
||||
|
||||
|
||||
def record_scoring(default: str, scores_file: pathlib.Path, ids: list[int]) -> Failure | None:
|
||||
|
||||
@@ -2,13 +2,14 @@ import re
|
||||
|
||||
CAP = 3
|
||||
PASSES = ("architecture", "full scan", "security", "stability", "product-owner", "prose")
|
||||
ROUND = re.compile(r"^Answer (.+?) round ([0-9]+):")
|
||||
ROUND = re.compile(r"^Answer (.+?) round ([0-9]+):", re.IGNORECASE)
|
||||
|
||||
|
||||
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, and a title naming no known pass adds its name."""
|
||||
"""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. Case is ignored, so a mis-cased title still counts."""
|
||||
counts = dict.fromkeys(PASSES, 0)
|
||||
for title in titles:
|
||||
if named := ROUND.match(title):
|
||||
counts[named.group(1)] = max(counts.get(named.group(1), 0), int(named.group(2)))
|
||||
name = named.group(1).lower()
|
||||
counts[name] = max(counts.get(name, 0), int(named.group(2)))
|
||||
return counts
|
||||
|
||||
@@ -18,12 +18,17 @@ def votes(seats: list[Seat]) -> dict[str, list[str]] | Failure:
|
||||
if unnamed := [place for place in seat.places if not place_dimensions(place)]:
|
||||
return Failure(f"{seat.name}'s place does not open with the dimensions it moves, each one of {', '.join(DIMENSIONS)}, then `: `: {unnamed[0]}")
|
||||
said[seat.name] = line
|
||||
first, second, *more = (each[-1] for each in counted(seats, said).values())
|
||||
if more and first == second:
|
||||
first, second, *more = (overall(each) for each in counted(seats, said).values())
|
||||
if more and not split([first, second]):
|
||||
return Failure(f"{' and '.join(FIRST_SEATS)} both count as {first} overall, which settles the ruling; drop the other seats' lines")
|
||||
return said
|
||||
|
||||
|
||||
def overall(votes: list[str]) -> str:
|
||||
"""The overall vote, which DIMENSIONS lists last."""
|
||||
return votes[-1]
|
||||
|
||||
|
||||
def counted(seats: list[Seat], said: dict[str, list[str]]) -> dict[str, list[str]]:
|
||||
"""Each seat's votes as they count: a dimension's vote counts as same unless one of the seat's `path:line` places opens with that dimension, and the overall vote unless the seat names any such place."""
|
||||
return {seat.name: [vote if names_a_place(seat, name) else "same" for name, vote in zip(DIMENSIONS, said[seat.name])] for seat in seats}
|
||||
|
||||
@@ -1,14 +1,4 @@
|
||||
import dataclasses
|
||||
|
||||
from comprehension_history import entries, Entry
|
||||
|
||||
|
||||
@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
|
||||
from comprehension_history import entries, Entry, HistoryChange
|
||||
|
||||
|
||||
def measured_commit(changes: list[HistoryChange]) -> str | None:
|
||||
|
||||
@@ -9,8 +9,8 @@ import unittest
|
||||
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
||||
|
||||
from comprehension_history import appended, entries, Place, recorded, ruling_entry, ScoringRun, Seat
|
||||
from larv_review.ruling_base import base, first_ruling, HistoryChange, measured_commit
|
||||
from comprehension_history import appended, entries, HistoryChange, Place, recorded, ruling_entry, ScoringRun, Seat
|
||||
from larv_review.ruling_base import base, first_ruling, measured_commit
|
||||
from larv_review.ruling import counted, fallen, ruling, split, votes
|
||||
from failure import Failure
|
||||
from larv_review.scoring import fall_ruling, means, under_floor
|
||||
@@ -169,6 +169,9 @@ class Rounds(unittest.TestCase):
|
||||
counts = round_counts(["Answer prose round 1: x", "Answer full scan round 2: y", "Answer full scan round 1: z", "Answer stability: no round", "Answer stabilty round 1: typo", "Answer security round 1: rename round 2: x", "Rescore: w"])
|
||||
self.assertEqual((counts["prose"], counts["full scan"], counts["stability"], counts["architecture"], counts["stabilty"], counts["security"]), (1, 2, 0, 0, 1, 1))
|
||||
|
||||
def test_counts_a_mis_cased_title_under_its_pass(self):
|
||||
self.assertEqual(round_counts(["Answer Architecture round 4: x", "Answer architecture round 3: y"])["architecture"], 4)
|
||||
|
||||
|
||||
class ScoringRunDue(unittest.TestCase):
|
||||
def test_reads_each_rows_id_release_and_tagline(self):
|
||||
|
||||
Reference in New Issue
Block a user