Files
claude-config/bin/larv_review/agreement.py
T

45 lines
2.7 KiB
Python

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."