Syntrex commited on
Commit
eb08ec1
·
verified ·
1 Parent(s): f7a1d92

Update simulation/pitch_simulator.py

Browse files
Files changed (1) hide show
  1. simulation/pitch_simulator.py +12 -2
simulation/pitch_simulator.py CHANGED
@@ -9,6 +9,16 @@ from simulation.pa_outcome_sampler import (
9
  sample_zone_bucket,
10
  )
11
 
 
 
 
 
 
 
 
 
 
 
12
 
13
  def _clamp(value: float, low: float, high: float) -> float:
14
  return max(low, min(high, value))
@@ -48,8 +58,8 @@ def simulate_plate_appearance(
48
  hr_prob = _clamp(hr_prob, 0.005, 0.25)
49
  tb2p_prob = _clamp(tb2p_prob, 0.03, 0.45)
50
 
51
- start_balls = int(float(game_row.get("balls", 0) or 0))
52
- start_strikes = int(float(game_row.get("strikes", 0) or 0))
53
 
54
  hit_total = 0
55
  hr_total = 0
 
9
  sample_zone_bucket,
10
  )
11
 
12
+ def _safe_count_int(value: Any, default: int = 0) -> int:
13
+ try:
14
+ if value is None:
15
+ return default
16
+ text = str(value).strip().lower()
17
+ if text in {"", "nan", "none"}:
18
+ return default
19
+ return int(float(value))
20
+ except Exception:
21
+ return default
22
 
23
  def _clamp(value: float, low: float, high: float) -> float:
24
  return max(low, min(high, value))
 
58
  hr_prob = _clamp(hr_prob, 0.005, 0.25)
59
  tb2p_prob = _clamp(tb2p_prob, 0.03, 0.45)
60
 
61
+ start_balls = _safe_count_int(game_row.get("balls"), 0)
62
+ start_strikes = _safe_count_int(game_row.get("strikes"), 0)
63
 
64
  hit_total = 0
65
  hr_total = 0