mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-04-10 13:02:59 +00:00
mlb and milb recent game debugging
This commit is contained in:
@@ -964,6 +964,8 @@ class MiLBRecentManager(BaseMiLBManager):
|
||||
logger.warning("[MiLB] No games returned from API")
|
||||
return
|
||||
|
||||
logger.info(f"[MiLB] Fetched {len(games)} total games from API")
|
||||
|
||||
# Process games
|
||||
new_recent_games = []
|
||||
|
||||
@@ -990,20 +992,24 @@ class MiLBRecentManager(BaseMiLBManager):
|
||||
|
||||
if is_favorite_game:
|
||||
favorite_games_log.append(game_info)
|
||||
logger.info(f"[MiLB] Checking favorite team game: {game['away_team']} @ {game['home_team']}")
|
||||
logger.info(f"[MiLB] Found favorite team game: {game['away_team']} @ {game['home_team']}")
|
||||
logger.info(f"[MiLB] Game time (UTC): {game_time}")
|
||||
logger.info(f"[MiLB] Game status: {game['status']}, State: {game['status_state']}")
|
||||
logger.info(f"[MiLB] Scores: {game['away_team']} {game.get('away_score', 0)} - {game['home_team']} {game.get('home_score', 0)}")
|
||||
|
||||
# Use status_state to determine if game is final
|
||||
is_final = game['status_state'] in ['post', 'final', 'completed']
|
||||
|
||||
self.logger.info(f"[MiLB] Game Time: {game_time.isoformat()}")
|
||||
self.logger.info(f"[MiLB] Is final: {is_final}")
|
||||
self.logger.info(f"[MiLB] Status: {game['status']}, Status State: {game['status_state']}")
|
||||
|
||||
# Only add favorite team games that are final
|
||||
if is_final:
|
||||
new_recent_games.append(game)
|
||||
logger.info(f"[MiLB] Added favorite team game to recent list: {game['away_team']} @ {game['home_team']}")
|
||||
else:
|
||||
logger.info(f"[MiLB] Skipping non-final game: {game['away_team']} @ {game['home_team']} (Status: {game['status_state']})")
|
||||
|
||||
# Log summary of all games found
|
||||
logger.info(f"[MiLB] All games found ({len(all_games_log)}): {all_games_log}")
|
||||
@@ -1014,14 +1020,38 @@ class MiLBRecentManager(BaseMiLBManager):
|
||||
new_recent_games = new_recent_games[:self.recent_games_to_show]
|
||||
|
||||
if new_recent_games:
|
||||
logger.info(f"[MiLB] Found {len(new_recent_games)} recent games for favorite teams: {self.favorite_teams}")
|
||||
logger.info(f"[MiLB] Found {len(new_recent_games)} recent final games for favorite teams: {self.favorite_teams}")
|
||||
self.recent_games = new_recent_games
|
||||
if not self.current_game:
|
||||
self.current_game = self.recent_games[0]
|
||||
else:
|
||||
logger.info("[MiLB] No recent games found for favorite teams")
|
||||
self.recent_games = []
|
||||
self.current_game = None
|
||||
# Fallback: if no final games found, show any recent games for favorite teams
|
||||
logger.info("[MiLB] No final games found for favorite teams, checking for any recent games...")
|
||||
fallback_games = []
|
||||
for game_id, game in games.items():
|
||||
if (game['home_team'] in self.favorite_teams or game['away_team'] in self.favorite_teams):
|
||||
game_time_str = game['start_time'].replace('Z', '+00:00')
|
||||
game_time = datetime.fromisoformat(game_time_str)
|
||||
if game_time.tzinfo is None:
|
||||
game_time = game_time.replace(tzinfo=timezone.utc)
|
||||
|
||||
# Include any game from the last 7 days
|
||||
if game_time >= datetime.now(timezone.utc) - timedelta(days=7):
|
||||
fallback_games.append(game)
|
||||
logger.info(f"[MiLB] Added fallback game: {game['away_team']} @ {game['home_team']} (Status: {game['status_state']})")
|
||||
|
||||
fallback_games.sort(key=lambda x: x['start_time'], reverse=True)
|
||||
fallback_games = fallback_games[:self.recent_games_to_show]
|
||||
|
||||
if fallback_games:
|
||||
logger.info(f"[MiLB] Found {len(fallback_games)} fallback games for favorite teams")
|
||||
self.recent_games = fallback_games
|
||||
if not self.current_game:
|
||||
self.current_game = self.recent_games[0]
|
||||
else:
|
||||
logger.info("[MiLB] No recent games found for favorite teams (including fallback)")
|
||||
self.recent_games = []
|
||||
self.current_game = None
|
||||
|
||||
self.last_update = current_time
|
||||
|
||||
|
||||
@@ -436,9 +436,6 @@ class BaseNCAAFBManager: # Renamed class
|
||||
competitors = competition["competitors"]
|
||||
game_date_str = game_event["date"]
|
||||
|
||||
# Debug: Log the game we're processing
|
||||
self.logger.debug(f"[NCAAFB] Processing game event: {game_event.get('id')}")
|
||||
|
||||
start_time_utc = None
|
||||
try:
|
||||
start_time_utc = datetime.fromisoformat(game_date_str.replace("Z", "+00:00"))
|
||||
@@ -455,8 +452,13 @@ class BaseNCAAFBManager: # Renamed class
|
||||
home_abbr = home_team["team"]["abbreviation"]
|
||||
away_abbr = away_team["team"]["abbreviation"]
|
||||
|
||||
# Debug: Log the teams found
|
||||
self.logger.debug(f"[NCAAFB] Found teams: {away_abbr}@{home_abbr}, Status: {status['type']['name']}")
|
||||
# Check if this is a favorite team game BEFORE doing expensive logging
|
||||
is_favorite_game = (home_abbr in self.favorite_teams or away_abbr in self.favorite_teams)
|
||||
|
||||
# Only log debug info for favorite team games
|
||||
if is_favorite_game:
|
||||
self.logger.debug(f"[NCAAFB] Processing favorite team game: {game_event.get('id')}")
|
||||
self.logger.debug(f"[NCAAFB] Found teams: {away_abbr}@{home_abbr}, Status: {status['type']['name']}")
|
||||
|
||||
home_record = home_team.get('records', [{}])[0].get('summary', '') if home_team.get('records') else ''
|
||||
away_record = away_team.get('records', [{}])[0].get('summary', '') if away_team.get('records') else ''
|
||||
@@ -969,19 +971,26 @@ class NCAAFBRecentManager(BaseNCAAFBManager): # Renamed class
|
||||
|
||||
# Process games and filter for final games & favorite teams
|
||||
processed_games = []
|
||||
favorite_games_found = 0
|
||||
for event in events:
|
||||
game = self._extract_game_details(event)
|
||||
# Filter criteria: must be final
|
||||
if game and game['is_final']:
|
||||
processed_games.append(game)
|
||||
# Count favorite team games for logging
|
||||
if (game['home_abbr'] in self.favorite_teams or
|
||||
game['away_abbr'] in self.favorite_teams):
|
||||
favorite_games_found += 1
|
||||
|
||||
# Filter for favorite teams
|
||||
if self.favorite_teams:
|
||||
team_games = [game for game in processed_games
|
||||
team_games = [game for game in processed_games
|
||||
if game['home_abbr'] in self.favorite_teams or
|
||||
game['away_abbr'] in self.favorite_teams]
|
||||
self.logger.info(f"[NCAAFB Recent] Found {favorite_games_found} favorite team games out of {len(processed_games)} total final games")
|
||||
else:
|
||||
team_games = processed_games # Show all recent games if no favorites defined
|
||||
self.logger.info(f"[NCAAFB Recent] Found {len(processed_games)} total final games (no favorite teams configured)")
|
||||
|
||||
# Sort by game time, most recent first
|
||||
team_games.sort(key=lambda g: g.get('start_time_utc') or datetime.min.replace(tzinfo=timezone.utc), reverse=True)
|
||||
@@ -1181,39 +1190,29 @@ class NCAAFBUpcomingManager(BaseNCAAFBManager): # Renamed class
|
||||
# self.logger.info(f"[NCAAFB Upcoming] Processing {len(events)} events from shared data.") # Changed log prefix
|
||||
|
||||
processed_games = []
|
||||
favorite_games_found = 0
|
||||
for event in events:
|
||||
game = self._extract_game_details(event)
|
||||
# Filter criteria: must be upcoming ('pre' state)
|
||||
if game and game['is_upcoming']:
|
||||
processed_games.append(game)
|
||||
# Count favorite team games for logging
|
||||
if (game['home_abbr'] in self.favorite_teams or
|
||||
game['away_abbr'] in self.favorite_teams):
|
||||
favorite_games_found += 1
|
||||
|
||||
# Debug logging to see what games we have
|
||||
self.logger.debug(f"[NCAAFB Upcoming] Processed {len(processed_games)} upcoming games")
|
||||
for game in processed_games:
|
||||
self.logger.debug(f"[NCAAFB Upcoming] Game: {game['away_abbr']}@{game['home_abbr']} - Upcoming: {game['is_upcoming']}")
|
||||
|
||||
# Log all unique teams found for debugging
|
||||
all_teams = set()
|
||||
for game in processed_games:
|
||||
all_teams.add(game['away_abbr'])
|
||||
all_teams.add(game['home_abbr'])
|
||||
self.logger.debug(f"[NCAAFB Upcoming] All teams found in API: {sorted(all_teams)}")
|
||||
|
||||
# Debug: Log what events we received and what we extracted
|
||||
self.logger.debug(f"[NCAAFB Upcoming] Received {len(events)} events from shared data")
|
||||
for i, event in enumerate(events):
|
||||
self.logger.debug(f"[NCAAFB Upcoming] Event {i}: ID={event.get('id')}, Status={event.get('competitions', [{}])[0].get('status', {}).get('type', {}).get('name', 'unknown')}")
|
||||
# Summary logging instead of verbose debug
|
||||
self.logger.info(f"[NCAAFB Upcoming] Found {len(processed_games)} total upcoming games")
|
||||
|
||||
# Filter for favorite teams
|
||||
if self.favorite_teams:
|
||||
team_games = [game for game in processed_games
|
||||
if game['home_abbr'] in self.favorite_teams or
|
||||
game['away_abbr'] in self.favorite_teams]
|
||||
self.logger.debug(f"[NCAAFB Upcoming] After favorite team filtering: {len(team_games)} games")
|
||||
for game in team_games:
|
||||
self.logger.debug(f"[NCAAFB Upcoming] Favorite game: {game['away_abbr']}@{game['home_abbr']}")
|
||||
self.logger.info(f"[NCAAFB Upcoming] Found {favorite_games_found} favorite team games out of {len(processed_games)} total upcoming games")
|
||||
else:
|
||||
team_games = processed_games # Show all upcoming if no favorites
|
||||
self.logger.info(f"[NCAAFB Upcoming] Found {len(processed_games)} total upcoming games (no favorite teams configured)")
|
||||
|
||||
# Sort by game time, earliest first
|
||||
team_games.sort(key=lambda g: g.get('start_time_utc') or datetime.max.replace(tzinfo=timezone.utc))
|
||||
|
||||
@@ -1111,7 +1111,9 @@ class NFLUpcomingManager(BaseNFLManager): # Renamed class
|
||||
|
||||
# Limit to the specified number of upcoming games (default 10)
|
||||
upcoming_games_to_show = self.nfl_config.get("upcoming_games_to_show", 10)
|
||||
self.logger.debug(f"[NFL Upcoming] Limiting to {upcoming_games_to_show} games (found {len(team_games)} total)")
|
||||
team_games = team_games[:upcoming_games_to_show]
|
||||
self.logger.debug(f"[NFL Upcoming] After limiting: {len(team_games)} games")
|
||||
|
||||
# Log changes or periodically
|
||||
should_log = (
|
||||
|
||||
@@ -562,12 +562,13 @@ class OddsTickerManager:
|
||||
return
|
||||
|
||||
gap_width = 24 # Reduced gap between games
|
||||
total_width = sum(img.width for img in game_images) + gap_width * (len(game_images))
|
||||
display_width = self.display_manager.matrix.width # Add display width of black space at start
|
||||
total_width = display_width + sum(img.width for img in game_images) + gap_width * (len(game_images))
|
||||
height = self.display_manager.matrix.height
|
||||
|
||||
self.ticker_image = Image.new('RGB', (total_width, height), color=(0, 0, 0))
|
||||
|
||||
current_x = 0
|
||||
current_x = display_width # Start after the black space
|
||||
for idx, img in enumerate(game_images):
|
||||
self.ticker_image.paste(img, (current_x, 0))
|
||||
current_x += img.width
|
||||
|
||||
Reference in New Issue
Block a user