35 lines
2.0 KiB
Python
35 lines
2.0 KiB
Python
import decimal
|
|
|
|
from review_rules.comprehension_history import DIMENSIONS, FLOOR
|
|
from release_plan.todo_table import Item
|
|
|
|
# plan.scoring_run_due keys on these words too, so the floor item filed calls its own scoring run.
|
|
FLOOR_ITEM = "comprehension floor"
|
|
|
|
|
|
def means(lines: list[list[str]]) -> list[decimal.Decimal]:
|
|
"""The mean of each score across the lines, in DIMENSIONS' order, rounded half up to two decimals."""
|
|
return [mean([decimal.Decimal(score) for score in column]) for column in zip(*lines)]
|
|
|
|
|
|
def mean(values: list[decimal.Decimal]) -> decimal.Decimal:
|
|
return (sum(values, decimal.Decimal(0)) / len(values)).quantize(decimal.Decimal("0.01"), decimal.ROUND_HALF_UP)
|
|
|
|
|
|
def under_floor(found: list[decimal.Decimal]) -> list[str]:
|
|
return [f"{name} {value}" for name, value in zip(DIMENSIONS, found) if value < FLOOR]
|
|
|
|
|
|
def floor_step(found: list[decimal.Decimal], plan: list[Item], ships: list[int]) -> str | None:
|
|
"""What a scoring run under the floor asks next, None when no mean is under it. It aims at the lowest of the four dimensions, each of them where they tie, since the lowest caps the overall. An item in plan naming the comprehension floor is open unless ships holds its ID: the chunk shipping it still asks for the next one."""
|
|
if not under_floor(found):
|
|
return None
|
|
dimensions = dict(zip(DIMENSIONS[:-1], found))
|
|
lowest = [name for name, value in dimensions.items() if value == min(dimensions.values())]
|
|
names = " and ".join(filter(None, [", ".join(lowest[:-1]), lowest[-1]]))
|
|
aim = f"{names}, the lowest dimension{'s' if len(lowest) > 1 else ''}"
|
|
rule = 'as larv-review §3 → "Floor item" says.'
|
|
if open_items := [item for item in plan if FLOOR_ITEM in item.tagline.lower() and item.id not in ships]:
|
|
return f"Next: refresh item {open_items[0].id}, which names the comprehension floor, to lift {aim}, with this run's places, and file no other, {rule}"
|
|
return f"Next: file one item naming the comprehension floor, a refactor lifting {aim}, to {FLOOR}, {rule}"
|