Answer architecture round 7: decide a fall inside record-ruling with the scoring seats' scores, give the history format one owner in comprehension_history, drop the moved Mean path, and plan the archive and judge restructures in items 83 and 62
This commit is contained in:
+103
-139
@@ -1,38 +1,35 @@
|
||||
"""Hold larv-review's mechanical rules: the paired ruling's base and vote count, each pass's rounds, the scoring run's trigger, and the comprehension history's format.
|
||||
|
||||
usage: larv-review ruling-base | round-count | needs-scoring-run [<item ID>...] | record-ruling <seats file> | record-scoring <seats file> [<item ID>...]
|
||||
usage: larv-review ruling-base | round-count | needs-scoring-run [<item ID>...] | record-ruling <votes file> [<scores file>] | record-scoring <scores file>
|
||||
|
||||
Run it inside a project checkout or one of its worktrees. Each command but record-ruling first
|
||||
fetches origin, when the checkout has that remote, and takes origin's default branch, or else the
|
||||
local main or master, as the default branch. When the fetch fails, round-count and record-scoring
|
||||
read origin as last fetched and say so on stderr; the other two exit 1. The history is
|
||||
Run it inside a project checkout or one of its worktrees. ruling-base, round-count and
|
||||
needs-scoring-run first fetch origin, when the checkout has that remote, and take origin's default
|
||||
branch, or else the local main or master, as the default branch. When the fetch fails, round-count
|
||||
reads origin as last fetched and says so on stderr; the other two exit 1. The history is
|
||||
docs/comprehension-history.md in the checkout.
|
||||
|
||||
ruling-base prints the commit a paired ruling reads against, then which of these found it. The last
|
||||
measured commit is the default branch's newest merged change whose last added paired ruling, by
|
||||
heading time, is better, or that adds a scoring run to the history while that ruling names no fall;
|
||||
a merge commit counts as one change against its first parent. With none, the base is the one the
|
||||
history's first paired ruling names; with no ruling either, it is the merge base of HEAD and the
|
||||
default branch.
|
||||
measured commit is the default branch's newest merged change that adds a scoring run to the
|
||||
history, or whose last added paired ruling, by heading time, is better; a merge commit counts as
|
||||
one change against its first parent. With none, the base is the one the history's first paired
|
||||
ruling names; with no ruling either, it is the merge base of HEAD and the default branch.
|
||||
|
||||
round-count prints each pass's count: the highest <n> among the titles opening `Answer <pass> round
|
||||
<n>:` of commits the default branch does not hold. It marks each pass at the cap of {cap} rounds,
|
||||
and each name in such a title that is not a pass.
|
||||
|
||||
needs-scoring-run takes the IDs of the todo.md items the chunk ships, none when it ships none, and
|
||||
prints why the chunk is due a scoring run, or `No scoring run due.` The chunk's entries are those
|
||||
the checkout's history holds and the default branch's lacks. It is due when the chunk ships an item
|
||||
whose tagline names the comprehension floor, when it leaves a release with no item in the
|
||||
checkout's todo.md, less the shipped items, and work has landed towards that release, or when the
|
||||
chunk's newest entry is a paired ruling with a `Fell:` line. Work has landed when the chunk ships
|
||||
one of the release's items, or when the release is the earliest the default branch's todo.md names
|
||||
and the default branch has a commit after its newest v* tag, or has no v* tag.
|
||||
prints why the chunk is due a scoring run, or `No scoring run due.` It is due when the chunk ships
|
||||
an item whose tagline names the comprehension floor, or when it leaves a release with no item in
|
||||
the checkout's todo.md, less the shipped items, and work has landed towards that release. Work has
|
||||
landed when the chunk ships one of the release's items, or when the release is the earliest the
|
||||
default branch's todo.md names and the default branch has a commit after its newest v* tag, or has
|
||||
no v* tag.
|
||||
|
||||
record-ruling and record-scoring read a seats file: a first line naming what the seats read, `<PR or
|
||||
branch> at <commit>`, ending `, against <base>` for a paired ruling, then each seat's line, each
|
||||
followed by its places, one `- ` bullet each, as the history writes them. A seat's line opens with
|
||||
its label, written exactly: `Junior A:`, `Mid A:`, `Maintainability senior:` or `Inherited
|
||||
architect:`.
|
||||
A seats file's first line names what the seats read, `<PR or branch> at <commit>`, ending
|
||||
`, against <base>` in a votes file. Each seat's line follows, opening with its label written
|
||||
exactly: `Junior A:`, `Mid A:`, `Maintainability senior:` or `Inherited architect:`. Its places
|
||||
follow it, one `- ` bullet each, as the history writes them. A votes file:
|
||||
|
||||
PR #231 at abc1234, against def5678
|
||||
|
||||
@@ -46,35 +43,30 @@ architect:`.
|
||||
- Navigation: `README.md:40` "Tools": ...
|
||||
- Locality: `bin/x.py:12` `run`: ...
|
||||
|
||||
A scores file holds Junior A's, Mid A's, the maintainability senior's and the inherited architect's
|
||||
lines in that order, each `Navigation <n>, Locality <n>, Shape <n>, Self-sufficiency <n>, Overall
|
||||
<n>`: each score from 1 to 10, and the overall at most 1 above the line's lowest dimension.
|
||||
|
||||
record-ruling takes Mid A's and the inherited architect's votes on each dimension and overall, each
|
||||
better, same or worse. Each place opens with the names from the seat's line that it moves, joined by
|
||||
`, ` and followed by `: `. A dimension's vote counts as same unless one of the seat's places opens
|
||||
with that dimension and holds a `path:line` in backticks; the overall vote counts as same unless any
|
||||
place holds one. The printed votes say so. When the two counted overall votes differ, it appends
|
||||
nothing and prints `Split:`, saying to add the maintainability senior's and Junior A's lines.
|
||||
Otherwise the ruling is the overall vote that leads each other vote by two or more, else same; it
|
||||
prints `Ruling:` and appends the ruling. A dimension falls when its worse votes lead each other vote
|
||||
by two or more. Unless the ruling is worse, it prints and records a `Fell:` line naming each.
|
||||
Otherwise the ruling is the overall vote that leads each other vote by two or more, else same. A
|
||||
dimension falls when its worse votes lead each other vote by two or more. When a better or same
|
||||
ruling has a fallen dimension, it appends nothing and prints `Fell:`, saying to run the four
|
||||
scoring seats on the same commit and run it again with their scores file. With that file, the
|
||||
ruling counts as worse when a fallen dimension's mean is under the floor of {floor}, and stands
|
||||
otherwise. It prints `Ruling:` and appends the ruling, with the scores where a fall called them.
|
||||
|
||||
record-scoring takes a seats file and the IDs of the items the chunk ships, as needs-scoring-run
|
||||
does. The file holds Junior A's, Mid A's, the maintainability senior's and the inherited architect's
|
||||
lines in that order, or a `Mean:` line alone for a run moved from a decision entry. Each line is
|
||||
`Navigation <n>, Locality <n>, Shape <n>, Self-sufficiency <n>, Overall <n>`, each score from 1 to
|
||||
10 and the overall at most 1 above the line's lowest dimension. Its first line names no `, against`.
|
||||
It appends the seats' scores and their means, rounded half up to two decimals, and prints the means,
|
||||
the item IDs it read, and each mean under the floor of {floor}. It exits 1 on a run with seats that
|
||||
no plan item, release or fall calls. A line opening `Floor:` says the means under the floor block
|
||||
the merge, as they do when needs-scoring-run would give a reason besides a fall. It reads the
|
||||
chunk's entries as needs-scoring-run does. When a fall is pending, it says whether the paired ruling
|
||||
stands. When a fallen dimension's mean is under the floor, the ruling counts as worse, and it prints
|
||||
and records a `Ratchet:` line. needs-scoring-run repeats that line, prefixed with `Still standing:`,
|
||||
until a paired ruling follows it. Once a scoring run follows a fall, the fall calls no other. A file
|
||||
holding a `Mean:` line alone prints only its means.
|
||||
record-scoring takes the scores file of a run needs-scoring-run called, whose first line names no
|
||||
`, against`. It appends the seats' scores and their means, rounded half up to two decimals, prints
|
||||
the means, and prints a line opening `Floor:` that names each mean under the floor of {floor}.
|
||||
|
||||
Each record is appended to the history, created when missing, under a heading of the current UTC
|
||||
time and the seats file's first line. A file holding a `Mean:` line alone opens with the date or
|
||||
time its decision entry gives, and that line alone is the heading. Each commit the line names must
|
||||
be in the checkout. Each run appends, so record a ruling or a run once.
|
||||
time and the seats file's first line. Each commit that line names must be in the checkout. Each run
|
||||
appends, so record a ruling or a run once.
|
||||
|
||||
Exit 1, saying why, on unknown arguments, an unknown item ID, a seats file it cannot read or that
|
||||
breaks the shape above, or when git cannot start, finds no checkout or no default branch, cannot
|
||||
@@ -87,18 +79,18 @@ import sys
|
||||
import time
|
||||
import typing
|
||||
|
||||
from larv_review.history import appended, heading, ruling_entry, scoring_entry, vote_text
|
||||
from comprehension_history import appended, DIMENSIONS, heading, HISTORY, ruling_entry, Scoring, scoring_entry, vote_text
|
||||
from larv_review.base import base
|
||||
from larv_review.rounds import CAP, PASSES, round_counts
|
||||
from larv_review.scoring import chunk_entries, fall, Fall, fall_outcome, fall_reasons, FLOOR, floor_verdict, means, plan_items, scoring_run_due, uncalled, under_floor
|
||||
from larv_review.git import commit_exists, default_branch, file_at, git, HISTORY, history_changes, landed_since_release, top
|
||||
from larv_review.git import commit_exists, default_branch, file_at, git, history_changes, landed_since_release, top
|
||||
from larv_review.ruling import counted, fallen, ruling, votes
|
||||
from larv_review.seats import DIMENSIONS, MEAN, Report, report, score_line, scores
|
||||
from failure import Failure
|
||||
from larv_review.scoring import fall_ruling, FLOOR, means, plan_items, scoring_run_due, under_floor
|
||||
from rank_todo import ITEMS_HEADER
|
||||
from file_writes import replace_file
|
||||
from larv_review.seats import scores, seats_file, SeatsFile
|
||||
|
||||
USAGE = "usage: larv-review ruling-base | round-count | needs-scoring-run [<item ID>...] | record-ruling <seats file> | record-scoring <seats file> [<item ID>...]"
|
||||
USAGE = "usage: larv-review ruling-base | round-count | needs-scoring-run [<item ID>...] | record-ruling <votes file> [<scores file>] | record-scoring <scores file>"
|
||||
|
||||
|
||||
def main(argv: list[str]) -> int:
|
||||
@@ -112,13 +104,12 @@ def main(argv: list[str]) -> int:
|
||||
done = with_default_branch(round_count, stale_ok=True)
|
||||
elif command == "needs-scoring-run" and all(re.fullmatch(r"[0-9]+", id_) for id_ in given):
|
||||
done = with_default_branch(lambda default: needs_scoring_run(default, [int(id_) for id_ in given]), stale_ok=False)
|
||||
elif command == "record-ruling" and len(given) == 1:
|
||||
done = record_ruling(pathlib.Path(given[0]))
|
||||
elif command == "record-scoring" and given and all(re.fullmatch(r"[0-9]+", id_) for id_ in given[1:]):
|
||||
done = with_default_branch(lambda default: record_scoring(default, pathlib.Path(given[0]), [int(id_) for id_ in given[1:]]), stale_ok=True)
|
||||
elif command in ("needs-scoring-run", "record-scoring") and given:
|
||||
named = given[1:] if command == "record-scoring" else given
|
||||
print(f"{command} takes item IDs, the numbers in todo.md's ID column, not {' '.join(id_ for id_ in named if not re.fullmatch(r'[0-9]+', id_))}; {USAGE}", file=sys.stderr)
|
||||
elif command == "record-ruling" and len(given) in (1, 2):
|
||||
done = record_ruling(*map(pathlib.Path, given))
|
||||
elif command == "record-scoring" and len(given) == 1:
|
||||
done = record_scoring(pathlib.Path(given[0]))
|
||||
elif command == "needs-scoring-run":
|
||||
print(f"needs-scoring-run takes item IDs, the numbers in todo.md's ID column, not {' '.join(id_ for id_ in given if not re.fullmatch(r'[0-9]+', id_))}", file=sys.stderr)
|
||||
return 1
|
||||
elif not argv:
|
||||
print(USAGE, file=sys.stderr)
|
||||
@@ -169,21 +160,6 @@ def round_count(default: str) -> Failure | None:
|
||||
|
||||
|
||||
def needs_scoring_run(default: str, ids: list[int]) -> Failure | None:
|
||||
state = chunk_fall(default)
|
||||
if isinstance(state, Failure):
|
||||
return state
|
||||
planned = plan_reasons(default, ids)
|
||||
if isinstance(planned, Failure):
|
||||
return planned
|
||||
reasons = planned + fall_reasons(state)
|
||||
print(f"Scoring run due: the chunk {' and '.join(reasons)}." if reasons else "No scoring run due.")
|
||||
if state.ratchet:
|
||||
print(f"Still standing: {state.ratchet} Fix it and rule again.")
|
||||
return None
|
||||
|
||||
|
||||
def plan_reasons(default: str, ids: list[int]) -> list[str] | Failure:
|
||||
"""Why the plan calls a scoring run, from the default branch's todo.md and the checkout's."""
|
||||
checkout = top()
|
||||
if isinstance(checkout, Failure):
|
||||
return checkout
|
||||
@@ -204,22 +180,15 @@ def plan_reasons(default: str, ids: list[int]) -> list[str] | Failure:
|
||||
landed = landed_since_release(default)
|
||||
if isinstance(landed, Failure):
|
||||
return landed
|
||||
return scoring_run_due(planned, chunk, ids, landed)
|
||||
reasons = scoring_run_due(planned, chunk, ids, landed)
|
||||
if isinstance(reasons, Failure):
|
||||
return reasons
|
||||
print(f"Scoring run due: the chunk {' and '.join(reasons)}." if reasons else "No scoring run due.")
|
||||
return None
|
||||
|
||||
|
||||
def chunk_fall(default: str) -> Fall | Failure:
|
||||
"""Where the chunk stands in the fall sequence, from the entries the checkout's history holds and the default branch's lacks."""
|
||||
held = file_at(default, HISTORY)
|
||||
if isinstance(held, Failure):
|
||||
return held
|
||||
read = history_text()
|
||||
if isinstance(read, Failure):
|
||||
return read
|
||||
return fall(chunk_entries(held, read[1]))
|
||||
|
||||
|
||||
def record_ruling(seats_file: pathlib.Path) -> Failure | None:
|
||||
read = read_seats(seats_file, paired=True)
|
||||
def record_ruling(votes_file: pathlib.Path, scores_file: pathlib.Path | None = None) -> Failure | None:
|
||||
read = read_seats(votes_file, paired=True)
|
||||
if isinstance(read, Failure):
|
||||
return read
|
||||
title, given = read
|
||||
@@ -230,65 +199,71 @@ def record_ruling(seats_file: pathlib.Path) -> Failure | None:
|
||||
tally = ", ".join(f"{seat.name} {vote_text(DIMENSIONS[-1], said[seat.name][-1], count[seat.name][-1])}" for seat in given.seats)
|
||||
ruled = ruling([each[-1] for each in count.values()])
|
||||
if ruled is None:
|
||||
print(f"Split: {tally}. Launch the maintainability senior and Junior A together, add their lines to the seats file, and run this again.")
|
||||
print(f"Split: {tally}. Launch the maintainability senior and Junior A together, add their lines to the votes file, and run this again.")
|
||||
return None
|
||||
fell = fallen(count) if ruled != "worse" else []
|
||||
print(f"Ruling: {ruled}. Overall votes as counted: {tally}.")
|
||||
if fell:
|
||||
print(f"Fell: {', '.join(fell)}. A scoring run is due; the ruling counts as worse if that run scores {' or '.join(fell)} under the floor of {FLOOR}.")
|
||||
return append(ruling_entry(title, given.seats, said, count, ruled, fell))
|
||||
if fell and scores_file is None:
|
||||
print(f"Fell: {', '.join(fell)}, in a {ruled} ruling. Launch the four scoring seats on {given.read.partition(', against')[0]}, write their lines to a scores file, and run this again with both files.")
|
||||
return None
|
||||
if scores_file and not fell:
|
||||
return Failure(f"no dimension fell in this {ruled} ruling, so it takes no scores file")
|
||||
lines = [f"Ruling: {ruled}"]
|
||||
scoring = None
|
||||
if scores_file:
|
||||
scored = read_scoring(scores_file, given.read.partition(", against")[0])
|
||||
if isinstance(scored, Failure):
|
||||
return scored
|
||||
scoring = scored
|
||||
ruled, why = fall_ruling(ruled, fell, [decimal.Decimal(value) for value in scoring.means])
|
||||
lines = [f"Ruling: {ruled}", why]
|
||||
print(f"{lines[0]}. {' '.join(lines[1:] + [f'Overall votes as counted: {tally}.'])}")
|
||||
return append(ruling_entry(title, given.seats, said, count, lines, scoring))
|
||||
|
||||
|
||||
def record_scoring(default: str, seats_file: pathlib.Path, ids: list[int]) -> Failure | None:
|
||||
read = read_seats(seats_file, paired=False)
|
||||
def record_scoring(scores_file: pathlib.Path) -> Failure | None:
|
||||
read = read_seats(scores_file, paired=False)
|
||||
if isinstance(read, Failure):
|
||||
return read
|
||||
title, given = read
|
||||
if given.moved_mean is not None:
|
||||
return record_moved_mean(title, given.moved_mean)
|
||||
scoring = scored_seats(given)
|
||||
if isinstance(scoring, Failure):
|
||||
return scoring
|
||||
found = [decimal.Decimal(value) for value in scoring.means]
|
||||
print(f"Means: {', '.join(f'{name} {value}' for name, value in zip(DIMENSIONS, found))}.")
|
||||
if under := under_floor(found):
|
||||
print(f"Floor: {', '.join(under)} under the floor of {FLOOR} block the merge.")
|
||||
return append(scoring_entry(title, [], scoring))
|
||||
|
||||
|
||||
def read_scoring(scores_file: pathlib.Path, read: str) -> Scoring | Failure:
|
||||
"""The scores a fall called, once their file names what the votes file read."""
|
||||
try:
|
||||
given = seats_file(scores_file.read_text(encoding="utf-8"))
|
||||
except (OSError, UnicodeDecodeError) as failure:
|
||||
return Failure(f"could not read {scores_file}: {failure}")
|
||||
if isinstance(given, Failure):
|
||||
return given
|
||||
if given.read != read:
|
||||
return Failure(f"the scores file's first line is not `{read}`, as the votes file reads: {given.read}")
|
||||
return scored_seats(given)
|
||||
|
||||
|
||||
def scored_seats(given: SeatsFile) -> Scoring | Failure:
|
||||
found = scores(given.seats)
|
||||
if isinstance(found, Failure):
|
||||
return found
|
||||
mean = means(list(found.values()))
|
||||
state = chunk_fall(default)
|
||||
if isinstance(state, Failure):
|
||||
return state
|
||||
planned = plan_reasons(default, ids)
|
||||
if isinstance(planned, Failure):
|
||||
return planned
|
||||
if not (planned or state.pending):
|
||||
return Failure(uncalled(state))
|
||||
print(f"Means: {means_text(mean)}.")
|
||||
print(f"Item IDs read: {', '.join(map(str, ids)) or 'none'}.")
|
||||
print(floor_verdict(under_floor(mean), planned))
|
||||
outcome = fall_outcome(state.pending, mean)
|
||||
if outcome:
|
||||
print(outcome[0])
|
||||
return append(scoring_entry(title, given.seats, found, [str(value) for value in mean], outcome[1] if outcome else []))
|
||||
return Scoring(given.seats, found, [str(value) for value in means(list(found.values()))])
|
||||
|
||||
|
||||
def record_moved_mean(title: str, line: str) -> Failure | None:
|
||||
moved = score_line(MEAN, line)
|
||||
if isinstance(moved, Failure):
|
||||
return moved
|
||||
mean = means([moved])
|
||||
print(f"Means: {means_text(mean)}.")
|
||||
return append(scoring_entry(title, [], {}, [str(value) for value in mean], []))
|
||||
|
||||
|
||||
def means_text(mean: list[decimal.Decimal]) -> str:
|
||||
return ", ".join(f"{name} {value}" for name, value in zip(DIMENSIONS, mean))
|
||||
|
||||
|
||||
def read_seats(seats_file: pathlib.Path, paired: bool) -> tuple[str, Report] | Failure:
|
||||
def read_seats(path: pathlib.Path, paired: bool) -> tuple[str, SeatsFile] | Failure:
|
||||
"""The seats file, and the heading its record goes under, once each commit it names is in the checkout."""
|
||||
try:
|
||||
given = report(seats_file.read_text(encoding="utf-8"))
|
||||
given = seats_file(path.read_text(encoding="utf-8"))
|
||||
except (OSError, UnicodeDecodeError) as failure:
|
||||
return Failure(f"could not read {seats_file}: {failure}")
|
||||
return Failure(f"could not read {path}: {failure}")
|
||||
if isinstance(given, Failure):
|
||||
return given
|
||||
named = heading(time.time(), given.read, paired, given.moved_mean is not None)
|
||||
named = heading(time.time(), given.read, paired)
|
||||
if isinstance(named, Failure):
|
||||
return named
|
||||
if unknown := [commit for commit in (named.commit, named.against) if commit and not commit_exists(commit)]:
|
||||
@@ -296,27 +271,16 @@ def read_seats(seats_file: pathlib.Path, paired: bool) -> tuple[str, Report] | F
|
||||
return named.title, given
|
||||
|
||||
|
||||
def history_text() -> tuple[pathlib.Path, str] | Failure:
|
||||
"""The checkout's history and its text, empty when the file is missing."""
|
||||
def append(entry: str) -> Failure | None:
|
||||
checkout = top()
|
||||
if isinstance(checkout, Failure):
|
||||
return checkout
|
||||
history = pathlib.Path(checkout, HISTORY)
|
||||
try:
|
||||
return history, history.read_text(encoding="utf-8") if history.exists() else ""
|
||||
text = history.read_text(encoding="utf-8") if history.exists() else ""
|
||||
history.parent.mkdir(parents=True, exist_ok=True)
|
||||
except (OSError, UnicodeDecodeError) as failure:
|
||||
return Failure(f"could not read {history}: {failure}")
|
||||
|
||||
|
||||
def append(entry: str) -> Failure | None:
|
||||
read = history_text()
|
||||
if isinstance(read, Failure):
|
||||
return read
|
||||
history, text = read
|
||||
try:
|
||||
history.parent.mkdir(parents=True, exist_ok=True)
|
||||
except OSError as failure:
|
||||
return Failure(f"could not create {history.parent}: {failure}")
|
||||
if unwritten := replace_file(history, appended(text, entry).encode()):
|
||||
return Failure(f"could not write {history}: {unwritten.reason}")
|
||||
print(f"Appended to {history}.")
|
||||
|
||||
Reference in New Issue
Block a user