generated from coulomb/repo-seed
44 lines
1.1 KiB
Python
44 lines
1.1 KiB
Python
from __future__ import annotations
|
|
|
|
from dataclasses import dataclass
|
|
|
|
from .models import ViabilityThreshold
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class ViabilityResult:
|
|
metric: str
|
|
value: float | None
|
|
threshold: ViabilityThreshold
|
|
passed: bool
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class ViabilityReport:
|
|
passed: bool
|
|
results: dict[str, ViabilityResult]
|
|
|
|
|
|
def evaluate_viability(
|
|
metrics: dict[str, float],
|
|
thresholds: dict[str, ViabilityThreshold],
|
|
) -> ViabilityReport:
|
|
results: dict[str, ViabilityResult] = {}
|
|
for name, threshold in thresholds.items():
|
|
value = metrics.get(name)
|
|
passed = value is not None
|
|
if value is not None and threshold.min is not None:
|
|
passed = passed and value >= threshold.min
|
|
if value is not None and threshold.max is not None:
|
|
passed = passed and value <= threshold.max
|
|
results[name] = ViabilityResult(
|
|
metric=name,
|
|
value=value,
|
|
threshold=threshold,
|
|
passed=passed,
|
|
)
|
|
return ViabilityReport(
|
|
passed=all(result.passed for result in results.values()),
|
|
results=results,
|
|
)
|