47 lines
2.9 KiB
Python
47 lines
2.9 KiB
Python
import decimal
|
|
|
|
from comprehension_history import counted_vote, entries, Entry, table_rows
|
|
from larv_review.seats import FIRST_SEATS
|
|
|
|
# Matches score-outcomes, which waits for 10 finished chunks before it shows a median.
|
|
MIN_PAIRS = 10
|
|
|
|
|
|
def overall_cells(entry: Entry) -> dict[str, str]:
|
|
"""Each table row's last non-empty cell, by its first cell: a seat's overall vote in a ruling table, whether it has five votes or the older single `Vote`, or its overall score in a scoring table."""
|
|
return {name: cells[-1] for name, cells in table_rows(entry.body).items() if cells and cells[-1]}
|
|
|
|
|
|
def ruling_agreement(found: list[Entry]) -> list[bool]:
|
|
"""For each paired ruling that holds both of the first seats' overall votes, whether they counted alike."""
|
|
first, second = FIRST_SEATS
|
|
cells = [overall_cells(entry) for entry in found if entry.paired]
|
|
return [counted_vote(each[first]) == counted_vote(each[second]) for each in cells if first in each and second in each]
|
|
|
|
|
|
def run_agreement(found: list[Entry]) -> list[bool]:
|
|
"""For each commit scored at least twice, whether the first two seats' overall scores moved the same way, up, down or not at all, from its first run to its second. Both runs read one tree, so the pair is the ruling those seats would make from absolute scores on code that did not change."""
|
|
first, second = FIRST_SEATS
|
|
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 first in cells and second in cells:
|
|
runs.setdefault(entry.commit, []).append({first: decimal.Decimal(cells[first]), second: decimal.Decimal(cells[second])})
|
|
pairs = [(each[0], each[1]) for each in runs.values() if len(each) >= 2]
|
|
return [direction(before[first], after[first]) == direction(before[second], after[second]) for before, after in pairs]
|
|
|
|
|
|
def direction(before: decimal.Decimal, after: decimal.Decimal) -> int:
|
|
return (after > before) - (after < before)
|
|
|
|
|
|
def agreement_report(history: str) -> str:
|
|
"""Whether the first two seats agree more often in a paired ruling than across two scoring runs on one commit, as the comprehension check's decision assumes. It opens `Unchecked:` until the history holds MIN_PAIRS pairs of runs and one paired ruling, then `Assumption holds:` or `Assumption fails:`; equal rates fail."""
|
|
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 on one commit in {sum(scored)} of {len(scored)} pairs."
|
|
if len(scored) < MIN_PAIRS or not ruled:
|
|
return f"Unchecked: {counts} A verdict needs {MIN_PAIRS} commits each scored twice and one paired ruling."
|
|
holds = sum(ruled) / len(ruled) > sum(scored) / len(scored)
|
|
return f"Assumption {'holds' if holds else 'fails'}: {counts}"
|