26 lines
1.3 KiB
Python
26 lines
1.3 KiB
Python
import decimal
|
|
|
|
from comprehension_history import DIMENSIONS
|
|
|
|
FLOOR = decimal.Decimal("7.0")
|
|
|
|
|
|
def fall_ruling(ruled: str, fell: list[str], found: list[decimal.Decimal]) -> tuple[str, str]:
|
|
"""The ruling once the scoring run has scored the dimensions that fell, and the line that says why: worse when one of their means is under the floor, so a chunk cannot trade one dimension below the floor for gains in the others."""
|
|
if under := [f"{name} {value}" for name, value in zip(DIMENSIONS, found) if name in fell and value < FLOOR]:
|
|
return "worse", f"Fell: {', '.join(fell)}. Under the floor of {FLOOR}: {', '.join(under)}, so the {ruled} ruling counts as worse."
|
|
return ruled, f"Fell: {', '.join(fell)}, each at or above the floor of {FLOOR}, so the {ruled} ruling stands."
|
|
|
|
|
|
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]
|