mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-04-12 05:42:59 +00:00
fix NCAA FB cache error
This commit is contained in:
@@ -883,88 +883,79 @@ class NCAAFBRecentManager(BaseNCAAFBManager): # Renamed class
|
|||||||
|
|
||||||
self.last_update = current_time # Update time even if fetch fails
|
self.last_update = current_time # Update time even if fetch fails
|
||||||
|
|
||||||
# Check for cached processed games first
|
try:
|
||||||
cached_games = self._get_cached_processed_games('recent')
|
data = self._fetch_data() # Uses shared cache
|
||||||
if cached_games:
|
if not data or 'events' not in data:
|
||||||
self.logger.debug("[NCAAFB Recent] Using cached processed games")
|
self.logger.warning("[NCAAFB Recent] No events found in shared data.") # Changed log prefix
|
||||||
team_games = cached_games
|
if not self.games_list: self.current_game = None # Clear display if no games were showing
|
||||||
else:
|
return
|
||||||
try:
|
|
||||||
data = self._fetch_data() # Uses shared cache
|
|
||||||
if not data or 'events' not in data:
|
|
||||||
self.logger.warning("[NCAAFB Recent] No events found in shared data.") # Changed log prefix
|
|
||||||
if not self.games_list: self.current_game = None # Clear display if no games were showing
|
|
||||||
return
|
|
||||||
|
|
||||||
events = data['events']
|
events = data['events']
|
||||||
# self.logger.info(f"[NCAAFB Recent] Processing {len(events)} events from shared data.") # Changed log prefix
|
# self.logger.info(f"[NCAAFB Recent] Processing {len(events)} events from shared data.") # Changed log prefix
|
||||||
|
|
||||||
# Process games and filter for final games & favorite teams
|
# Process games and filter for final games & favorite teams
|
||||||
processed_games = []
|
processed_games = []
|
||||||
favorite_games_found = 0
|
favorite_games_found = 0
|
||||||
for event in events:
|
for event in events:
|
||||||
game = self._extract_game_details(event)
|
game = self._extract_game_details(event)
|
||||||
# Filter criteria: must be final
|
# Filter criteria: must be final
|
||||||
if game and game['is_final']:
|
if game and game['is_final']:
|
||||||
processed_games.append(game)
|
processed_games.append(game)
|
||||||
# Count favorite team games for logging
|
# Count favorite team games for logging
|
||||||
if (game['home_abbr'] in self.favorite_teams or
|
if (game['home_abbr'] in self.favorite_teams or
|
||||||
game['away_abbr'] in self.favorite_teams):
|
game['away_abbr'] in self.favorite_teams):
|
||||||
favorite_games_found += 1
|
favorite_games_found += 1
|
||||||
|
|
||||||
# Filter for favorite teams
|
# Filter for favorite teams
|
||||||
if self.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
|
if game['home_abbr'] in self.favorite_teams or
|
||||||
game['away_abbr'] in self.favorite_teams]
|
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")
|
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)
|
||||||
|
|
||||||
|
# Limit to the specified number of recent games
|
||||||
|
team_games = team_games[:self.recent_games_to_show]
|
||||||
|
|
||||||
|
# Check if the list of games to display has changed
|
||||||
|
new_game_ids = {g['id'] for g in team_games}
|
||||||
|
current_game_ids = {g['id'] for g in self.games_list}
|
||||||
|
|
||||||
|
if new_game_ids != current_game_ids:
|
||||||
|
self.logger.info(f"[NCAAFB Recent] Found {len(team_games)} final games within window for display.") # Changed log prefix
|
||||||
|
self.games_list = team_games
|
||||||
|
# Reset index if list changed or current game removed
|
||||||
|
if not self.current_game or not self.games_list or self.current_game['id'] not in new_game_ids:
|
||||||
|
self.current_game_index = 0
|
||||||
|
self.current_game = self.games_list[0] if self.games_list else None
|
||||||
|
self.last_game_switch = current_time # Reset switch timer
|
||||||
else:
|
else:
|
||||||
team_games = processed_games # Show all recent games if no favorites defined
|
# Try to maintain position if possible
|
||||||
self.logger.info(f"[NCAAFB Recent] Found {len(processed_games)} total final games (no favorite teams configured)")
|
try:
|
||||||
|
self.current_game_index = next(i for i, g in enumerate(self.games_list) if g['id'] == self.current_game['id'])
|
||||||
|
self.current_game = self.games_list[self.current_game_index] # Update data just in case
|
||||||
|
except StopIteration:
|
||||||
|
self.current_game_index = 0
|
||||||
|
self.current_game = self.games_list[0]
|
||||||
|
self.last_game_switch = current_time
|
||||||
|
|
||||||
# Sort by game time, most recent first
|
elif self.games_list:
|
||||||
team_games.sort(key=lambda g: g.get('start_time_utc') or datetime.min.replace(tzinfo=timezone.utc), reverse=True)
|
# List content is same, just update data for current game
|
||||||
|
self.current_game = self.games_list[self.current_game_index]
|
||||||
|
|
||||||
# Limit to the specified number of recent games
|
if not self.games_list:
|
||||||
team_games = team_games[:self.recent_games_to_show]
|
self.logger.info("[NCAAFB Recent] No relevant recent games found to display.") # Changed log prefix
|
||||||
|
self.current_game = None # Ensure display clears if no games
|
||||||
|
|
||||||
# Cache the processed games
|
except Exception as e:
|
||||||
self._cache_processed_games('recent', team_games)
|
self.logger.error(f"[NCAAFB Recent] Error updating recent games: {e}", exc_info=True) # Changed log prefix
|
||||||
|
# Don't clear current game on error, keep showing last known state
|
||||||
# Check if the list of games to display has changed
|
# self.current_game = None # Decide if we want to clear display on error
|
||||||
new_game_ids = {g['id'] for g in team_games}
|
|
||||||
current_game_ids = {g['id'] for g in self.games_list}
|
|
||||||
|
|
||||||
if new_game_ids != current_game_ids:
|
|
||||||
self.logger.info(f"[NCAAFB Recent] Found {len(team_games)} final games within window for display.") # Changed log prefix
|
|
||||||
self.games_list = team_games
|
|
||||||
# Reset index if list changed or current game removed
|
|
||||||
if not self.current_game or not self.games_list or self.current_game['id'] not in new_game_ids:
|
|
||||||
self.current_game_index = 0
|
|
||||||
self.current_game = self.games_list[0] if self.games_list else None
|
|
||||||
self.last_game_switch = current_time # Reset switch timer
|
|
||||||
else:
|
|
||||||
# Try to maintain position if possible
|
|
||||||
try:
|
|
||||||
self.current_game_index = next(i for i, g in enumerate(self.games_list) if g['id'] == self.current_game['id'])
|
|
||||||
self.current_game = self.games_list[self.current_game_index] # Update data just in case
|
|
||||||
except StopIteration:
|
|
||||||
self.current_game_index = 0
|
|
||||||
self.current_game = self.games_list[0]
|
|
||||||
self.last_game_switch = current_time
|
|
||||||
|
|
||||||
elif self.games_list:
|
|
||||||
# List content is same, just update data for current game
|
|
||||||
self.current_game = self.games_list[self.current_game_index]
|
|
||||||
|
|
||||||
if not self.games_list:
|
|
||||||
self.logger.info("[NCAAFB Recent] No relevant recent games found to display.") # Changed log prefix
|
|
||||||
self.current_game = None # Ensure display clears if no games
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
self.logger.error(f"[NCAAFB Recent] Error updating recent games: {e}", exc_info=True) # Changed log prefix
|
|
||||||
# Don't clear current game on error, keep showing last known state
|
|
||||||
# self.current_game = None # Decide if we want to clear display on error
|
|
||||||
|
|
||||||
def _draw_scorebug_layout(self, game: Dict, force_clear: bool = False) -> None:
|
def _draw_scorebug_layout(self, game: Dict, force_clear: bool = False) -> None:
|
||||||
"""Draw the layout for a recently completed NCAA FB game.""" # Updated docstring
|
"""Draw the layout for a recently completed NCAA FB game.""" # Updated docstring
|
||||||
@@ -1103,108 +1094,99 @@ class NCAAFBUpcomingManager(BaseNCAAFBManager): # Renamed class
|
|||||||
|
|
||||||
self.last_update = current_time
|
self.last_update = current_time
|
||||||
|
|
||||||
# Check for cached processed games first
|
try:
|
||||||
cached_games = self._get_cached_processed_games('upcoming')
|
data = self._fetch_data() # Uses shared cache
|
||||||
if cached_games:
|
if not data or 'events' not in data:
|
||||||
self.logger.debug("[NCAAFB Upcoming] Using cached processed games")
|
self.logger.warning("[NCAAFB Upcoming] No events found in shared data.") # Changed log prefix
|
||||||
team_games = cached_games
|
if not self.games_list: self.current_game = None
|
||||||
else:
|
return
|
||||||
try:
|
|
||||||
data = self._fetch_data() # Uses shared cache
|
|
||||||
if not data or 'events' not in data:
|
|
||||||
self.logger.warning("[NCAAFB Upcoming] No events found in shared data.") # Changed log prefix
|
|
||||||
if not self.games_list: self.current_game = None
|
|
||||||
return
|
|
||||||
|
|
||||||
events = data['events']
|
events = data['events']
|
||||||
# self.logger.info(f"[NCAAFB Upcoming] Processing {len(events)} events from shared data.") # Changed log prefix
|
# self.logger.info(f"[NCAAFB Upcoming] Processing {len(events)} events from shared data.") # Changed log prefix
|
||||||
|
|
||||||
processed_games = []
|
processed_games = []
|
||||||
favorite_games_found = 0
|
favorite_games_found = 0
|
||||||
for event in events:
|
for event in events:
|
||||||
game = self._extract_game_details(event)
|
game = self._extract_game_details(event)
|
||||||
# Filter criteria: must be upcoming ('pre' state)
|
# Filter criteria: must be upcoming ('pre' state)
|
||||||
if game and game['is_upcoming']:
|
if game and game['is_upcoming']:
|
||||||
# Only fetch odds for games that will be displayed
|
# Only fetch odds for games that will be displayed
|
||||||
if self.ncaa_fb_config.get("show_favorite_teams_only", False):
|
if self.ncaa_fb_config.get("show_favorite_teams_only", False):
|
||||||
if not self.favorite_teams:
|
if not self.favorite_teams:
|
||||||
continue
|
continue
|
||||||
if game['home_abbr'] not in self.favorite_teams and game['away_abbr'] not in self.favorite_teams:
|
if game['home_abbr'] not in self.favorite_teams and game['away_abbr'] not in self.favorite_teams:
|
||||||
continue
|
continue
|
||||||
processed_games.append(game)
|
processed_games.append(game)
|
||||||
# Count favorite team games for logging
|
# Count favorite team games for logging
|
||||||
if (game['home_abbr'] in self.favorite_teams or
|
if (game['home_abbr'] in self.favorite_teams or
|
||||||
game['away_abbr'] in self.favorite_teams):
|
game['away_abbr'] in self.favorite_teams):
|
||||||
favorite_games_found += 1
|
favorite_games_found += 1
|
||||||
if self.show_odds:
|
if self.show_odds:
|
||||||
self._fetch_odds(game)
|
self._fetch_odds(game)
|
||||||
|
|
||||||
# Summary logging instead of verbose debug
|
# Summary logging instead of verbose debug
|
||||||
self.logger.info(f"[NCAAFB Upcoming] Found {len(processed_games)} total upcoming games")
|
self.logger.info(f"[NCAAFB Upcoming] Found {len(processed_games)} total upcoming games")
|
||||||
|
|
||||||
# Filter for favorite teams only if the config is set
|
# Filter for favorite teams only if the config is set
|
||||||
if self.ncaa_fb_config.get("show_favorite_teams_only", False):
|
if self.ncaa_fb_config.get("show_favorite_teams_only", False):
|
||||||
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
|
if game['home_abbr'] in self.favorite_teams or
|
||||||
game['away_abbr'] in self.favorite_teams]
|
game['away_abbr'] in self.favorite_teams]
|
||||||
else:
|
else:
|
||||||
team_games = processed_games # Show all upcoming if no favorites
|
team_games = processed_games # Show all upcoming if no favorites
|
||||||
|
|
||||||
# Sort by game time, earliest first
|
# Sort by game time, earliest first
|
||||||
team_games.sort(key=lambda g: g.get('start_time_utc') or datetime.max.replace(tzinfo=timezone.utc))
|
team_games.sort(key=lambda g: g.get('start_time_utc') or datetime.max.replace(tzinfo=timezone.utc))
|
||||||
|
|
||||||
# Limit to the specified number of upcoming games
|
# Limit to the specified number of upcoming games
|
||||||
team_games = team_games[:self.upcoming_games_to_show]
|
team_games = team_games[:self.upcoming_games_to_show]
|
||||||
|
|
||||||
# Cache the processed games
|
# Log changes or periodically
|
||||||
self._cache_processed_games('upcoming', team_games)
|
should_log = (
|
||||||
|
current_time - self.last_log_time >= self.log_interval or
|
||||||
|
len(team_games) != len(self.games_list) or
|
||||||
|
any(g1['id'] != g2.get('id') for g1, g2 in zip(self.games_list, team_games)) or
|
||||||
|
(not self.games_list and team_games)
|
||||||
|
)
|
||||||
|
|
||||||
# Log changes or periodically
|
# Check if the list of games to display has changed
|
||||||
should_log = (
|
new_game_ids = {g['id'] for g in team_games}
|
||||||
current_time - self.last_log_time >= self.log_interval or
|
current_game_ids = {g['id'] for g in self.games_list}
|
||||||
len(team_games) != len(self.games_list) or
|
|
||||||
any(g1['id'] != g2.get('id') for g1, g2 in zip(self.games_list, team_games)) or
|
|
||||||
(not self.games_list and team_games)
|
|
||||||
)
|
|
||||||
|
|
||||||
# Check if the list of games to display has changed
|
if new_game_ids != current_game_ids:
|
||||||
new_game_ids = {g['id'] for g in team_games}
|
self.logger.info(f"[NCAAFB Upcoming] Found {len(team_games)} upcoming games within window for display.") # Changed log prefix
|
||||||
current_game_ids = {g['id'] for g in self.games_list}
|
self.games_list = team_games
|
||||||
|
if not self.current_game or not self.games_list or self.current_game['id'] not in new_game_ids:
|
||||||
|
self.current_game_index = 0
|
||||||
|
self.current_game = self.games_list[0] if self.games_list else None
|
||||||
|
self.last_game_switch = current_time
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
self.current_game_index = next(i for i, g in enumerate(self.games_list) if g['id'] == self.current_game['id'])
|
||||||
|
self.current_game = self.games_list[self.current_game_index]
|
||||||
|
except StopIteration:
|
||||||
|
self.current_game_index = 0
|
||||||
|
self.current_game = self.games_list[0]
|
||||||
|
self.last_game_switch = current_time
|
||||||
|
|
||||||
if new_game_ids != current_game_ids:
|
elif self.games_list:
|
||||||
self.logger.info(f"[NCAAFB Upcoming] Found {len(team_games)} upcoming games within window for display.") # Changed log prefix
|
self.current_game = self.games_list[self.current_game_index] # Update data
|
||||||
self.games_list = team_games
|
|
||||||
if not self.current_game or not self.games_list or self.current_game['id'] not in new_game_ids:
|
|
||||||
self.current_game_index = 0
|
|
||||||
self.current_game = self.games_list[0] if self.games_list else None
|
|
||||||
self.last_game_switch = current_time
|
|
||||||
else:
|
|
||||||
try:
|
|
||||||
self.current_game_index = next(i for i, g in enumerate(self.games_list) if g['id'] == self.current_game['id'])
|
|
||||||
self.current_game = self.games_list[self.current_game_index]
|
|
||||||
except StopIteration:
|
|
||||||
self.current_game_index = 0
|
|
||||||
self.current_game = self.games_list[0]
|
|
||||||
self.last_game_switch = current_time
|
|
||||||
|
|
||||||
elif self.games_list:
|
if not self.games_list:
|
||||||
self.current_game = self.games_list[self.current_game_index] # Update data
|
self.logger.info("[NCAAFB Upcoming] No relevant upcoming games found to display.") # Changed log prefix
|
||||||
|
self.current_game = None
|
||||||
|
|
||||||
if not self.games_list:
|
if should_log and not self.games_list:
|
||||||
self.logger.info("[NCAAFB Upcoming] No relevant upcoming games found to display.") # Changed log prefix
|
# Log favorite teams only if no games are found and logging is needed
|
||||||
self.current_game = None
|
self.logger.debug(f"[NCAAFB Upcoming] Favorite teams: {self.favorite_teams}") # Changed log prefix
|
||||||
|
self.logger.debug(f"[NCAAFB Upcoming] Total upcoming games before filtering: {len(processed_games)}") # Changed log prefix
|
||||||
|
self.last_log_time = current_time
|
||||||
|
elif should_log:
|
||||||
|
self.last_log_time = current_time
|
||||||
|
|
||||||
if should_log and not self.games_list:
|
except Exception as e:
|
||||||
# Log favorite teams only if no games are found and logging is needed
|
self.logger.error(f"[NCAAFB Upcoming] Error updating upcoming games: {e}", exc_info=True) # Changed log prefix
|
||||||
self.logger.debug(f"[NCAAFB Upcoming] Favorite teams: {self.favorite_teams}") # Changed log prefix
|
# self.current_game = None # Decide if clear on error
|
||||||
self.logger.debug(f"[NCAAFB Upcoming] Total upcoming games before filtering: {len(processed_games)}") # Changed log prefix
|
|
||||||
self.last_log_time = current_time
|
|
||||||
elif should_log:
|
|
||||||
self.last_log_time = current_time
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
self.logger.error(f"[NCAAFB Upcoming] Error updating upcoming games: {e}", exc_info=True) # Changed log prefix
|
|
||||||
# self.current_game = None # Decide if clear on error
|
|
||||||
|
|
||||||
def _draw_scorebug_layout(self, game: Dict, force_clear: bool = False) -> None:
|
def _draw_scorebug_layout(self, game: Dict, force_clear: bool = False) -> None:
|
||||||
"""Draw the layout for an upcoming NCAA FB game.""" # Updated docstring
|
"""Draw the layout for an upcoming NCAA FB game.""" # Updated docstring
|
||||||
|
|||||||
Reference in New Issue
Block a user