Answer architecture round 1: 0 🔴, 2 🟡 (0 misread); read a round title's counts once, into one Counts value
This commit is contained in:
+26
-19
@@ -1,4 +1,5 @@
|
||||
"""The titles of larv-review's round commits, `Answer <pass> round <n>: <k> 🔴, <m> 🟡 (<j> misread); <summary>`: each pass's round count, and the findings the rounds reported. <j> counts the 🔴 and 🟡 findings a reviewer marked `[misread]`, because the implementer misread code that had already shipped."""
|
||||
import dataclasses
|
||||
import re
|
||||
|
||||
from review_passes import PASSES
|
||||
@@ -10,6 +11,14 @@ ROUND = re.compile(r"^Answer (.+?) round ([0-9]+):", re.IGNORECASE)
|
||||
FINDINGS = re.compile(r" ([0-9]+) 🔴, ([0-9]+) 🟡(?: \(([0-9]+) misread\))?(?:;|$)")
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class Counts:
|
||||
"""A round title's findings: its 🔴 and 🟡 counts, and how many of them were misread, None for a title from before that count."""
|
||||
red: int
|
||||
yellow: int
|
||||
misread: int | None
|
||||
|
||||
|
||||
def round_counts(titles: list[str]) -> dict[str, int]:
|
||||
"""Each pass's round count among the branch's `Answer <pass> round <n>:` commit titles: the highest <n>, or the number of such commits where that is more, so a repeated number still counts. A pass with none has 0, and a title naming no known pass adds its name. Case is ignored."""
|
||||
highest: dict[str, int] = dict.fromkeys(PASSES, 0)
|
||||
@@ -24,8 +33,7 @@ def round_counts(titles: list[str]) -> dict[str, int]:
|
||||
|
||||
def lacks_counts(title: str) -> bool:
|
||||
"""Whether title is a round title without all three counts after its colon."""
|
||||
named = ROUND.match(title)
|
||||
return named is not None and ((found := FINDINGS.match(title, named.end())) is None or found.group(3) is None)
|
||||
return ROUND.match(title) is not None and ((counts := title_counts(title)) is None or counts.misread is None)
|
||||
|
||||
|
||||
def past_cap(title: str) -> bool:
|
||||
@@ -34,25 +42,24 @@ def past_cap(title: str) -> bool:
|
||||
return named is not None and int(named.group(2)) > CAP
|
||||
|
||||
|
||||
def round_findings(titles: list[str]) -> tuple[int, int] | None:
|
||||
"""The 🔴 and 🟡 counts summed over the round titles among titles; None where a round title lacks them, or no title is a round."""
|
||||
counts = []
|
||||
for title in titles:
|
||||
if named := ROUND.match(title):
|
||||
found = FINDINGS.match(title, named.end())
|
||||
if not found:
|
||||
return None
|
||||
counts.append((int(found.group(1)), int(found.group(2))))
|
||||
return (sum(red for red, _ in counts), sum(yellow for _, yellow in counts)) if counts else None
|
||||
def title_counts(title: str) -> Counts | None:
|
||||
"""The counts after a round title's colon; None where title is no round title, or lacks the 🔴 and 🟡 counts."""
|
||||
named = ROUND.match(title)
|
||||
found = FINDINGS.match(title, named.end()) if named else None
|
||||
if not found:
|
||||
return None
|
||||
return Counts(int(found.group(1)), int(found.group(2)), None if found.group(3) is None else int(found.group(3)))
|
||||
|
||||
|
||||
def round_misreads(titles: list[str]) -> int | None:
|
||||
"""The misread counts summed over the round titles among titles; None where a round title lacks one, or no title is a round."""
|
||||
def round_findings(titles: list[str]) -> Counts | None:
|
||||
"""The counts summed over the round titles among titles; None where a round title lacks the 🔴 and 🟡 counts, or no title is a round. Its misread is None where a round title lacks that count."""
|
||||
counts = []
|
||||
for title in titles:
|
||||
if named := ROUND.match(title):
|
||||
found = FINDINGS.match(title, named.end())
|
||||
if not found or found.group(3) is None:
|
||||
if ROUND.match(title):
|
||||
if (found := title_counts(title)) is None:
|
||||
return None
|
||||
counts.append(int(found.group(3)))
|
||||
return sum(counts) if counts else None
|
||||
counts.append(found)
|
||||
if not counts:
|
||||
return None
|
||||
misreads = [found.misread for found in counts if found.misread is not None]
|
||||
return Counts(sum(found.red for found in counts), sum(found.yellow for found in counts), sum(misreads) if len(misreads) == len(counts) else None)
|
||||
|
||||
@@ -2,11 +2,11 @@ import dataclasses
|
||||
import statistics
|
||||
import typing
|
||||
|
||||
from round_titles import Counts, round_counts, round_findings
|
||||
from comprehension_history import HISTORY
|
||||
from todo_table import Item, items
|
||||
from markdown_text import listed
|
||||
from reading_cost.figures import RECORD
|
||||
from round_titles import round_counts, round_findings, round_misreads
|
||||
|
||||
# Fewest single-item chunks a score needs before its medians print: the 10 figures the reading-cost trend waits for; no published standard sets either.
|
||||
ENOUGH = 10
|
||||
@@ -22,7 +22,7 @@ Chunk = tuple[str, str, int, Landing]
|
||||
# The tool's name and report call a Result an outcome, a word the code keeps for an entry of a `.outcomes.md` file: docs/decisions.md → `bin/: an outcome is an entry`.
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class Result:
|
||||
"""What the chunk that shipped an item measured. findings holds the 🔴 and 🟡 counts, None where a round title lacks them or the branch has no round. landed says how the chunk reached the default branch: by a merge commit, by a rebase that replayed its commits, or by commits never replayed. misread counts the 🔴 and 🟡 findings that arose from misreading code that had already shipped, None where a round title lacks the count or the branch has no round."""
|
||||
"""What the chunk that shipped an item measured. findings holds the 🔴 and 🟡 counts, and how many of them arose from misreading code that had already shipped, None where a round title lacks the 🔴 and 🟡 counts or the branch has no round; its misread is None where a round title lacks that count. landed says how the chunk reached the default branch: by a merge commit, by a rebase that replayed its commits, or by commits never replayed."""
|
||||
item: Item
|
||||
merge: str
|
||||
merged: str
|
||||
@@ -30,15 +30,14 @@ class Result:
|
||||
lines: int
|
||||
files: int
|
||||
rounds_past_first: int
|
||||
findings: tuple[int, int] | None
|
||||
findings: Counts | None
|
||||
landed: Landing
|
||||
misread: int | None
|
||||
|
||||
|
||||
# A measure's name and how to read it from a Result, None where the chunk did not record it.
|
||||
Measure = tuple[str, typing.Callable[[Result], int | None]]
|
||||
# The scores whose median result the report gives at each guessed value.
|
||||
MEDIANS: dict[str, Measure] = {"R": ("🔴 findings", lambda result: result.findings[0] if result.findings else None), "S": ("lines changed", lambda result: result.lines)}
|
||||
MEDIANS: dict[str, Measure] = {"R": ("🔴 findings", lambda result: result.findings.red if result.findings else None), "S": ("lines changed", lambda result: result.lines)}
|
||||
# The levels R is built from; for each, the report gives how well it orders chunks by review rounds and by 🔴 findings.
|
||||
ORDERED = ("L", "E", "I")
|
||||
# The scores render shows, in this order; C only on an item scored before L, E and I replaced it.
|
||||
@@ -64,7 +63,7 @@ def results_of(shipped: list[Item], merge: str, merged: str, numstat: str, title
|
||||
lines = sum(int(count) for row in work for count in row[:2] if count.isdigit())
|
||||
past_first = sum(max(0, count - 1) for count in round_counts(titles).values())
|
||||
ids = [item.id for item in shipped]
|
||||
return [Result(item, merge, merged, tuple(id_ for id_ in ids if id_ != item.id), lines, len(work), past_first, round_findings(titles), landed, round_misreads(titles)) for item in shipped]
|
||||
return [Result(item, merge, merged, tuple(id_ for id_ in ids if id_ != item.id), lines, len(work), past_first, round_findings(titles), landed) for item in shipped]
|
||||
|
||||
|
||||
def nearest(results: list[Result], given: dict[str, int], count: int = 5) -> list[Result]:
|
||||
@@ -89,7 +88,7 @@ def report(results: list[Result]) -> list[str]:
|
||||
lines.append(f"- {name}, {what}: " + ", ".join(f"{guess} → {statistics.median(found):g} ({plural(len(found), 'chunk')})" for guess, found in medians))
|
||||
for name in ORDERED:
|
||||
# Each pass takes a first round whatever the change, so only the rounds after it measure how hard the change was to get right.
|
||||
rows = [(result.item.scores[name], result.rounds_past_first, result.findings[0]) for result in single if name in result.item.scores and result.findings is not None]
|
||||
rows = [(result.item.scores[name], result.rounds_past_first, result.findings.red) for result in single if name in result.item.scores and result.findings is not None]
|
||||
opening = f"- {name}, by review rounds past each pass's first and 🔴 findings: "
|
||||
if len(rows) < ENOUGH:
|
||||
lines.append(opening + too_few(len(rows), name, "both outcomes"))
|
||||
@@ -107,10 +106,10 @@ def misreads(results: list[Result]) -> list[str]:
|
||||
chunks = {result.merge: result for result in results}
|
||||
lines = []
|
||||
for result in sorted(chunks.values(), key=lambda result: result.merged, reverse=True):
|
||||
if result.misread is None or result.findings is None:
|
||||
if result.findings is None or result.findings.misread is None:
|
||||
continue
|
||||
at_least = "" if result.landed == "merge" else "at least "
|
||||
lines.append(f"- {result.merged} in {result.merge}: {at_least}{result.misread} of {result.findings[0]} 🔴, {result.findings[1]} 🟡")
|
||||
lines.append(f"- {result.merged} in {result.merge}: {at_least}{result.findings.misread} of {result.findings.red} 🔴, {result.findings.yellow} 🟡")
|
||||
return lines or ["- None: no chunk's round titles count them."]
|
||||
|
||||
|
||||
@@ -137,8 +136,8 @@ def render(result: Result) -> str:
|
||||
# Rebase drops a round's commit that changed no file, so history shows such a chunk's rounds and findings short.
|
||||
at_least = "" if result.landed == "merge" else "at least "
|
||||
merged = {"merge": f"merged {result.merged} in {result.merge}", "rebase": f"merged {result.merged} by rebase in {result.merge}", "push": f"committed {result.merged} in {result.merge}, never replayed, so perhaps part of a pull request"}[result.landed]
|
||||
misread = "" if result.misread is None else f" ({result.misread} misread)"
|
||||
findings = f"{at_least}{result.findings[0]} 🔴, {result.findings[1]} 🟡{misread}" if result.findings else "findings unknown"
|
||||
misread = "" if result.findings is None or result.findings.misread is None else f" ({result.findings.misread} misread)"
|
||||
findings = f"{at_least}{result.findings.red} 🔴, {result.findings.yellow} 🟡{misread}" if result.findings else "findings unknown"
|
||||
others = result.shipped_with
|
||||
together = f", with item{'s' if len(others) > 1 else ''} {', '.join(map(str, others))}" if others else ""
|
||||
return f"- Item {result.item.id}, {scores}: {plural(result.lines, 'line')} in {plural(result.files, 'file')}, {at_least}{plural(result.rounds_past_first, 'round')} past each pass's first, {findings}; {merged}{together}. {result.item.tagline}"
|
||||
|
||||
@@ -9,6 +9,7 @@ sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
||||
|
||||
from score_outcomes.anchors import anchor_lines, parse_anchors
|
||||
from score_outcomes.main import chunk_log, report_text
|
||||
from round_titles import Counts
|
||||
from failure import Failure
|
||||
from test_env import isolated_env
|
||||
from todo_table import Item
|
||||
@@ -30,7 +31,7 @@ def item(id_: int, scores: dict[str, int]) -> Item:
|
||||
|
||||
|
||||
def result(id_: int, r: int, s: int, c: int | None, lines: int = 10, rounds: int = 1, findings: tuple[int, int] | None = (0, 0), merged: str = "2026-10-13T10:00:00Z", shipped_with: tuple[int, ...] = (), levels: dict[str, int] | None = None, landed: Landing = "merge", misread: int | None = None, merge: str = "aaaaaaa") -> Result:
|
||||
return Result(item(id_, {"R": r, "S": s} | ({"C": c} if c else {}) | (levels or {})), merge, merged, shipped_with, lines, 1, rounds, findings, landed, misread)
|
||||
return Result(item(id_, {"R": r, "S": s} | ({"C": c} if c else {}) | (levels or {})), merge, merged, shipped_with, lines, 1, rounds, None if findings is None else Counts(*findings, misread), landed)
|
||||
|
||||
|
||||
class Shipped(unittest.TestCase):
|
||||
@@ -77,12 +78,12 @@ class ResultsOf(unittest.TestCase):
|
||||
numstat = "3\t1\ta.py\n-\t-\tlogo.png\n0\t1\t2026\n5\t0\ttodo.md\n9\t0\tdocs/reading-cost.md\n4\t0\tdocs/comprehension-history.md\n"
|
||||
titles = ["Answer stability round 1: 1 🔴, 2 🟡; fix", "Answer stability round 2: 0 🔴, 1 🟡; fix", "Answer prose round 1: 0 🔴, 3 🟡", "Do it"]
|
||||
found = results_of([item(4, {"R": 2}), item(5, {"R": 3})], "abc1234", "2026-10-13T10:00:00Z", numstat, titles, "merge")
|
||||
self.assertEqual(found[0], Result(item(4, {"R": 2}), "abc1234", "2026-10-13T10:00:00Z", (5,), 5, 3, 1, (1, 6), "merge", None))
|
||||
self.assertEqual(found[0], Result(item(4, {"R": 2}), "abc1234", "2026-10-13T10:00:00Z", (5,), 5, 3, 1, Counts(1, 6, None), "merge"))
|
||||
self.assertEqual(found[1].shipped_with, (4,))
|
||||
|
||||
def test_counts_the_findings_from_misread_shipped_code_where_every_round_title_counts_them(self):
|
||||
titles = ["Answer stability round 1: 1 🔴, 2 🟡 (2 misread); fix", "Answer prose round 1: 0 🔴, 3 🟡 (1 misread)"]
|
||||
self.assertEqual(results_of([item(4, {"R": 2})], "abc1234", "2026-10-13T10:00:00Z", "3\t1\ta.py\n", titles, "merge")[0].misread, 3)
|
||||
self.assertEqual(results_of([item(4, {"R": 2})], "abc1234", "2026-10-13T10:00:00Z", "3\t1\ta.py\n", titles, "merge")[0].findings, Counts(1, 5, 3))
|
||||
|
||||
def test_measures_no_chunk_that_changed_only_the_plan(self):
|
||||
self.assertEqual(results_of([item(4, {"R": 2})], "abc1234", "2026-10-13T10:00:00Z", "0\t5\ttodo.md\n", [], "merge"), [])
|
||||
|
||||
+10
-14
@@ -4,7 +4,7 @@ import unittest
|
||||
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent))
|
||||
|
||||
from round_titles import lacks_counts, past_cap, round_counts, round_findings, round_misreads
|
||||
from round_titles import Counts, lacks_counts, past_cap, round_counts, round_findings
|
||||
|
||||
|
||||
class Rounds(unittest.TestCase):
|
||||
@@ -32,7 +32,7 @@ class Cap(unittest.TestCase):
|
||||
|
||||
class RoundFindings(unittest.TestCase):
|
||||
def test_sums_the_counts_each_round_title_opens_with(self):
|
||||
self.assertEqual(round_findings(["Answer stability round 1: 1 🔴, 2 🟡; flag a deleted test", "Answer prose round 1: 0 🔴, 3 🟡", "Merge origin/main"]), (1, 5))
|
||||
self.assertEqual(round_findings(["Answer stability round 1: 1 🔴, 2 🟡; flag a deleted test", "Answer prose round 1: 0 🔴, 3 🟡", "Merge origin/main"]), Counts(1, 5, None))
|
||||
|
||||
def test_knows_no_count_when_a_round_title_or_every_round_lacks_one(self):
|
||||
self.assertIsNone(round_findings(["Answer stability round 1: 1 🔴, 2 🟡; fix", "Answer prose round 1: fix the README"]))
|
||||
@@ -40,7 +40,14 @@ class RoundFindings(unittest.TestCase):
|
||||
self.assertIsNone(round_findings(["Do the work"]))
|
||||
|
||||
def test_reads_the_counts_of_a_title_that_also_counts_misread_findings(self):
|
||||
self.assertEqual(round_findings(["Answer stability round 1: 1 🔴, 2 🟡 (1 misread); fix", "Answer prose round 1: 0 🔴, 3 🟡 (0 misread)"]), (1, 5))
|
||||
self.assertEqual(round_findings(["Answer stability round 1: 1 🔴, 2 🟡 (1 misread); fix", "Answer prose round 1: 0 🔴, 3 🟡 (0 misread)"]), Counts(1, 5, 1))
|
||||
|
||||
def test_sums_the_misread_findings_each_round_title_counts(self):
|
||||
self.assertEqual(round_findings(["Answer stability round 1: 1 🔴, 2 🟡 (1 misread); fix", "Answer prose round 1: 0 🔴, 3 🟡 (2 misread)", "Merge origin/main"]), Counts(1, 5, 3))
|
||||
self.assertEqual(round_findings(["Answer stability round 1: 0 🔴, 0 🟡 (0 misread)"]), Counts(0, 0, 0))
|
||||
|
||||
def test_knows_no_misread_count_when_a_round_title_lacks_one(self):
|
||||
self.assertEqual(round_findings(["Answer stability round 1: 1 🔴, 2 🟡 (1 misread); fix", "Answer prose round 1: 0 🔴, 3 🟡; fix"]), Counts(1, 5, None))
|
||||
|
||||
|
||||
def test_finds_a_round_title_without_counts(self):
|
||||
@@ -51,16 +58,5 @@ class RoundFindings(unittest.TestCase):
|
||||
self.assertFalse(lacks_counts("Answer the question"))
|
||||
|
||||
|
||||
class RoundMisreads(unittest.TestCase):
|
||||
def test_sums_the_misread_findings_each_round_title_counts(self):
|
||||
self.assertEqual(round_misreads(["Answer stability round 1: 1 🔴, 2 🟡 (1 misread); fix", "Answer prose round 1: 0 🔴, 3 🟡 (2 misread)", "Merge origin/main"]), 3)
|
||||
self.assertEqual(round_misreads(["Answer stability round 1: 0 🔴, 0 🟡 (0 misread)"]), 0)
|
||||
|
||||
def test_knows_no_count_when_a_round_title_or_every_round_lacks_one(self):
|
||||
self.assertIsNone(round_misreads(["Answer stability round 1: 1 🔴, 2 🟡 (1 misread); fix", "Answer prose round 1: 0 🔴, 3 🟡; fix"]))
|
||||
self.assertIsNone(round_misreads(["Answer stability round 1: fix"]))
|
||||
self.assertIsNone(round_misreads(["Do the work"]))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user