Files changed (1) hide show
  1. server/my_env_environment.py +12 -7
server/my_env_environment.py CHANGED
@@ -57,11 +57,14 @@ def _load_task_cases(difficulty: str) -> List[Dict[str, Any]]:
57
  ICD10_PATTERN = re.compile(r"^[A-Z]\d{2}(\.\d{1,4})?$", re.IGNORECASE)
58
  CPT_PATTERN = re.compile(r"^\d{5}$")
59
  HCPCS_PATTERN = re.compile(r"^[A-Z]\d{4}$", re.IGNORECASE)
60
- SCORE_EPSILON = 1e-4
61
 
62
 
63
  def _to_open_interval_score(value: float) -> float:
64
- """Map a score to the strict open interval (0, 1)."""
 
 
 
65
  try:
66
  score = float(value)
67
  except (TypeError, ValueError):
@@ -69,16 +72,18 @@ def _to_open_interval_score(value: float) -> float:
69
 
70
  if not math.isfinite(score):
71
  score = 0.0
72
- if score <= 0.0:
73
- return SCORE_EPSILON
74
- if score >= 1.0:
75
- return 1.0 - SCORE_EPSILON
76
  return score
77
 
78
 
79
  def _rounded_open_interval_score(value: float, ndigits: int = 4) -> float:
80
  """Round score while preserving strict open interval bounds."""
81
- return _to_open_interval_score(round(_to_open_interval_score(value), ndigits))
 
 
 
82
 
83
 
84
  def _rounded_component_score(value: float, ndigits: int = 4) -> float:
 
57
  ICD10_PATTERN = re.compile(r"^[A-Z]\d{2}(\.\d{1,4})?$", re.IGNORECASE)
58
  CPT_PATTERN = re.compile(r"^\d{5}$")
59
  HCPCS_PATTERN = re.compile(r"^[A-Z]\d{4}$", re.IGNORECASE)
60
+ SCORE_EPSILON = 1e-3
61
 
62
 
63
  def _to_open_interval_score(value: float) -> float:
64
+ """Map a score to the strict open interval (0, 1).
65
+
66
+ Guarantees the returned value satisfies 0 < value < 1.
67
+ """
68
  try:
69
  score = float(value)
70
  except (TypeError, ValueError):
 
72
 
73
  if not math.isfinite(score):
74
  score = 0.0
75
+
76
+ # Clamp into the safe open interval (SCORE_EPSILON, 1 - SCORE_EPSILON)
77
+ score = max(SCORE_EPSILON, min(1.0 - SCORE_EPSILON, score))
 
78
  return score
79
 
80
 
81
  def _rounded_open_interval_score(value: float, ndigits: int = 4) -> float:
82
  """Round score while preserving strict open interval bounds."""
83
+ clamped = _to_open_interval_score(value)
84
+ rounded = round(clamped, ndigits)
85
+ # Re-clamp after rounding to guarantee strict (0, 1)
86
+ return _to_open_interval_score(rounded)
87
 
88
 
89
  def _rounded_component_score(value: float, ndigits: int = 4) -> float: