HelpDesk / graders /score_utils.py
Freakdivi's picture
updating model.py
913b593
raw
history blame contribute delete
519 Bytes
import math
from typing import Any
MIN_SCORE = 0.001
MAX_SCORE = 0.999
def ensure_open_unit_interval(value: Any) -> float:
"""Return a native Python float strictly inside the open unit interval."""
try:
score = float(value)
except (TypeError, ValueError):
return MIN_SCORE
if not math.isfinite(score):
return MIN_SCORE
score = max(0.0, min(1.0, score))
if score <= 0.0:
return MIN_SCORE
if score >= 1.0:
return MAX_SCORE
return float(score)