Count how often seats agree in a paired ruling and across scoring runs
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
import decimal
|
||||
import itertools
|
||||
|
||||
from comprehension_history import Entry, entries, HEADING
|
||||
from larv_review.seats import FIRST_SEATS
|
||||
|
||||
|
||||
def overall_cells(entry: Entry) -> dict[str, str]:
|
||||
"""Each seat's last cell, the overall, from the first table that lists it; a vote reads as its first word, so `same (voted worse, naming no place)` is same."""
|
||||
found: dict[str, str] = {}
|
||||
for line in entry.body.splitlines():
|
||||
if line.startswith("| "):
|
||||
name, *cells = [cell.strip() for cell in line.strip("|").split("|")]
|
||||
found.setdefault(name, cells[-1].split()[0] if cells else "")
|
||||
return found
|
||||
|
||||
|
||||
def ruling_agreement(found: list[Entry]) -> list[bool]:
|
||||
"""For each paired ruling that holds both of the first seats' overall votes, whether they agree."""
|
||||
cells = [overall_cells(entry) for entry in found if entry.paired]
|
||||
return [each[FIRST_SEATS[0]] == each[FIRST_SEATS[1]] for each in cells if all(seat in each for seat in FIRST_SEATS)]
|
||||
|
||||
|
||||
def run_agreement(found: list[Entry], seats: tuple[str, str] = FIRST_SEATS) -> list[bool]:
|
||||
"""For each two successive scoring runs of one PR, whether two seats' overall scores moved the same way, up, down or not at all, between them. The two runs read near-identical code, so it is the ruling those seats would make from absolute scores."""
|
||||
runs: dict[str, list[dict[str, decimal.Decimal]]] = {}
|
||||
for entry in sorted((each for each in found if not each.paired), key=lambda each: each.time):
|
||||
cells = overall_cells(entry)
|
||||
if all(seat in cells for seat in seats):
|
||||
label = HEADING.match(entry.heading)
|
||||
runs.setdefault(label.group(2) if label else entry.heading, []).append({seat: decimal.Decimal(cells[seat]) for seat in seats})
|
||||
moves = ([(after[seat] > before[seat]) - (after[seat] < before[seat]) for seat in seats] for each in runs.values() for before, after in itertools.pairwise(each))
|
||||
return [first == second for first, second in moves]
|
||||
|
||||
|
||||
def agreement_report(history: str) -> str:
|
||||
"""Whether the first two seats agree more often in a paired ruling than across two scoring runs of one PR, as the comprehension check's decision assumes; None of either leaves it unchecked."""
|
||||
found = entries(history)
|
||||
ruled, scored = ruling_agreement(found), run_agreement(found)
|
||||
counts = f"{' and '.join(FIRST_SEATS)} voted alike overall in {sum(ruled)} of {len(ruled)} paired rulings, and their overall scores moved alike between two scoring runs of one PR in {sum(scored)} of {len(scored)} pairs of runs."
|
||||
if not ruled or not scored:
|
||||
return f"{counts} The assumption cannot be checked until the history holds both."
|
||||
holds = sum(ruled) / len(ruled) > sum(scored) / len(scored)
|
||||
return f"{counts} The assumption {'holds' if holds else 'does not hold'}: seats {'agree more' if holds else 'do not agree more'} often in a paired ruling than across scoring runs."
|
||||
+11
-4
@@ -1,6 +1,6 @@
|
||||
"""Hold larv-review's mechanical rules: the paired ruling's base and vote count, each pass's rounds, the scoring run's trigger, and the comprehension history's format and latest places.
|
||||
"""Hold larv-review's mechanical rules: the paired ruling's base and vote count, each pass's rounds, the scoring run's trigger, and the comprehension history's format, latest places and seat agreement.
|
||||
|
||||
usage: larv-review ruling-base | round-count | needs-scoring-run [<item ID>...] | record-ruling <votes file> | record-scoring <scores file> [<item ID>...] | places
|
||||
usage: larv-review ruling-base | round-count | needs-scoring-run [<item ID>...] | record-ruling <votes file> | record-scoring <scores file> [<item ID>...] | places | agreement
|
||||
|
||||
The comprehension check records how hard a project is to read, two ways, and blocks no merge. In a
|
||||
paired ruling, simulated readers, the seats, read the branch's head beside a base and vote better,
|
||||
@@ -71,6 +71,11 @@ in each later ruling, each place opening with a dimension, or Overall, that its
|
||||
A ruling recorded with scoring seats' places counts as a scoring run. Each entry's places come
|
||||
under its heading, oldest first. With no scoring run, it reads every ruling.
|
||||
|
||||
agreement checks the assumption behind the paired ruling: that Mid A and the inherited architect
|
||||
vote alike overall in a paired ruling more often than they move alike between two scoring runs of
|
||||
one PR, which read near-identical code. A seat's move between two runs is up, down or none in its
|
||||
overall score. It prints both counts and whether the assumption holds, and exits 0 either way.
|
||||
|
||||
Each record is appended to the history, created when missing, under a heading of the current UTC
|
||||
time and the seats file's first line. Each commit that line names must be in the checkout. It exits 1
|
||||
when the history already holds an entry on what that line reads.
|
||||
@@ -91,9 +96,9 @@ from larv_review.scoring import FLOOR
|
||||
from larv_review.git import history_changes
|
||||
from larv_review.ruling_base import measured_commit
|
||||
from larv_review.plan import plan_reasons
|
||||
from larv_review.record import record_ruling, record_scoring, show_places
|
||||
from larv_review.record import record_ruling, record_scoring, show_agreement, show_places
|
||||
|
||||
USAGE = "usage: larv-review ruling-base | round-count | needs-scoring-run [<item ID>...] | record-ruling <votes file> | record-scoring <scores file> [<item ID>...] | places"
|
||||
USAGE = "usage: larv-review ruling-base | round-count | needs-scoring-run [<item ID>...] | record-ruling <votes file> | record-scoring <scores file> [<item ID>...] | places | agreement"
|
||||
|
||||
|
||||
def main(argv: list[str]) -> int:
|
||||
@@ -113,6 +118,8 @@ def main(argv: list[str]) -> int:
|
||||
done = with_default_branch(lambda default: record_scoring(default, pathlib.Path(given[0]), [int(id_) for id_ in given[1:]]), stale_ok=False)
|
||||
elif command == "places" and not given:
|
||||
done = show_places()
|
||||
elif command == "agreement" and not given:
|
||||
done = show_agreement()
|
||||
elif command in ("needs-scoring-run", "record-scoring") and given:
|
||||
named = given[1:] if command == "record-scoring" else given
|
||||
print(f"{command} takes item IDs, the numbers in todo.md's ID column, not {' '.join(id_ for id_ in named if not re.fullmatch(r'[0-9]+', id_))}; {USAGE}", file=sys.stderr)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import pathlib
|
||||
import time
|
||||
|
||||
from larv_review.agreement import agreement_report
|
||||
from comprehension_history import appended, DIMENSIONS, heading, Heading, HISTORY, latest_places, recorded, ruling_entry, scoring_entry, ScoringRun, vote_text
|
||||
from git_repo import commit_exists, top
|
||||
from larv_review.ruling import counted, overall, ruling, split, votes
|
||||
@@ -85,6 +86,14 @@ def show_places() -> Failure | None:
|
||||
return None
|
||||
|
||||
|
||||
def show_agreement() -> Failure | None:
|
||||
history = history_file()
|
||||
if isinstance(history, Failure):
|
||||
return history
|
||||
print(agreement_report(history[1]))
|
||||
return None
|
||||
|
||||
|
||||
def history_file() -> tuple[pathlib.Path, str] | Failure:
|
||||
"""The checkout's history and its text, empty when the file is missing."""
|
||||
checkout = top()
|
||||
|
||||
@@ -10,6 +10,7 @@ import unittest
|
||||
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
||||
|
||||
from larv_review.agreement import agreement_report, ruling_agreement, run_agreement
|
||||
from comprehension_history import appended, entries, HistoryChange, latest_places, Place, recorded, ruling_entry, scoring_entry, ScoringRun, Seat
|
||||
import comprehension_history
|
||||
from larv_review.ruling import counted, ruling, split, votes
|
||||
@@ -156,6 +157,36 @@ class History(unittest.TestCase):
|
||||
self.assertEqual(latest_places(appended(appended("", scored), fell)), hard_since.replace("2026-10-10T12:00:00Z", "2026-10-09T12:00:00Z") + "\nJunior A, hardest first:\n\n- `bin/j.py:5` `s`: wide\n")
|
||||
|
||||
|
||||
def scored(time: str, pr: str, commit: str, junior: str, mid: str, architect: str = "7") -> str:
|
||||
return f"## {time}, {pr} at {commit}\n\n| Seat | Navigation | Locality | Shape | Self-sufficiency | Overall |\n|---|---|---|---|---|---|\n| Junior A | 7 | 7 | 7 | 7 | {junior} |\n| Mid A | 7 | 7 | 7 | 7 | {mid} |\n| Inherited architect | 7 | 7 | 7 | 7 | {architect} |\n| Mean | 7.00 | 7.00 | 7.00 | 7.00 | 7.00 |\n"
|
||||
|
||||
|
||||
def ruled(time: str, pr: str, mid: str, architect: str) -> str:
|
||||
return f"## {time}, {pr} at ccccccc, against aaaaaaa\n\nRuling: same\n\n| Seat | Navigation | Locality | Shape | Self-sufficiency | Overall |\n|---|---|---|---|---|---|\n| Mid A | same | same | same | same | {mid} |\n| Inherited architect | same | same | same | same | {architect} |\n"
|
||||
|
||||
|
||||
class Agreement(unittest.TestCase):
|
||||
def test_counts_the_rulings_whose_two_seats_vote_alike_overall(self):
|
||||
history = "\n".join([ruled("2026-10-01T00:00:00Z", "PR #1", "same", "same"), ruled("2026-10-02T00:00:00Z", "PR #2", "same (voted worse, naming no place)", "same"), ruled("2026-10-03T00:00:00Z", "PR #3", "worse", "better")])
|
||||
self.assertEqual(ruling_agreement(entries(history)), [True, True, False])
|
||||
|
||||
def test_counts_the_seat_pairs_whose_scores_move_the_same_way_between_runs_of_one_pr(self):
|
||||
seats = ("Junior A", "Mid A")
|
||||
# Junior A better and Mid A same, then Junior A worse and Mid A better: the seats differ twice. PR #2 has one run.
|
||||
differing = "\n".join([scored("2026-10-01T00:00:00Z", "PR #1", "aaaaaaa", "6.5", "7"), scored("2026-10-02T00:00:00Z", "PR #1", "bbbbbbb", "7", "7"), scored("2026-10-03T00:00:00Z", "PR #1", "ccccccc", "6.5", "7.5"), scored("2026-10-04T00:00:00Z", "PR #2", "ddddddd", "5", "5")])
|
||||
self.assertEqual(run_agreement(entries(differing), seats), [False, False])
|
||||
alike = "\n".join([scored("2026-10-01T00:00:00Z", "PR #1", "aaaaaaa", "6.5", "7"), scored("2026-10-02T00:00:00Z", "PR #1", "bbbbbbb", "7", "7.5")])
|
||||
self.assertEqual(run_agreement(entries(alike), seats), [True])
|
||||
|
||||
def test_says_whether_seats_agree_more_often_in_a_ruling_than_across_two_runs(self):
|
||||
runs = [scored("2026-10-01T00:00:00Z", "PR #1", "aaaaaaa", "7", "7", "7"), scored("2026-10-02T00:00:00Z", "PR #1", "bbbbbbb", "7", "7", "6.5")]
|
||||
agreeing = ruled("2026-10-03T00:00:00Z", "PR #2", "same", "same")
|
||||
disagreeing = ruled("2026-10-03T00:00:00Z", "PR #2", "worse", "same")
|
||||
self.assertIn("The assumption holds", agreement_report("\n".join([*runs, agreeing])))
|
||||
self.assertIn("does not hold", agreement_report("\n".join([*runs, disagreeing])))
|
||||
self.assertIn("cannot be checked", agreement_report("\n".join(runs)))
|
||||
|
||||
|
||||
class Base(unittest.TestCase):
|
||||
def test_takes_the_newest_change_adding_an_entry(self):
|
||||
older = HistoryChange("old", "", SCORING)
|
||||
@@ -337,6 +368,13 @@ class LarvReviewTool(unittest.TestCase):
|
||||
outside = subprocess.run([sys.executable, str(TOOL), "places"], capture_output=True, cwd=self.checkout.parent, env=self.env, text=True)
|
||||
self.assertEqual((outside.returncode, outside.stdout), (1, ""))
|
||||
|
||||
def test_prints_how_often_seats_agree_in_rulings_and_across_runs_of_one_pr(self):
|
||||
history = "\n".join([scored("2026-10-01T00:00:00Z", "PR #1", "aaaaaaa", "7", "7", "7"), scored("2026-10-02T00:00:00Z", "PR #1", "bbbbbbb", "7", "7", "6.5"), ruled("2026-10-03T00:00:00Z", "PR #2", "same", "same")])
|
||||
self.commit("Record the checks", {"docs/comprehension-history.md": appended("", history)})
|
||||
ran = self.run_tool("agreement")
|
||||
self.assertEqual((ran.returncode, ran.stdout), (0, "Mid A and Inherited architect voted alike overall in 1 of 1 paired rulings, and their overall scores moved alike between two scoring runs of one PR in 0 of 1 pairs of runs. The assumption holds: seats agree more often in a paired ruling than across scoring runs.\n"), ran.stderr)
|
||||
self.assertIn("unknown arguments", self.run_tool("agreement", "x").stderr)
|
||||
|
||||
def test_refuses_a_ruling_file_that_names_no_base_or_a_commit_the_checkout_lacks(self):
|
||||
ran = self.run_tool("record-ruling", self.seats_file(f"PR #2 at {self.start}\n\nMid A: {said('same')}\n\nInherited architect: {said('same')}\n"))
|
||||
self.assertEqual(ran.returncode, 1)
|
||||
|
||||
Reference in New Issue
Block a user