Score defects like any item, a maintain-restoring defect naming its goal at the heaviest weight, and add a fixed chunk cost F = 8, as lilleman asked
This commit is contained in:
+21
-21
@@ -5,8 +5,7 @@ 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
|
||||
security rows come first, 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.
|
||||
|
||||
@@ -16,7 +15,7 @@ A valid todo.md; ## Details and each item's detail are optional:
|
||||
|
||||
## Scoring
|
||||
|
||||
`Score = 100 * V / 2**S`
|
||||
`Score = 100 * V / (2**S + 8)`
|
||||
|
||||
`Bar = 1`
|
||||
|
||||
@@ -36,9 +35,10 @@ A valid todo.md; ## Details and each item's detail are optional:
|
||||
|
||||
- The formula holds numbers, + - * / ** and parentheses over R, S and V.
|
||||
- V sums, over the goals in an item's Moves cell, each goal's weight times how far the item moves it.
|
||||
README.md marks each goal **Maintain:** or **Achieve:**; only an achieve goal scores. The one
|
||||
ranked k of n achieve goals, in reading order, a sub-goal such as 1.1 included, weighs
|
||||
(1/k) / (1 + 1/2 + ... + 1/n).
|
||||
README.md marks each goal **Maintain:** or **Achieve:**. The one ranked k of n achieve goals, in
|
||||
reading order, a sub-goal such as 1.1 included, weighs (1/k) / (1 + 1/2 + ... + 1/n). Only an item
|
||||
marked defect may name a maintain goal, the one it restores, which weighs as the heaviest achieve
|
||||
goal.
|
||||
- The bar is judged on the Score as shown, to one decimal.
|
||||
- A new item takes Next ID, and Next ID then goes up by one; every ID stays below it.
|
||||
- An item's R, S and C are whole numbers from 1 to 10. C, how hard the change is to get right, stays
|
||||
@@ -83,8 +83,6 @@ 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 |"
|
||||
# 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"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"
|
||||
@@ -96,9 +94,9 @@ class Scoring:
|
||||
formula: ast.Expression
|
||||
bar: float
|
||||
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 position in README.md.
|
||||
# README.md's goals in reading order, each with its mark.
|
||||
goals: dict[str, Mark]
|
||||
# The weight of each goal an item may name: in OLD_SHAPE every goal, at the weight todo.md states; else each goal goal_weights weighs.
|
||||
weights: dict[str, float]
|
||||
|
||||
|
||||
@@ -222,7 +220,7 @@ def notes(items: list[Item], scoring: Scoring) -> list[str]:
|
||||
if scoring.shape is OLD_SHAPE:
|
||||
return [RESHAPE] + dropped
|
||||
# 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"]
|
||||
unweighed = [] if any(scoring.weights.values()) else ["README.md marks no goal **Achieve:**, so every item scores V 0"]
|
||||
return unweighed + dropped
|
||||
|
||||
|
||||
@@ -237,14 +235,14 @@ def blocked_through(id_: int, items: list[Item]) -> set[int]:
|
||||
|
||||
|
||||
def ordered(items: list[Item], scoring: Scoring) -> list[tuple[Item, float]] | Failure:
|
||||
"""Each item with its score, by release, then security first and defect next, then by score from highest, then by ID; then each blocker above every item it blocks."""
|
||||
"""Each item with its score, by release, then security first, then by score from highest, then by ID; then each blocker above every item it blocks."""
|
||||
by_score = []
|
||||
for item in items:
|
||||
value = score(scoring.formula, item, scoring)
|
||||
if isinstance(value, Failure):
|
||||
return value
|
||||
by_score.append((item, value))
|
||||
by_score.sort(key=lambda pair: (pair[0].release, FIRST.get(pair[0].exempt, len(FIRST)), -pair[1], pair[0].id))
|
||||
by_score.sort(key=lambda pair: (pair[0].release, pair[0].exempt != "security", -pair[1], pair[0].id))
|
||||
return blockers_first(by_score)
|
||||
|
||||
|
||||
@@ -273,10 +271,10 @@ def read_scoring(text: str, lines: list[str], readme: str, shape: Shape) -> Scor
|
||||
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 position in README.md")
|
||||
else:
|
||||
weights = achieve_weights(goals)
|
||||
weights = goal_weights(goals)
|
||||
if isinstance(weights, Failure):
|
||||
return weights
|
||||
return Scoring(shape, formula, bar, int(next_id), numbers, weights)
|
||||
return Scoring(shape, formula, bar, int(next_id), dict(goals), weights)
|
||||
|
||||
|
||||
def read_table(lines: list[str]) -> Table | Failure:
|
||||
@@ -412,13 +410,15 @@ def readme_goals(readme: str) -> list[tuple[str, Mark]] | Failure:
|
||||
return goals
|
||||
|
||||
|
||||
def achieve_weights(goals: list[tuple[str, Mark]]) -> dict[str, float] | Failure:
|
||||
"""Each achieve goal's sum-reciprocal weight: the one ranked k of n in reading order weighs (1/k) / (1 + 1/2 + ... + 1/n). Empty where README.md marks no goal **Achieve:**, so every item scores V 0 and only an exempt one passes the bar."""
|
||||
def goal_weights(goals: list[tuple[str, Mark]]) -> dict[str, float] | Failure:
|
||||
"""Each achieve goal's sum-reciprocal weight: the one ranked k of n in reading order weighs (1/k) / (1 + 1/2 + ... + 1/n). Each maintain goal weighs as the heaviest achieve goal, since a broken one outranks any achieve goal; only a defect that restores it may name it. Every weight is 0 where README.md marks no goal **Achieve:**, so every item scores V 0 and only an exempt one passes the bar."""
|
||||
if unmarked := [number for number, mark in goals if mark is None]:
|
||||
return Failure(f"README.md's goal {unmarked[0]} is marked neither **Maintain:** nor **Achieve:**; mark it, as ~/.claude/rules/goals-and-audience.md says, so rank_todo.py knows which goals score")
|
||||
achieve = [number for number, mark in goals if mark == "Achieve"]
|
||||
harmonic = sum(1 / rank for rank in range(1, len(achieve) + 1))
|
||||
return {number: 1 / rank / harmonic for rank, number in enumerate(achieve, 1)}
|
||||
weights = {number: 1 / rank / harmonic for rank, number in enumerate(achieve, 1)}
|
||||
heaviest = max(weights.values(), default=0.0)
|
||||
return weights | {number: heaviest for number, mark in goals if mark == "Maintain"}
|
||||
|
||||
|
||||
def cited_items(decisions: str) -> list[int]:
|
||||
@@ -550,8 +550,8 @@ def parse_item(row: str, scoring: Scoring, table: Table) -> Item | Failure:
|
||||
for goal, _ in item.moves:
|
||||
if goal not in scoring.goals:
|
||||
return Failure(f"item {item.id} cites goal {goal}, which README.md's ## Goals does not number")
|
||||
if goal not in scoring.weights:
|
||||
return Failure(f"item {item.id} cites goal {goal}, a maintain goal, which vetoes and never scores; name only the achieve goals it moves")
|
||||
if scoring.goals[goal] == "Maintain" and item.exempt != "defect":
|
||||
return Failure(f"item {item.id} cites goal {goal}, a maintain goal, which only a defect that restores it may name; name the achieve goals the item moves")
|
||||
return item
|
||||
|
||||
|
||||
|
||||
@@ -113,7 +113,7 @@ class Rank(unittest.TestCase):
|
||||
|
||||
def test_weighs_each_achieve_goal_by_its_sum_reciprocal_rank(self):
|
||||
readme = "## Goals\n\n1. **Achieve:** A.\n 1. **Maintain:** B.\n 2. **Achieve:** C.\n2. **Achieve:** D.\n"
|
||||
self.assertEqual({goal: round(weight, 4) for goal, weight in rank_todo.achieve_weights(rank_todo.readme_goals(readme)).items()}, {"1": 0.5455, "1.2": 0.2727, "2": 0.1818})
|
||||
self.assertEqual({goal: round(weight, 4) for goal, weight in rank_todo.goal_weights(rank_todo.readme_goals(readme)).items()}, {"1": 0.5455, "1.1": 0.5455, "1.2": 0.2727, "2": 0.1818})
|
||||
todo = TODO.replace("2.1 by 8, 1 by 6", "1.2 by 2, 2 by 3").replace("| 2.1 by 1 |", "| 1 by 1 |")
|
||||
ranked = self.ranked(todo, readme)
|
||||
self.assertIn("| **Make it fast, `a \\| b`.** | 3 | 8 | 3 | 1.2 by 2, 2 by 3 | 0.4 |", ranked.text)
|
||||
@@ -146,7 +146,7 @@ class Rank(unittest.TestCase):
|
||||
|
||||
def test_refuses_a_goal_it_cannot_weigh(self):
|
||||
cases = {
|
||||
(TODO.replace("2.1 by 8, 1 by 6", "1 by 8, 2 by 6"), README): "item 3 cites goal 2, a maintain goal, which vetoes and never scores; name only the achieve goals it moves",
|
||||
(TODO.replace("2.1 by 8, 1 by 6", "1 by 8, 2 by 6"), README): "item 3 cites goal 2, a maintain goal, which only a defect that restores it may name; name the achieve goals the item moves",
|
||||
(TODO.replace("2.1 by 8, 1 by 6", "2.1 by 8, 3 by 6"), README): "item 3 cites goal 3, which README.md's ## Goals does not number",
|
||||
(TODO.replace("2.1 by 8, 1 by 6", "2.1 by 8, 2.1 by 6"), README): "item 3 cites goal 2.1 twice; name each goal once",
|
||||
(TODO, README.replace("**Maintain:** Correct", "Correct")): "README.md's goal 2 is marked neither **Maintain:** nor **Achieve:**; mark it, as ~/.claude/rules/goals-and-audience.md says, so rank_todo.py knows which goals score",
|
||||
@@ -155,11 +155,14 @@ class Rank(unittest.TestCase):
|
||||
with self.subTest(reason=reason):
|
||||
self.assertEqual(self.ranked(todo, readme), Failure(reason))
|
||||
|
||||
def test_ranks_defects_after_security_and_before_the_rest(self):
|
||||
# Item 4, security, scores under the defect, so only the order of the groups puts it first.
|
||||
def test_ranks_security_first_whatever_it_scores_and_a_defect_by_its_score(self):
|
||||
todo = TODO.replace("| 2 | 0.1.0 | | |", "| 2 | 0.1.0 | | defect |").replace("| 9 | 2 | 3 | 2.1 by 1 |", "| 9 | 8 | 3 | 2.1 by 1 |")
|
||||
rows = [line.split(" | ")[0] for line in self.ranked(todo).text.splitlines() if line.startswith("| ") and " | 0." in line]
|
||||
self.assertEqual(rows, ["| 4", "| 2", "| 3", "| 5", "| 1"])
|
||||
self.assertEqual(rows, ["| 4", "| 3", "| 2", "| 5", "| 1"])
|
||||
|
||||
def test_weighs_the_maintain_goal_a_defect_restores_as_the_heaviest_achieve_goal(self):
|
||||
ranked = self.ranked(TODO.replace("| 2 | 0.1.0 | | | **Tighten the tests.** | 2 | 4 | 3 | 2.1 by 1 |", "| 2 | 0.1.0 | | defect | **Tighten the tests.** | 2 | 4 | 3 | 2 by 3 |"))
|
||||
self.assertIn("| **Tighten the tests.** | 2 | 4 | 3 | 2 by 3 | 12.5 |", ranked.text)
|
||||
|
||||
def test_refuses_a_goal_named_beside_its_own_sub_goal(self):
|
||||
readme = "## Goals\n\n1. **Achieve:** A.\n 1. **Maintain:** B.\n 2. **Achieve:** C.\n2. **Achieve:** D.\n"
|
||||
|
||||
Reference in New Issue
Block a user