Syntrex commited on
Commit
9c8a3e6
·
verified ·
1 Parent(s): 1503c02

Update engine/live_game_engine.py

Browse files
Files changed (1) hide show
  1. engine/live_game_engine.py +33 -0
engine/live_game_engine.py CHANGED
@@ -193,6 +193,39 @@ def _extract_upcoming_hitters(
193
 
194
  return on_deck, in_hole, three_away
195
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
196
 
197
  def enrich_game_from_live_feed(game: dict[str, Any], feed: dict[str, Any]) -> dict[str, Any]:
198
  out = dict(game)
 
193
 
194
  return on_deck, in_hole, three_away
195
 
196
+ def derive_feed_status(
197
+ feed: dict[str, Any],
198
+ inning_half: str,
199
+ current_inning: int | None,
200
+ fallback: str = "",
201
+ ) -> str:
202
+ game_data = feed.get("gameData", {}) or {}
203
+ status_info = game_data.get("status", {}) or {}
204
+
205
+ abstract_state = str(status_info.get("abstractGameState", "") or "").strip().lower()
206
+ detailed_state = str(status_info.get("detailedState", "") or "").strip()
207
+
208
+ if abstract_state == "final":
209
+ return "Final"
210
+
211
+ if detailed_state.lower() in {"final", "game over", "completed", "ended"}:
212
+ return "Final"
213
+
214
+ if abstract_state == "live":
215
+ formatted = format_status(inning_half, current_inning, "")
216
+ return formatted if formatted else (detailed_state or "Live")
217
+
218
+ if abstract_state == "preview":
219
+ return fallback if fallback else "Scheduled"
220
+
221
+ formatted = format_status(inning_half, current_inning, "")
222
+ if formatted:
223
+ return formatted
224
+
225
+ if detailed_state:
226
+ return detailed_state
227
+
228
+ return fallback
229
 
230
  def enrich_game_from_live_feed(game: dict[str, Any], feed: dict[str, Any]) -> dict[str, Any]:
231
  out = dict(game)