Answer prose round 1: 0 🔴, 16 🟡; say position not rank, split the changelog entry, tighten messages and details
This commit is contained in:
+16
-14
@@ -1,14 +1,14 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Score todo.md's items by the formula it states, weighing each achieve goal by its rank in README.md, and hold them to its bar.
|
||||
"""Score todo.md's items by the formula it states, weighing each achieve goal by its position in README.md, and hold them to its bar.
|
||||
|
||||
usage: rank_todo.py [--check] [todo.md]
|
||||
|
||||
Reads todo.md (default: ./todo.md), the README.md beside it, and docs/decisions.md when there is
|
||||
one. Rewrites each item's Score from the formula and sorts the items by release; within a release,
|
||||
security rows come first, then defect rows, then the rest, each group by score from highest, then by ID. Then it moves each blocker,
|
||||
an item another's Blocked by cell names, that ranks below an item it blocks to just above the first
|
||||
such item. Orders the details to match. Adds the Blocked by column to a table
|
||||
without it. --check writes nothing and fails when the file is not ranked as it would be.
|
||||
security rows come first, then defect rows, then the rest, each group by score from highest, then
|
||||
by ID. Then it moves each blocker, an item another's Blocked by cell names, that ranks below an item
|
||||
it blocks to just above the first such item. Orders the details to match. Adds the Blocked by column
|
||||
to a table without it. --check writes nothing and fails when the file is not ranked as it would be.
|
||||
|
||||
A valid todo.md; ## Details and each item's detail are optional:
|
||||
|
||||
@@ -83,11 +83,11 @@ LARGEST_FORMULA = 200
|
||||
LONGEST_FORMULA = 4 * LARGEST_FORMULA
|
||||
OPERATORS = (ast.Add, ast.BinOp, ast.Div, ast.Expression, ast.Load, ast.Mult, ast.Pow, ast.Sub, ast.UAdd, ast.UnaryOp, ast.USub)
|
||||
WEIGHTS_HEADER = "| Goal | W |"
|
||||
# The Exempt reasons that rank an item ahead of the rest of its release, in order: a security finding, then a defect, which a 🔴 or a broken maintain goal is.
|
||||
# Exempt reasons that rank ahead of the rest of their release, in this order.
|
||||
FIRST = {"security": 0, "defect": 1}
|
||||
# How README.md marks a goal; None where it marks it neither way.
|
||||
Mark = typing.Literal["Maintain", "Achieve"] | None
|
||||
RESHAPE = f"the items table scores A and G against goal weights todo.md states, the shape before {MOVES}. Until it has the shape rank_todo.py --help shows, reshaping it is the project's only work, as ~/.claude/CLAUDE.md → 'Working loop' says: mark README.md's goals **Maintain:** or **Achieve:**, name each item's {MOVES}, and set the bar on the new scale under every item to keep"
|
||||
RESHAPE = f"todo.md's items table is in the old shape, scoring A and G against goal weights todo.md states. Until todo.md has the shape rank_todo.py --help shows, reshaping it is the project's only work, as ~/.claude/CLAUDE.md → 'Working loop' says: mark README.md's goals **Maintain:** or **Achieve:**, name each item's {MOVES}, and set the bar below the score of every item to keep"
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
@@ -98,7 +98,7 @@ class Scoring:
|
||||
next_id: int
|
||||
# README.md's goal numbers, in reading order.
|
||||
goals: list[str]
|
||||
# The weight of each goal an item may name: in OLD_SHAPE every goal, at the weight todo.md states; else each achieve goal, by its rank in README.md.
|
||||
# The weight of each goal an item may name: in OLD_SHAPE every goal, at the weight todo.md states; else each achieve goal, by its position in README.md.
|
||||
weights: dict[str, float]
|
||||
|
||||
|
||||
@@ -106,7 +106,7 @@ class Scoring:
|
||||
class Ranked:
|
||||
text: str
|
||||
under_bar: list[str]
|
||||
# The lines ranking prints and --check does not: that an old-shape table wants reshaping, and each blocker ID dropped because the table no longer holds it, since a mistyped ID is dropped the same way.
|
||||
# What ranking prints and --check does not: an old-shape table's call to reshape, a README with no achieve goal, and each dropped blocker ID, since a mistyped ID drops the same way.
|
||||
notes: list[str]
|
||||
|
||||
|
||||
@@ -221,7 +221,7 @@ def notes(items: list[Item], scoring: Scoring) -> list[str]:
|
||||
dropped = [f"item {item.id}: dropped {', '.join(map(str, gone))} from its {BLOCKED_BY}; the table no longer holds {'it' if len(gone) == 1 else 'them'}" for item in items if (gone := sorted(set(item.blocked_by) - held))]
|
||||
if scoring.shape is OLD_SHAPE:
|
||||
return [RESHAPE] + dropped
|
||||
# Said, since every item under the bar for that reason reads like one of low value.
|
||||
# Printed so the under-bar lines it causes do not read as items of low value.
|
||||
unweighed = [] if scoring.weights else ["README.md marks no goal **Achieve:**, so every item scores V 0"]
|
||||
return unweighed + dropped
|
||||
|
||||
@@ -271,7 +271,7 @@ def read_scoring(text: str, lines: list[str], readme: str, shape: Shape) -> Scor
|
||||
if shape is OLD_SHAPE:
|
||||
weights = parse_weights(lines, numbers)
|
||||
elif WEIGHTS_HEADER in lines:
|
||||
weights = Failure(f"todo.md holds a goal weights table beside a {MOVES} column; drop the table, since rank_todo.py weighs each achieve goal by its rank in README.md")
|
||||
weights = Failure(f"todo.md holds a goal weights table beside a {MOVES} column; drop the table, since rank_todo.py weighs each achieve goal by its position in README.md")
|
||||
else:
|
||||
weights = achieve_weights(goals)
|
||||
if isinstance(weights, Failure):
|
||||
@@ -299,7 +299,9 @@ def unknown_columns(table: Table) -> Failure | None:
|
||||
known = shape_of(table.columns).columns
|
||||
unknown = [column for column in table.columns if column not in known]
|
||||
if old := [column for column in unknown if column in OLD_SHAPE.columns]:
|
||||
return Failure(f"todo.md's items table has the column {', '.join(old)}, a column of the old shape, which {MOVES} replaced; drop it")
|
||||
listed = old[0] if len(old) == 1 else f"{', '.join(old[:-1])} and {old[-1]}"
|
||||
kind = f"a column of the old shape that {MOVES} replaced; drop it" if len(old) == 1 else f"columns of the old shape that {MOVES} replaced; drop them"
|
||||
return Failure(f"todo.md's items table has {listed}, {kind}")
|
||||
if unknown:
|
||||
return Failure(f"todo.md's items table has the column {', '.join(unknown)}, which this rank_todo.py does not know; the columns it knows are {', '.join(known)}. Rename it, or move this machine to the release that added it")
|
||||
return None
|
||||
@@ -473,7 +475,7 @@ def evaluate(node: ast.AST, values: dict[str, float]) -> float:
|
||||
divisor = evaluate(right, values)
|
||||
return evaluate(left, values) / divisor if divisor else math.nan
|
||||
case ast.BinOp(left, ast.Pow(), right):
|
||||
# Caught in place of checking first: a negative base with a fractional exponent, zero to a negative power and an overflow each raise, and three checks would read worse than one catch.
|
||||
# math.pow raises on a negative base with a fractional exponent, zero to a negative power, and overflow; one catch covers all three.
|
||||
base, exponent = evaluate(left, values), evaluate(right, values)
|
||||
# A nan from a zero divisor stays nan, though math.pow(1, nan) and math.pow(nan, 0) give 1.
|
||||
if math.isnan(base) or math.isnan(exponent):
|
||||
@@ -497,7 +499,7 @@ def variables(shape: Shape) -> tuple[str, ...]:
|
||||
|
||||
def score(formula: ast.Expression, item: Item, scoring: Scoring) -> float | Failure:
|
||||
if goal_term(scoring.shape) == "W":
|
||||
# An item serving several goals is weighed by the heaviest; summing them would reward citing more.
|
||||
# The old shape weighs an item by its heaviest cited goal.
|
||||
term = max(scoring.weights[goal] for goal, _ in item.moves)
|
||||
else:
|
||||
# Only an OLD_SHAPE item names a goal without a move.
|
||||
|
||||
Reference in New Issue
Block a user