Answer architecture round 2: 0 🔴, 0 🟡; one owner for the formula's goal term

This commit is contained in:
2026-10-16 00:43:01 +02:00
parent e2fe71b842
commit 11f4c5ab17
+14 -10
View File
@@ -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")