import decimal from review_rules.comprehension_history import DIMENSIONS from plan.todo_table import Item # A floor item's tagline opens with this phrase, which a tagline quoting or mentioning the floor never does; a floor item's chunk runs a scoring run. FLOOR_ITEM = "Reach the comprehension floor:" def is_floor_item(item: Item) -> bool: """Whether the item's tagline, which keeps its `**` bold markers, opens with FLOOR_ITEM.""" return item.tagline.removeprefix("**").startswith(FLOOR_ITEM) 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], floor: decimal.Decimal) -> list[str]: """Each mean in found under floor, the project's readability floor, with its dimension's name.""" 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], floor: decimal.Decimal) -> 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, floor): 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 is_floor_item(item) 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}, with a tagline that opens with `{FLOOR_ITEM}`, until every mean reaches {floor}, {rule}"