Answer architecture round 1: 1 🔴, 0 🟡; read the history's tables once and compare scoring runs on one commit
This commit is contained in:
@@ -1,44 +1,46 @@
|
||||
import decimal
|
||||
import itertools
|
||||
|
||||
from comprehension_history import Entry, entries, HEADING
|
||||
from comprehension_history import counted_vote, entries, Entry, table_rows
|
||||
from larv_review.seats import FIRST_SEATS
|
||||
|
||||
# As score-outcomes waits for 10 finished chunks before it shows a median.
|
||||
MIN_PAIRS = 10
|
||||
|
||||
|
||||
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
|
||||
"""Each seat's last cell: its overall vote in a ruling, its overall score in a scoring run."""
|
||||
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 agree."""
|
||||
"""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 [each[FIRST_SEATS[0]] == each[FIRST_SEATS[1]] for each in cells if all(seat in each for seat in FIRST_SEATS)]
|
||||
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], 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."""
|
||||
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 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]
|
||||
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 of one PR, as the comprehension check's decision assumes; None of either leaves it unchecked."""
|
||||
"""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 `Assumption holds:`, `Assumption fails:`, or `Unchecked:` until the history holds MIN_PAIRS pairs of runs and a ruling."""
|
||||
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."
|
||||
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} pairs of scoring runs on one commit and one paired ruling."
|
||||
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."
|
||||
return f"Assumption {'holds' if holds else 'fails'}: {counts}"
|
||||
|
||||
Reference in New Issue
Block a user