changes to fildering and processing of MILB live games

This commit is contained in:
Chuck
2025-08-09 13:26:18 -05:00
parent 3ba0ec2041
commit 71bb616b76

View File

@@ -425,6 +425,7 @@ class BaseMiLBManager:
if not self.favorite_teams or is_favorite_game: if not self.favorite_teams or is_favorite_game:
status_obj = event['status'] status_obj = event['status']
status_state = status_obj.get('abstractGameState', 'Preview') # Changed default to 'Preview' status_state = status_obj.get('abstractGameState', 'Preview') # Changed default to 'Preview'
detailed_state = status_obj.get('detailedState', '')
# Map status to a consistent format using abstractGameState # Map status to a consistent format using abstractGameState
mapped_status = 'status_other' mapped_status = 'status_other'
@@ -448,6 +449,7 @@ class BaseMiLBManager:
'home_score': event['teams']['home'].get('score', 0), 'home_score': event['teams']['home'].get('score', 0),
'status': mapped_status, 'status': mapped_status,
'status_state': mapped_status_state, 'status_state': mapped_status_state,
'detailed_state': detailed_state,
'start_time': event.get('gameDate'), 'start_time': event.get('gameDate'),
'away_record': away_record_str, 'away_record': away_record_str,
'home_record': home_record_str 'home_record': home_record_str
@@ -809,8 +811,15 @@ class MiLBLiveManager(BaseMiLBManager):
# Find all live games (optionally filtering to favorites) # Find all live games (optionally filtering to favorites)
new_live_games = [] new_live_games = []
for game in games.values(): for game in games.values():
self.logger.debug(f"[MiLB] Game status check: {game['away_team']} @ {game['home_team']} - status_state='{game['status_state']}', status='{game['status']}'") self.logger.debug(f"[MiLB] Game status check: {game['away_team']} @ {game['home_team']} - status_state='{game['status_state']}', status='{game['status']}', detailed_state='{game.get('detailed_state','')}'")
if game['status_state'] == 'in' and game['status'] == 'status_in_progress': is_live_by_flags = (game['status_state'] == 'in' and game['status'] == 'status_in_progress')
detailed = str(game.get('detailed_state','')).lower()
is_live_by_detail = any(
token in detailed for token in [
'in progress', 'game in progress', 'top of the', 'bottom of the', 'warmup'
]
)
if is_live_by_flags or is_live_by_detail:
# Sanity check on time # Sanity check on time
game_date_str = game.get('start_time', '') game_date_str = game.get('start_time', '')
if game_date_str: if game_date_str:
@@ -818,11 +827,13 @@ class MiLBLiveManager(BaseMiLBManager):
game_date = datetime.fromisoformat(game_date_str.replace('Z', '+00:00')) game_date = datetime.fromisoformat(game_date_str.replace('Z', '+00:00'))
current_utc = datetime.now(timezone.utc) current_utc = datetime.now(timezone.utc)
hours_diff = (current_utc - game_date).total_seconds() / 3600 hours_diff = (current_utc - game_date).total_seconds() / 3600
# Accept slightly future-started games as live if detailed_state indicates in progress/warmup
future_grace_hours = 1.0 if is_live_by_detail else 0.0
if hours_diff > 24: if hours_diff > 24:
self.logger.warning(f"[MiLB] Skipping old game marked live: {game['away_team']} @ {game['home_team']}") self.logger.warning(f"[MiLB] Skipping old game marked live: {game['away_team']} @ {game['home_team']}")
continue continue
elif hours_diff < -1: elif hours_diff < -future_grace_hours:
self.logger.warning(f"[MiLB] Skipping future game marked live: {game['away_team']} @ {game['home_team']}") self.logger.warning(f"[MiLB] Skipping future game marked live: {game['away_team']} @ {game['home_team']} (starts in {abs(hours_diff):.2f}h)")
continue continue
except Exception as e: except Exception as e:
self.logger.warning(f"[MiLB] Could not parse game date {game_date_str}: {e}") self.logger.warning(f"[MiLB] Could not parse game date {game_date_str}: {e}")