Answer architecture round 1: 0 🔴, 2 🟡 (0 misread); read a round title's counts once, into one Counts value

This commit is contained in:
2026-10-23 11:30:17 +02:00
parent 4d18b8e125
commit 80cc36e904
4 changed files with 50 additions and 47 deletions
+10 -11
View File
@@ -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}"
+4 -3
View File
@@ -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"), [])