Answer architecture round 1: 3 🔴, 13 🟡; one items-table reader, a pure measuring core, shared git and round-title modules, and a hook rule for round counts
This commit is contained in:
+43
-48
@@ -7,15 +7,15 @@ that remote, and reads origin's default branch, or else the local main or master
|
||||
reads origin as last fetched and says so on stderr.
|
||||
|
||||
Git history is the record. A chunk is a merge commit on the default branch's first-parent line
|
||||
whose change removed items from todo.md; it shipped those items. Each item's guess is its R, S and
|
||||
C in the todo.md the merge's first parent held, when the chunk began; C only where that todo.md
|
||||
scored one. The chunk measures:
|
||||
whose change removed items from todo.md, and changed more than todo.md and the records below; it
|
||||
shipped those items. Each item's guess is its R, S and C in the todo.md the merge's first parent
|
||||
held, when the chunk began; C only where that todo.md scored one. The chunk measures:
|
||||
|
||||
- lines changed: lines added plus lines deleted against the first parent, leaving out
|
||||
docs/comprehension-history.md and docs/reading-cost.md, which tools append to;
|
||||
- lines changed: lines added plus lines deleted against the first parent, leaving out todo.md and
|
||||
the records tools append to, docs/comprehension-history.md and docs/reading-cost.md;
|
||||
- files: the files those lines are in;
|
||||
- review rounds: each pass's rounds among the branch's `Answer <pass> round <n>:` commit titles,
|
||||
summed, counted as `larv-review round-count` counts them;
|
||||
- review rounds past each pass's first: among the branch's `Answer <pass> round <n>:` commit
|
||||
titles, each pass's rounds as `larv-review round-count` counts them, less one, summed;
|
||||
- 🔴 and 🟡 findings: summed over those titles, each opening `<n> 🔴, <n> 🟡` after the colon,
|
||||
such as `Answer stability round 1: 1 🔴, 2 🟡; flag a deleted test`. Unknown where a round title
|
||||
lacks the counts, or the branch has no round.
|
||||
@@ -23,11 +23,11 @@ scored one. The chunk measures:
|
||||
A project that merges without merge commits, by fast-forward or squash, has no chunk to measure.
|
||||
|
||||
Given R, S and C, it lists the 5 finished items whose guesses sit closest, closest first: the
|
||||
smallest sum of squared differences, C counted only where the item had one, the newest first among
|
||||
equals. Each line gives what the item's chunk measured, which items shipped with it, and its tagline.
|
||||
least mean squared difference over the scores both hold, C only where the item had one, the newest
|
||||
first among equals. Each line gives what the item's chunk measured, which items shipped with it, and its tagline.
|
||||
|
||||
Then, for each score, the median of the outcome it predicts at each value it was guessed at: R
|
||||
against 🔴 findings, S against lines changed, C against review rounds. It counts only chunks that
|
||||
against 🔴 findings, S against lines changed, C against review rounds past each pass's first. It counts only chunks that
|
||||
shipped one item, since a chunk measures all its items at once, and reports a score only once 10
|
||||
such chunks hold it and its outcome.
|
||||
|
||||
@@ -37,12 +37,10 @@ clone, or the default branch cannot be read.
|
||||
import re
|
||||
import sys
|
||||
|
||||
from git_repo import default_branch, file_at, full_history, git
|
||||
from failure import Failure
|
||||
from larv_review.git import default_branch, file_at, git
|
||||
from score_outcomes.outcomes import guesses, nearest, Outcome, render, report, round_findings, rounds, shipped
|
||||
|
||||
# Tools append to these records; their lines are not the chunk's work.
|
||||
RECORDS = ("docs/comprehension-history.md", "docs/reading-cost.md")
|
||||
from score_outcomes.outcomes import nearest, Outcome, outcomes_of, render, report, shipped
|
||||
from utc_stamp import utc
|
||||
|
||||
|
||||
def main(argv: list[str]) -> int:
|
||||
@@ -52,38 +50,40 @@ def main(argv: list[str]) -> int:
|
||||
if argv and (len(argv) != 3 or not all(re.fullmatch(r"[1-9]|10", arg) for arg in argv)):
|
||||
print(f"score-outcomes: cannot read the arguments {' '.join(argv)}; usage: score-outcomes [R S C], each a whole number from 1 to 10", file=sys.stderr)
|
||||
return 1
|
||||
outcomes = read_outcomes()
|
||||
found = default_branch(stale_ok=True)
|
||||
if isinstance(found, Failure):
|
||||
return failed(found)
|
||||
default, note = found
|
||||
if note:
|
||||
print(f"score-outcomes: {note}", file=sys.stderr)
|
||||
outcomes = read_outcomes(default)
|
||||
if isinstance(outcomes, Failure):
|
||||
print(f"score-outcomes: {outcomes.reason}", file=sys.stderr)
|
||||
return 1
|
||||
return failed(outcomes)
|
||||
if argv:
|
||||
given = dict(zip("RSC", map(int, argv)))
|
||||
print(f"Finished items nearest R {given['R']}, S {given['S']}, C {given['C']}, closest first:\n")
|
||||
print("\n".join(render(outcome) for outcome in nearest(outcomes, given)) or "- None: no merge commit on the default branch removed an item from todo.md.")
|
||||
print("\n".join(render(outcome) for outcome in nearest(outcomes, given)) or "- None: no merge commit on the default branch shipped an item from todo.md.")
|
||||
print()
|
||||
print("Median outcome at each guessed score, among chunks that shipped one item:\n")
|
||||
print("\n".join(report(outcomes)))
|
||||
return 0
|
||||
|
||||
|
||||
def read_outcomes() -> list[Outcome] | Failure:
|
||||
found = default_branch(stale_ok=True)
|
||||
if isinstance(found, Failure):
|
||||
return found
|
||||
default, note = found
|
||||
if note:
|
||||
print(f"score-outcomes: {note}", file=sys.stderr)
|
||||
shallow = git("rev-parse", "--is-shallow-repository")
|
||||
if isinstance(shallow, Failure):
|
||||
return shallow
|
||||
if shallow.strip() == "true":
|
||||
return Failure("a shallow clone lacks the merges it measures; run `git fetch --unshallow origin`")
|
||||
merges = git("log", "--first-parent", "--merges", "--format=%H %h %cs", default, "--", "todo.md")
|
||||
def failed(failure: Failure) -> int:
|
||||
print(f"score-outcomes: {failure.reason}", file=sys.stderr)
|
||||
return 1
|
||||
|
||||
|
||||
def read_outcomes(default: str) -> list[Outcome] | Failure:
|
||||
if partial := full_history():
|
||||
return partial
|
||||
merges = git("log", "--first-parent", "--merges", "--format=%H %h %ct", default, "--", "todo.md")
|
||||
if isinstance(merges, Failure):
|
||||
return merges
|
||||
outcomes: list[Outcome] = []
|
||||
for line in merges.splitlines():
|
||||
measured = measure(*line.split())
|
||||
merge, short, time = line.split()
|
||||
measured = measure(merge, short, utc(int(time)))
|
||||
if isinstance(measured, Failure):
|
||||
return measured
|
||||
outcomes += measured
|
||||
@@ -91,26 +91,21 @@ def read_outcomes() -> list[Outcome] | Failure:
|
||||
|
||||
|
||||
def measure(merge: str, short: str, merged: str) -> list[Outcome] | Failure:
|
||||
"""What one merge measured, for each item it removed from todo.md; none where either todo.md holds no items table."""
|
||||
texts = [file_at(f"{merge}^1", "todo.md"), file_at(merge, "todo.md")]
|
||||
if failed := next((text for text in texts if isinstance(text, Failure)), None):
|
||||
return failed
|
||||
before, after = (guesses(text) for text in texts if isinstance(text, str))
|
||||
if before is None or after is None:
|
||||
return []
|
||||
"""What one merge measured for each item it shipped."""
|
||||
before = file_at(f"{merge}^1", "todo.md")
|
||||
if isinstance(before, Failure):
|
||||
return before
|
||||
after = file_at(merge, "todo.md")
|
||||
if isinstance(after, Failure):
|
||||
return after
|
||||
items = shipped(before, after)
|
||||
# Most merges ship nothing; this spares them two more git calls.
|
||||
if not items:
|
||||
return []
|
||||
numstat = git("diff", "--numstat", f"{merge}^1", merge, "--", ".", *(f":(exclude){record}" for record in RECORDS))
|
||||
numstat = git("diff", "--numstat", f"{merge}^1", merge)
|
||||
if isinstance(numstat, Failure):
|
||||
return numstat
|
||||
changed = [row.split("\t") for row in numstat.splitlines()]
|
||||
# Git counts a binary file's lines as "-".
|
||||
lines = sum(int(count) for row in changed for count in row[:2] if count.isdigit())
|
||||
titles = git("log", "--format=%s", f"{merge}^1..{merge}^2")
|
||||
if isinstance(titles, Failure):
|
||||
return titles
|
||||
findings = round_findings(titles.splitlines())
|
||||
red, yellow = findings if findings else (None, None)
|
||||
ids = [item.id for item in items]
|
||||
return [Outcome(item, short, merged, tuple(id_ for id_ in ids if id_ != item.id), lines, len(changed), rounds(titles.splitlines()), red, yellow) for item in items]
|
||||
return outcomes_of(items, short, merged, numstat, titles.splitlines())
|
||||
|
||||
Reference in New Issue
Block a user