From 11f4c5ab1722cb8c7dce1260cd5cb6faf75ba2ad Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 16 Oct 2026 00:43:01 +0200 Subject: [PATCH] =?UTF-8?q?Answer=20architecture=20round=202:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=200=20=F0=9F=9F=A1;=20one=20owner=20for=20the=20f?= =?UTF-8?q?ormula's=20goal=20term?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/rank_todo.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/bin/rank_todo.py b/bin/rank_todo.py index 2118e034..fa8ab090 100755 --- a/bin/rank_todo.py +++ b/bin/rank_todo.py @@ -197,16 +197,15 @@ def rank(text: str, readme: str, decisions: str) -> Ranked | Failure: scored = ordered(items, scoring) if isinstance(scored, Failure): return scored - ranked = rank_details(rewrite_table(lines, table, scored), [item for item, _ in scored]) + ranked = rank_details(rewrite_table(lines, table, shape, scored), [item for item, _ in scored]) if isinstance(ranked, Failure): return ranked under_bar = [under_the_bar(item, value, scoring.bar, items) for item, value in scored if not item.exempt and round(value, 1) < scoring.bar] return Ranked(ranked, under_bar, notes(items, shape)) -def rewrite_table(lines: list[str], table: Table, scored: list[tuple[Item, float]]) -> str: - """lines with the table's rows in scored's order, under a header naming every column of its shape, so a table from before BLOCKED_BY joined gains the column.""" - shape = shape_of(table.columns) +def rewrite_table(lines: list[str], table: Table, shape: Shape, scored: list[tuple[Item, float]]) -> str: + """lines with the table's rows in scored's order, under a header naming every column of shape, so a table from before BLOCKED_BY joined gains the column.""" columns = shape.columns header = ["| " + " | ".join(columns) + " |", "|" + "---|" * len(columns)] rows = [render_item(item, value, shape) for item, value in scored] @@ -476,19 +475,24 @@ def evaluate(node: ast.AST, values: dict[str, float]) -> float: return math.nan +def goal_term(shape: Shape) -> str: + """The name of the formula's goal term, which score builds: W in OLD_SHAPE, V in the current shape.""" + return "W" if shape is OLD_SHAPE else "V" + + def variables(shape: Shape) -> tuple[str, ...]: - """The names the formula may use: the shape's scores but C, which stays out of the formula, and the goal term score builds, W in OLD_SHAPE and V in the current shape.""" - return tuple(sorted({*shape.score_columns} - {"C"} | {"W" if shape is OLD_SHAPE else "V"})) + """The names the formula may use: the shape's scores but C, which stays out of the formula, and its goal term.""" + return tuple(sorted({*shape.score_columns} - {"C"} | {goal_term(shape)})) def score(formula: ast.Expression, item: Item, scoring: Scoring) -> float | Failure: - if scoring.shape is OLD_SHAPE: + if goal_term(scoring.shape) == "W": # An item serving several goals is weighed by the heaviest; summing them would reward citing more. - variables = {**item.scores, "W": max(scoring.weights[goal] for goal, _ in item.moves)} + term = max(scoring.weights[goal] for goal, _ in item.moves) else: # Only an OLD_SHAPE item names a goal without a move. - variables = {**item.scores, "V": sum(scoring.weights[goal] * (by or 0) for goal, by in item.moves)} - value = evaluate(formula, variables) + term = sum(scoring.weights[goal] * (by or 0) for goal, by in item.moves) + value = evaluate(formula, {**item.scores, goal_term(scoring.shape): term}) return value if math.isfinite(value) else Failure(f"the formula gives item {item.id} no finite score")