import decimal from review_rules.comprehension_history import DIMENSIONS, FLOOR from release_plan.todo_table import Item # A floor item's tagline holds these words, and plan.scoring_run_due keys on them too, so each floor item's chunk runs a 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: """The `Next:` line of a scoring run with a mean under the floor, None when no mean is under it (SKILL.md → "Floor item"). The line aims at the lowest of the four dimensions, or at each where they tie, since the lowest caps the overall. A floor item in plan is open unless ships holds its ID, so a chunk that ships one still files the next. """ 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 floor item {open_items[0].id} to lift {aim}, with this run's places, and file no other, {rule}" return f"Next: file one floor item, a refactor lifting {aim}, until every mean reaches {FLOOR}, {rule}"