Rank todo.md items by value per cost, with a Moves column naming how far each item moves each achieve goal in place of A and G

This commit is contained in:
2026-10-16 00:10:59 +02:00
parent 450f0b3851
commit 016fbb2441
8 changed files with 524 additions and 363 deletions
+20 -8
View File
@@ -3,17 +3,20 @@ import re
from failure import Failure
# Each of R, S, C, A and G runs from 1 to TOP_SCORE.
# Each of R, S, C, A and G, and each goal's move, runs from 1 to TOP_SCORE.
TOP_SCORE = 10
EXEMPTIONS = ("", "decision", "defect", "owner", "principle", "question", "security")
# The column naming the items that block an item: each must be done before the item starts.
BLOCKED_BY = "Blocked by"
# The column naming each achieve goal an item moves and how far, such as `1.1 by 8, 1.2 by 5`.
MOVES = "Moves"
# The columns rank_todo writes, in order. A reader takes cells by column name, so it reads a table from before BLOCKED_BY or C joined, or with a column a later release adds.
COLUMNS = ("ID", "Release", BLOCKED_BY, "Exempt", "Item", "R", "S", "C", "A", "G", "Goals", "Score")
ITEMS_HEADER = "| " + " | ".join(COLUMNS) + " |"
DIVIDER = "|" + "---|" * len(COLUMNS)
COLUMNS = ("ID", "Release", BLOCKED_BY, "Exempt", "Item", "R", "S", "C", MOVES, "Score")
# The columns of a table from before MOVES replaced A, G and Goals, which rank_todo still ranks until its project reshapes it.
OLD_COLUMNS = ("ID", "Release", BLOCKED_BY, "Exempt", "Item", "R", "S", "C", "A", "G", "Goals", "Score")
# The columns without which no row can be read; a missing BLOCKED_BY reads as blocked by nothing, a missing C as no C.
NEEDED = ("ID", "Release", "Exempt", "Item", "R", "S", "A", "G", "Goals")
NEEDED = ("ID", "Release", "Exempt", "Item", "R", "S", MOVES)
OLD_NEEDED = ("ID", "Release", "Exempt", "Item", "R", "S", "A", "G", "Goals")
# How the items table's header opens, which tells it from the goal weights table.
HEADER_START = "| ID | Release |"
@@ -27,6 +30,8 @@ class Item:
scores: dict[str, int]
goals: tuple[str, ...]
blocked_by: tuple[int, ...]
# How far the item moves each of goals, in their order; empty in an old-shape table.
moves: tuple[int, ...] = ()
@property
def risk_and_complexity(self) -> int:
@@ -73,7 +78,8 @@ def items_table(lines: list[str]) -> Table | None | Failure:
return table
if repeated := sorted({column for column in table.columns if table.columns.count(column) > 1}):
return Failure(f"todo.md's items table names the column {', '.join(repeated)} twice; keep one")
if missing := [column for column in NEEDED if column not in table.columns]:
needed = NEEDED if MOVES in table.columns else OLD_NEEDED
if missing := [column for column in needed if column not in table.columns]:
return Failure(f"todo.md's items table has no {', '.join(missing)} column; rank_todo.py --help shows a valid one")
return table
@@ -132,6 +138,12 @@ def parse_row(row: str, columns: tuple[str, ...]) -> Item | Failure:
blocked_by = tuple(int(blocker) for blocker in blockers.split(", ") if blocker)
if int(id_) in blocked_by:
return Failure(f"item {id_} is blocked by itself; drop {id_} from its {BLOCKED_BY}")
cited = tuple(goal.strip() for goal in named["Goals"].split(","))
major, minor, patch = (int(part) for part in release.split("."))
return Item(int(id_), (major, minor, patch), exempt, tagline, scores, cited, blocked_by)
if MOVES not in named:
cited = tuple(goal.strip() for goal in named["Goals"].split(","))
return Item(int(id_), (major, minor, patch), exempt, tagline, scores, cited, blocked_by)
matches = [re.fullmatch(r"([0-9]+(?:\.[0-9]+)*) by ([0-9]+)", move) for move in named[MOVES].split(", ")] if named[MOVES] else []
moves = [(match.group(1), int(match.group(2))) for match in matches if match]
if len(moves) < len(matches) or any(not 1 <= by <= TOP_SCORE for _, by in moves):
return Failure(f"item {id_}'s {MOVES} {named[MOVES]!r} is not empty or goals such as `1.1 by 8, 1.2 by 5`, each moved by a whole number from 1 to {TOP_SCORE}")
return Item(int(id_), (major, minor, patch), exempt, tagline, scores, tuple(goal for goal, _ in moves), blocked_by, tuple(by for _, by in moves))