mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-04-10 21:03:01 +00:00
Fix NCAA Football recent games to show truly recent games (last 14 days) instead of entire season
- Add date-based filtering to NCAAFBRecentManager - Only consider games from last 14 days as 'recent' - Prevents Week 1 games from showing when user wants yesterday's games - Fixes issue where recent_games_to_show: 1 would show old games instead of most recent
This commit is contained in:
@@ -992,13 +992,19 @@ class NCAAFBRecentManager(BaseNCAAFBManager): # Renamed class
|
|||||||
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
|
# Define date range for "recent" games (last 14 days)
|
||||||
|
now = datetime.now(timezone.utc)
|
||||||
|
recent_cutoff = now - timedelta(days=14)
|
||||||
|
|
||||||
|
# Process games and filter for final games, date range & 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 AND within recent date range
|
||||||
if game and game['is_final']:
|
if game and game['is_final']:
|
||||||
|
game_time = game.get('start_time_utc')
|
||||||
|
if game_time and game_time >= recent_cutoff:
|
||||||
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
|
||||||
@@ -1010,10 +1016,10 @@ class NCAAFBRecentManager(BaseNCAAFBManager): # Renamed class
|
|||||||
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 within last 14 days")
|
||||||
else:
|
else:
|
||||||
team_games = processed_games # Show all recent games if no favorites defined
|
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)")
|
self.logger.info(f"[NCAAFB Recent] Found {len(processed_games)} total final games within last 14 days (no favorite teams configured)")
|
||||||
|
|
||||||
# Sort by game time, most recent first
|
# 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)
|
team_games.sort(key=lambda g: g.get('start_time_utc') or datetime.min.replace(tzinfo=timezone.utc), reverse=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user