mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-04-10 21:03:01 +00:00
all sports managers process recent and upcoming games as a function of game count instead of time (hours). Ensure all sports managers respect favorite team filtering if enabled
This commit is contained in:
@@ -51,7 +51,6 @@ class BaseNBAManager:
|
||||
self.current_game = None
|
||||
self.fonts = self._load_fonts()
|
||||
self.favorite_teams = self.nba_config.get("favorite_teams", [])
|
||||
self.recent_hours = self.nba_config.get("recent_game_hours", 72) # Default 72 hours
|
||||
|
||||
# Set logging level to INFO to reduce noise
|
||||
self.logger.setLevel(logging.INFO)
|
||||
@@ -691,6 +690,12 @@ class NBALiveManager(BaseNBAManager):
|
||||
self._fetch_odds(details)
|
||||
new_live_games.append(details)
|
||||
|
||||
# Filter for favorite teams only if the config is set
|
||||
if self.nba_config.get("show_favorite_teams_only", False) and self.favorite_teams:
|
||||
new_live_games = [game for game in new_live_games
|
||||
if game['home_abbr'] in self.favorite_teams or
|
||||
game['away_abbr'] in self.favorite_teams]
|
||||
|
||||
# Update game list and current game
|
||||
if new_live_games:
|
||||
self.live_games = new_live_games
|
||||
@@ -720,6 +725,7 @@ class NBARecentManager(BaseNBAManager):
|
||||
self.current_game_index = 0
|
||||
self.last_update = 0
|
||||
self.update_interval = 3600 # 1 hour for recent games
|
||||
self.recent_games_to_show = self.nba_config.get("recent_games_to_show", 5) # Number of most recent games to display
|
||||
self.last_game_switch = 0
|
||||
self.game_display_duration = 15 # Display each game for 15 seconds
|
||||
|
||||
@@ -750,7 +756,9 @@ class NBARecentManager(BaseNBAManager):
|
||||
else:
|
||||
team_games = new_recent_games
|
||||
|
||||
# Sort games by start time, most recent first, then limit to recent_games_to_show
|
||||
team_games.sort(key=lambda x: x.get('start_time_utc') or datetime.min.replace(tzinfo=timezone.utc), reverse=True)
|
||||
team_games = team_games[:self.recent_games_to_show]
|
||||
self.recent_games = team_games
|
||||
|
||||
if self.recent_games:
|
||||
@@ -796,6 +804,7 @@ class NBAUpcomingManager(BaseNBAManager):
|
||||
self.current_game_index = 0
|
||||
self.last_update = 0
|
||||
self.update_interval = 3600 # 1 hour for upcoming games
|
||||
self.upcoming_games_to_show = self.nba_config.get("upcoming_games_to_show", 5) # Number of upcoming games to display
|
||||
|
||||
def update(self):
|
||||
"""Update upcoming games data."""
|
||||
@@ -824,7 +833,9 @@ class NBAUpcomingManager(BaseNBAManager):
|
||||
else:
|
||||
team_games = new_upcoming_games
|
||||
|
||||
# Sort games by start time, soonest first, then limit to configured count
|
||||
team_games.sort(key=lambda x: x.get('start_time_utc') or datetime.max.replace(tzinfo=timezone.utc))
|
||||
team_games = team_games[:self.upcoming_games_to_show]
|
||||
self.upcoming_games = team_games
|
||||
|
||||
if self.upcoming_games:
|
||||
|
||||
@@ -607,6 +607,11 @@ class NCAABaseballLiveManager(BaseNCAABaseballManager):
|
||||
new_live_games = []
|
||||
for game in games.values():
|
||||
if game['status_state'] == 'in':
|
||||
# Filter for favorite teams only if the config is set
|
||||
if self.ncaa_baseball_config.get("show_favorite_teams_only", False) and self.favorite_teams:
|
||||
if not (game['home_team'] in self.favorite_teams or game['away_team'] in self.favorite_teams):
|
||||
continue
|
||||
|
||||
self._fetch_odds(game)
|
||||
try:
|
||||
game['home_score'] = int(game['home_score'])
|
||||
@@ -623,11 +628,13 @@ class NCAABaseballLiveManager(BaseNCAABaseballManager):
|
||||
|
||||
if should_log:
|
||||
if new_live_games:
|
||||
logger.info(f"[NCAABaseball] Found {len(new_live_games)} live games")
|
||||
filter_text = "favorite teams" if self.ncaa_baseball_config.get("show_favorite_teams_only", False) and self.favorite_teams else "all teams"
|
||||
logger.info(f"[NCAABaseball] Found {len(new_live_games)} live games involving {filter_text}")
|
||||
for game in new_live_games:
|
||||
logger.info(f"[NCAABaseball] Live game: {game['away_team']} vs {game['home_team']} - {game['inning_half']}{game['inning']}, {game['balls']}-{game['strikes']}")
|
||||
else:
|
||||
logger.info("[NCAABaseball] No live games found")
|
||||
filter_text = "favorite teams" if self.ncaa_baseball_config.get("show_favorite_teams_only", False) and self.favorite_teams else "criteria"
|
||||
logger.info(f"[NCAABaseball] No live games found matching {filter_text}")
|
||||
self.last_log_time = current_time
|
||||
|
||||
if new_live_games:
|
||||
@@ -844,7 +851,7 @@ class NCAABaseballRecentManager(BaseNCAABaseballManager):
|
||||
self.current_game_index = 0
|
||||
self.last_update = 0
|
||||
self.update_interval = self.ncaa_baseball_config.get('recent_update_interval', 3600)
|
||||
self.recent_hours = self.ncaa_baseball_config.get('recent_game_hours', 72)
|
||||
self.recent_games_to_show = self.ncaa_baseball_config.get('recent_games_to_show', 5) # Number of most recent games to display
|
||||
self.last_game_switch = 0
|
||||
self.game_display_duration = 10
|
||||
self.last_warning_time = 0
|
||||
@@ -866,10 +873,6 @@ class NCAABaseballRecentManager(BaseNCAABaseballManager):
|
||||
return
|
||||
|
||||
new_recent_games = []
|
||||
now = datetime.now(timezone.utc)
|
||||
recent_cutoff = now - timedelta(hours=self.recent_hours)
|
||||
|
||||
logger.info(f"[NCAABaseball] Time window: {recent_cutoff} to {now}")
|
||||
|
||||
for game_id, game in games.items():
|
||||
game_time_str = game['start_time'].replace('Z', '+00:00')
|
||||
@@ -884,12 +887,10 @@ class NCAABaseballRecentManager(BaseNCAABaseballManager):
|
||||
logger.info(f"[NCAABaseball] Game status: {game['status']}, State: {game['status_state']}")
|
||||
|
||||
is_final = game['status_state'] in ['post', 'final', 'completed']
|
||||
is_within_time = recent_cutoff <= game_time <= now
|
||||
|
||||
logger.info(f"[NCAABaseball] Is final: {is_final}")
|
||||
logger.info(f"[NCAABaseball] Is within time window: {is_within_time}")
|
||||
|
||||
if is_final and is_within_time:
|
||||
if is_final:
|
||||
self._fetch_odds(game)
|
||||
new_recent_games.append(game)
|
||||
logger.info(f"[NCAABaseball] Added favorite team game to recent list: {game['away_team']} @ {game['home_team']}")
|
||||
@@ -901,8 +902,11 @@ class NCAABaseballRecentManager(BaseNCAABaseballManager):
|
||||
team_games = new_recent_games
|
||||
|
||||
if team_games:
|
||||
logger.info(f"[NCAABaseball] Found {len(team_games)} recent games for favorite teams: {self.favorite_teams}")
|
||||
self.recent_games = sorted(team_games, key=lambda g: g.get('start_time'), reverse=True)
|
||||
# Sort by game time (most recent first), then limit to recent_games_to_show
|
||||
team_games = sorted(team_games, key=lambda g: g.get('start_time'), reverse=True)
|
||||
team_games = team_games[:self.recent_games_to_show]
|
||||
logger.info(f"[NCAABaseball] Found {len(team_games)} recent games for favorite teams (limited to {self.recent_games_to_show}): {self.favorite_teams}")
|
||||
self.recent_games = team_games
|
||||
if not self.current_game or self.current_game.get('id') not in [g.get('id') for g in self.recent_games]:
|
||||
self.current_game_index = 0
|
||||
self.current_game = self.recent_games[0] if self.recent_games else None
|
||||
@@ -951,6 +955,7 @@ class NCAABaseballUpcomingManager(BaseNCAABaseballManager):
|
||||
self.current_game_index = 0
|
||||
self.last_update = 0
|
||||
self.update_interval = self.ncaa_baseball_config.get('upcoming_update_interval', 3600)
|
||||
self.upcoming_games_to_show = self.ncaa_baseball_config.get('upcoming_games_to_show', 5) # Number of upcoming games to display
|
||||
self.last_warning_time = 0
|
||||
self.warning_cooldown = 300
|
||||
self.last_game_switch = 0
|
||||
@@ -968,9 +973,6 @@ class NCAABaseballUpcomingManager(BaseNCAABaseballManager):
|
||||
if games:
|
||||
new_upcoming_games = []
|
||||
now = datetime.now(timezone.utc)
|
||||
upcoming_cutoff = now + timedelta(hours=24)
|
||||
|
||||
logger.info(f"[NCAABaseball] Looking for games between {now} and {upcoming_cutoff}")
|
||||
|
||||
for game in games.values():
|
||||
is_favorite_game = (game['home_team'] in self.favorite_teams or game['away_team'] in self.favorite_teams)
|
||||
@@ -982,13 +984,13 @@ class NCAABaseballUpcomingManager(BaseNCAABaseballManager):
|
||||
logger.info(f"[NCAABaseball] Checking favorite upcoming game: {game['away_team']} @ {game['home_team']} at {game_time}")
|
||||
logger.info(f"[NCAABaseball] Game status: {game['status']}, State: {game['status_state']}")
|
||||
|
||||
is_within_time = now <= game_time <= upcoming_cutoff
|
||||
is_upcoming_state = game['status_state'] not in ['post', 'final', 'completed'] and game['status'] == 'status_scheduled'
|
||||
is_future = game_time > now
|
||||
|
||||
logger.info(f"[NCAABaseball] Within time: {is_within_time}")
|
||||
logger.info(f"[NCAABaseball] Is upcoming state: {is_upcoming_state}")
|
||||
logger.info(f"[NCAABaseball] Is future: {is_future}")
|
||||
|
||||
if is_within_time and is_upcoming_state:
|
||||
if is_upcoming_state and is_future:
|
||||
self._fetch_odds(game)
|
||||
new_upcoming_games.append(game)
|
||||
logger.info(f"[NCAABaseball] Added favorite team game to upcoming list: {game['away_team']} @ {game['home_team']}")
|
||||
@@ -1000,8 +1002,11 @@ class NCAABaseballUpcomingManager(BaseNCAABaseballManager):
|
||||
team_games = new_upcoming_games
|
||||
|
||||
if team_games:
|
||||
logger.info(f"[NCAABaseball] Found {len(team_games)} upcoming games for favorite teams")
|
||||
self.upcoming_games = sorted(team_games, key=lambda g: g.get('start_time'))
|
||||
# Sort by game time (soonest first), then limit to configured count
|
||||
team_games = sorted(team_games, key=lambda g: g.get('start_time'))
|
||||
team_games = team_games[:self.upcoming_games_to_show]
|
||||
logger.info(f"[NCAABaseball] Found {len(team_games)} upcoming games for favorite teams (limited to {self.upcoming_games_to_show})")
|
||||
self.upcoming_games = team_games
|
||||
if not self.current_game or self.current_game.get('id') not in [g.get('id') for g in self.upcoming_games]:
|
||||
self.current_game_index = 0
|
||||
self.current_game = self.upcoming_games[0] if self.upcoming_games else None
|
||||
|
||||
@@ -51,7 +51,6 @@ class BaseNCAAMBasketballManager:
|
||||
self.current_game = None
|
||||
self.fonts = self._load_fonts()
|
||||
self.favorite_teams = self.ncaam_basketball_config.get("favorite_teams", [])
|
||||
self.recent_hours = self.ncaam_basketball_config.get("recent_game_hours", 72) # Default 72 hours
|
||||
|
||||
# Set logging level to INFO to reduce noise
|
||||
self.logger.setLevel(logging.INFO)
|
||||
@@ -391,13 +390,6 @@ class BaseNCAAMBasketballManager:
|
||||
else:
|
||||
game_date = self.display_manager.format_date_with_ordinal(local_time)
|
||||
|
||||
# Calculate if game is within recent window
|
||||
is_within_window = False
|
||||
if start_time_utc:
|
||||
cutoff_time = datetime.now(self._get_timezone()) - timedelta(hours=self.recent_hours)
|
||||
is_within_window = start_time_utc > cutoff_time
|
||||
self.logger.debug(f"[NCAAMBasketball] Game time: {start_time_utc}, Cutoff time: {cutoff_time}, Within window: {is_within_window}")
|
||||
|
||||
details = {
|
||||
"start_time_utc": start_time_utc,
|
||||
"status_text": status["type"]["shortDetail"],
|
||||
@@ -407,7 +399,6 @@ class BaseNCAAMBasketballManager:
|
||||
"is_halftime": status["type"]["state"] == "halftime",
|
||||
"is_final": status["type"]["state"] == "post",
|
||||
"is_upcoming": status["type"]["state"] == "pre",
|
||||
"is_within_window": is_within_window,
|
||||
"home_abbr": home_team["team"]["abbreviation"],
|
||||
"home_score": home_team.get("score", "0"),
|
||||
"home_record": home_record,
|
||||
@@ -683,6 +674,11 @@ class NCAAMBasketballLiveManager(BaseNCAAMBasketballManager):
|
||||
for event in data["events"]:
|
||||
details = self._extract_game_details(event)
|
||||
if details and details["is_live"]: # is_live includes 'in' and 'halftime'
|
||||
# Filter for favorite teams only if the config is set
|
||||
if self.ncaam_basketball_config.get("show_favorite_teams_only", False) and self.favorite_teams:
|
||||
if not (details["home_abbr"] in self.favorite_teams or details["away_abbr"] in self.favorite_teams):
|
||||
continue
|
||||
|
||||
self._fetch_odds(details)
|
||||
new_live_games.append(details)
|
||||
if self.favorite_teams and (
|
||||
@@ -704,7 +700,8 @@ class NCAAMBasketballLiveManager(BaseNCAAMBasketballManager):
|
||||
|
||||
if should_log:
|
||||
if new_live_games:
|
||||
self.logger.info(f"[NCAAMBasketball] Found {len(new_live_games)} live games")
|
||||
filter_text = "favorite teams" if self.ncaam_basketball_config.get("show_favorite_teams_only", False) and self.favorite_teams else "all teams"
|
||||
self.logger.info(f"[NCAAMBasketball] Found {len(new_live_games)} live games involving {filter_text}")
|
||||
for game in new_live_games:
|
||||
period = game.get('period', 0)
|
||||
if game.get('is_halftime'):
|
||||
@@ -723,7 +720,8 @@ class NCAAMBasketballLiveManager(BaseNCAAMBasketballManager):
|
||||
if has_favorite_team:
|
||||
self.logger.info("[NCAAMBasketball] Found live game(s) for favorite team(s)")
|
||||
else:
|
||||
self.logger.info("[NCAAMBasketball] No live games found")
|
||||
filter_text = "favorite teams" if self.ncaam_basketball_config.get("show_favorite_teams_only", False) and self.favorite_teams else "criteria"
|
||||
self.logger.info(f"[NCAAMBasketball] No live games found matching {filter_text}")
|
||||
self.last_log_time = current_time
|
||||
|
||||
if new_live_games:
|
||||
@@ -783,7 +781,7 @@ class NCAAMBasketballRecentManager(BaseNCAAMBasketballManager):
|
||||
self.current_game_index = 0
|
||||
self.last_update = 0
|
||||
self.update_interval = 3600 # 1 hour for recent games
|
||||
self.recent_hours = self.ncaam_basketball_config.get("recent_game_hours", 48)
|
||||
self.recent_games_to_show = self.ncaam_basketball_config.get("recent_games_to_show", 5) # Number of most recent games to display
|
||||
self.last_game_switch = 0
|
||||
self.game_display_duration = self.ncaam_basketball_config.get("recent_game_duration", 15) # Configurable duration
|
||||
self.last_log_time = 0
|
||||
@@ -815,8 +813,8 @@ class NCAAMBasketballRecentManager(BaseNCAAMBasketballManager):
|
||||
new_recent_games = []
|
||||
for event in events:
|
||||
game = self._extract_game_details(event)
|
||||
# Filter for recent games: must be final and within the time window
|
||||
if game and game['is_final'] and game['is_within_window']:
|
||||
# Filter for recent games: must be final
|
||||
if game and game['is_final']:
|
||||
self._fetch_odds(game)
|
||||
new_recent_games.append(game)
|
||||
|
||||
@@ -828,8 +826,9 @@ class NCAAMBasketballRecentManager(BaseNCAAMBasketballManager):
|
||||
else:
|
||||
new_team_games = new_recent_games
|
||||
|
||||
# Sort by game time (most recent first)
|
||||
# Sort by game time (most recent first), then limit to recent_games_to_show
|
||||
new_team_games.sort(key=lambda g: g.get('start_time_utc', datetime.min.replace(tzinfo=timezone.utc)), reverse=True)
|
||||
new_team_games = new_team_games[:self.recent_games_to_show]
|
||||
|
||||
# Only log if there's a change in games or enough time has passed
|
||||
should_log = (
|
||||
@@ -840,7 +839,7 @@ class NCAAMBasketballRecentManager(BaseNCAAMBasketballManager):
|
||||
|
||||
if should_log:
|
||||
if new_team_games:
|
||||
self.logger.info(f"[NCAAMBasketball] Found {len(new_team_games)} recent games for favorite teams")
|
||||
self.logger.info(f"[NCAAMBasketball] Found {len(new_team_games)} recent games for favorite teams (limited to {self.recent_games_to_show})")
|
||||
elif self.favorite_teams: # Only log "none found" if favorites are configured
|
||||
self.logger.info("[NCAAMBasketball] No recent games found for favorite teams")
|
||||
self.last_log_time = current_time
|
||||
@@ -918,6 +917,7 @@ class NCAAMBasketballUpcomingManager(BaseNCAAMBasketballManager):
|
||||
self.current_game_index = 0
|
||||
self.last_update = 0
|
||||
self.update_interval = 3600 # 1 hour for upcoming games
|
||||
self.upcoming_games_to_show = self.ncaam_basketball_config.get("upcoming_games_to_show", 5) # Number of upcoming games to display
|
||||
self.last_warning_time = 0
|
||||
self.warning_cooldown = 300 # Only show warning every 5 minutes
|
||||
self.last_game_switch = 0
|
||||
@@ -962,13 +962,14 @@ class NCAAMBasketballUpcomingManager(BaseNCAAMBasketballManager):
|
||||
else:
|
||||
team_games = new_upcoming_games
|
||||
|
||||
# Sort by game time (soonest first)
|
||||
# Sort by game time (soonest first), then limit to configured count
|
||||
team_games.sort(key=lambda g: g.get('start_time_utc', datetime.max.replace(tzinfo=timezone.utc)))
|
||||
team_games = team_games[:self.upcoming_games_to_show]
|
||||
|
||||
|
||||
if self._should_log("team_games_upcoming", 300):
|
||||
if team_games:
|
||||
self.logger.info(f"[NCAAMBasketball] Found {len(team_games)} upcoming games for favorite teams")
|
||||
self.logger.info(f"[NCAAMBasketball] Found {len(team_games)} upcoming games for favorite teams (limited to {self.upcoming_games_to_show})")
|
||||
elif self.favorite_teams: # Only log "none found" if favorites configured
|
||||
self.logger.info("[NCAAMBasketball] No upcoming games found for favorite teams")
|
||||
|
||||
|
||||
@@ -539,10 +539,10 @@ class NHLLiveManager(BaseNHLManager):
|
||||
|
||||
def update(self):
|
||||
"""Update live game data."""
|
||||
if not self.is_enabled: return
|
||||
current_time = time.time()
|
||||
# Use longer interval if no game data
|
||||
interval = self.no_data_interval if not self.live_games else self.update_interval
|
||||
|
||||
|
||||
if current_time - self.last_update >= interval:
|
||||
self.last_update = current_time
|
||||
|
||||
@@ -576,6 +576,12 @@ class NHLLiveManager(BaseNHLManager):
|
||||
self._fetch_odds(details)
|
||||
new_live_games.append(details)
|
||||
|
||||
# Filter for favorite teams only if the config is set
|
||||
if self.nhl_config.get("show_favorite_teams_only", False) and self.favorite_teams:
|
||||
new_live_games = [game for game in new_live_games
|
||||
if game['home_abbr'] in self.favorite_teams or
|
||||
game['away_abbr'] in self.favorite_teams]
|
||||
|
||||
# Only log if there's a change in games or enough time has passed
|
||||
should_log = (
|
||||
current_time - self.last_log_time >= self.log_interval or
|
||||
@@ -585,11 +591,13 @@ class NHLLiveManager(BaseNHLManager):
|
||||
|
||||
if should_log:
|
||||
if new_live_games:
|
||||
self.logger.info(f"[NHL] Found {len(new_live_games)} live games")
|
||||
filter_text = "favorite teams" if self.nhl_config.get("show_favorite_teams_only", False) and self.favorite_teams else "all teams"
|
||||
self.logger.info(f"[NHL] Found {len(new_live_games)} live games involving {filter_text}")
|
||||
for game in new_live_games:
|
||||
self.logger.info(f"[NHL] Live game: {game['away_abbr']} vs {game['home_abbr']} - Period {game['period']}, {game['clock']}")
|
||||
else:
|
||||
self.logger.info("[NHL] No live games found")
|
||||
filter_text = "favorite teams" if self.nhl_config.get("show_favorite_teams_only", False) and self.favorite_teams else "criteria"
|
||||
self.logger.info(f"[NHL] No live games found matching {filter_text}")
|
||||
self.last_log_time = current_time
|
||||
|
||||
if new_live_games:
|
||||
@@ -631,7 +639,7 @@ class NHLLiveManager(BaseNHLManager):
|
||||
# self.display(force_clear=True) # REMOVED: DisplayController handles this
|
||||
self.last_display_update = current_time # Track time for potential display update
|
||||
|
||||
def display(self, force_clear: bool = False):
|
||||
def display(self, force_clear=False):
|
||||
"""Display live game information."""
|
||||
if not self.current_game:
|
||||
return
|
||||
@@ -645,7 +653,7 @@ class NHLRecentManager(BaseNHLManager):
|
||||
self.current_game_index = 0
|
||||
self.last_update = 0
|
||||
self.update_interval = 300 # 5 minutes
|
||||
self.recent_hours = self.nhl_config.get("recent_game_hours", 48)
|
||||
self.recent_games_to_show = self.nhl_config.get("recent_games_to_show", 5) # Number of most recent games to display
|
||||
self.last_game_switch = 0
|
||||
self.game_display_duration = 15 # Display each game for 15 seconds
|
||||
self.logger.info(f"Initialized NHLRecentManager with {len(self.favorite_teams)} favorite teams")
|
||||
@@ -685,9 +693,11 @@ class NHLRecentManager(BaseNHLManager):
|
||||
else:
|
||||
team_games = processed_games
|
||||
|
||||
# Sort games by start time, most recent first, then limit to recent_games_to_show
|
||||
team_games.sort(key=lambda x: x.get('start_time_utc') or datetime.min.replace(tzinfo=timezone.utc), reverse=True)
|
||||
team_games = team_games[:self.recent_games_to_show]
|
||||
|
||||
self.logger.info(f"[NHL] Found {len(team_games)} recent games for favorite teams")
|
||||
self.logger.info(f"[NHL] Found {len(team_games)} recent games for favorite teams (limited to {self.recent_games_to_show})")
|
||||
|
||||
new_game_ids = {g['id'] for g in team_games}
|
||||
current_game_ids = {g['id'] for g in getattr(self, 'games_list', [])}
|
||||
@@ -740,6 +750,7 @@ class NHLUpcomingManager(BaseNHLManager):
|
||||
self.current_game_index = 0
|
||||
self.last_update = 0
|
||||
self.update_interval = 300 # 5 minutes
|
||||
self.upcoming_games_to_show = self.nhl_config.get("upcoming_games_to_show", 5) # Number of upcoming games to display
|
||||
self.last_log_time = 0
|
||||
self.log_interval = 300 # Only log status every 5 minutes
|
||||
self.last_warning_time = 0
|
||||
@@ -787,7 +798,9 @@ class NHLUpcomingManager(BaseNHLManager):
|
||||
else:
|
||||
team_games = new_upcoming_games
|
||||
|
||||
# Sort games by start time, soonest first, then limit to configured count
|
||||
team_games.sort(key=lambda x: x.get('start_time_utc') or datetime.max.replace(tzinfo=timezone.utc))
|
||||
team_games = team_games[:self.upcoming_games_to_show]
|
||||
|
||||
# Only log if there's a change in games or enough time has passed
|
||||
should_log = (
|
||||
@@ -798,7 +811,7 @@ class NHLUpcomingManager(BaseNHLManager):
|
||||
|
||||
if should_log:
|
||||
if team_games:
|
||||
self.logger.info(f"[NHL] Found {len(team_games)} upcoming games for favorite teams")
|
||||
self.logger.info(f"[NHL] Found {len(team_games)} upcoming games for favorite teams (limited to {self.upcoming_games_to_show})")
|
||||
for game in team_games:
|
||||
self.logger.info(f"[NHL] Upcoming game: {game['away_abbr']} vs {game['home_abbr']} - {game['game_date']} {game['game_time']}")
|
||||
else:
|
||||
|
||||
@@ -69,7 +69,8 @@ class BaseSoccerManager:
|
||||
self.fonts = self._load_fonts()
|
||||
self.favorite_teams = self.soccer_config.get("favorite_teams", [])
|
||||
self.target_leagues_config = self.soccer_config.get("leagues", list(LEAGUE_SLUGS.keys())) # Get target leagues from config
|
||||
self.recent_hours = self.soccer_config.get("recent_game_hours", 168) # Used for recent past AND upcoming future display window
|
||||
self.recent_games_to_show = self.soccer_config.get("recent_games_to_show", 5) # Number of most recent games to display
|
||||
self.upcoming_games_to_show = self.soccer_config.get("upcoming_games_to_show", 5) # Number of upcoming games to display
|
||||
self.upcoming_fetch_days = self.soccer_config.get("upcoming_fetch_days", 7) # Days ahead to fetch (default: tomorrow)
|
||||
self.team_map_file = self.soccer_config.get("team_map_file", "assets/data/team_league_map.json")
|
||||
self.team_map_update_days = self.soccer_config.get("team_map_update_days", 7) # How often to update the map
|
||||
@@ -92,6 +93,7 @@ class BaseSoccerManager:
|
||||
self.logger.info(f"Logo directory: {self.logo_dir}")
|
||||
self.logger.info(f"Configured target leagues: {self.target_leagues_config}")
|
||||
self.logger.info(f"Upcoming fetch days: {self.upcoming_fetch_days}") # Log new setting
|
||||
self.logger.info(f"Recent games to show: {self.recent_games_to_show}") # Log new setting
|
||||
self.logger.info(f"Team map file: {self.team_map_file}")
|
||||
self.logger.info(f"Team map update interval: {self.team_map_update_days} days")
|
||||
|
||||
@@ -519,12 +521,8 @@ class BaseSoccerManager:
|
||||
is_upcoming = status_type == "STATUS_SCHEDULED"
|
||||
is_halftime = status_type == "STATUS_HALFTIME"
|
||||
|
||||
# Calculate if game is within recent window
|
||||
is_within_window = False
|
||||
if start_time_utc:
|
||||
cutoff_time = datetime.now(self._get_timezone()) - timedelta(hours=self.recent_hours)
|
||||
is_within_window = start_time_utc > cutoff_time
|
||||
self.logger.debug(f"[Soccer] Game time: {start_time_utc}, Cutoff time: {cutoff_time}, Within window: {is_within_window}")
|
||||
# Note: is_within_window calculation removed as it's no longer used for filtering
|
||||
# Recent games are now filtered by count instead of time window
|
||||
|
||||
details = {
|
||||
"id": game_event["id"],
|
||||
@@ -535,7 +533,6 @@ class BaseSoccerManager:
|
||||
"is_live": is_live or is_halftime, # Treat halftime as live for display purposes
|
||||
"is_final": is_final,
|
||||
"is_upcoming": is_upcoming,
|
||||
"is_within_window": is_within_window,
|
||||
"home_abbr": home_team["team"]["abbreviation"],
|
||||
"home_score": home_team.get("score", "0"),
|
||||
"home_record": home_record,
|
||||
@@ -550,7 +547,7 @@ class BaseSoccerManager:
|
||||
"league_slug": league_slug
|
||||
}
|
||||
|
||||
self.logger.debug(f"[Soccer] Extracted game: {details['away_abbr']} {details['away_score']} @ {details['home_abbr']} {details['home_score']} ({details['game_clock_display']}) - League: {details['league']} - Final: {details['is_final']}, Upcoming: {details['is_upcoming']}, Live: {details['is_live']}, Within Window: {details['is_within_window']}")
|
||||
self.logger.debug(f"[Soccer] Extracted game: {details['away_abbr']} {details['away_score']} @ {details['home_abbr']} {details['home_score']} ({details['game_clock_display']}) - League: {details['league']} - Final: {details['is_final']}, Upcoming: {details['is_upcoming']}, Live: {details['is_live']}")
|
||||
|
||||
# Basic validation (logos handled in loading)
|
||||
if not details["home_abbr"] or not details["away_abbr"]:
|
||||
@@ -924,12 +921,10 @@ class SoccerRecentManager(BaseSoccerManager):
|
||||
|
||||
# Process and filter games
|
||||
new_recent_games = []
|
||||
now_utc = datetime.now(pytz.utc)
|
||||
cutoff_time = now_utc - timedelta(hours=self.recent_hours)
|
||||
|
||||
for event in data['events']:
|
||||
game = self._extract_game_details(event)
|
||||
if game and game['is_final'] and game.get('start_time_utc') and game['start_time_utc'] >= cutoff_time:
|
||||
if game and game['is_final'] and game.get('start_time_utc'):
|
||||
self._fetch_odds(game)
|
||||
new_recent_games.append(game)
|
||||
|
||||
@@ -939,15 +934,16 @@ class SoccerRecentManager(BaseSoccerManager):
|
||||
else:
|
||||
team_games = new_recent_games
|
||||
|
||||
# Sort games by start time, most recent first
|
||||
# Sort games by start time, most recent first, and limit to recent_games_to_show
|
||||
team_games.sort(key=lambda x: x['start_time_utc'], reverse=True)
|
||||
team_games = team_games[:self.recent_games_to_show]
|
||||
|
||||
# Update only if the list content changes
|
||||
new_ids = {g['id'] for g in team_games}
|
||||
current_ids = {g['id'] for g in self.games_list}
|
||||
|
||||
if new_ids != current_ids:
|
||||
self.logger.info(f"[Soccer] Found {len(team_games)} recent games matching criteria.")
|
||||
self.logger.info(f"[Soccer] Found {len(team_games)} recent games (showing {self.recent_games_to_show} most recent).")
|
||||
self.recent_games = team_games
|
||||
self.games_list = team_games
|
||||
|
||||
@@ -1030,13 +1026,12 @@ class SoccerUpcomingManager(BaseSoccerManager):
|
||||
# Process and filter games
|
||||
new_upcoming_games = []
|
||||
now_utc = datetime.now(pytz.utc)
|
||||
cutoff_time = now_utc + timedelta(hours=self.recent_hours) # Use recent_hours as upcoming window
|
||||
|
||||
for event in data['events']:
|
||||
game = self._extract_game_details(event)
|
||||
# Must be upcoming, have a start time, and be within the window
|
||||
# Must be upcoming and have a start time
|
||||
if game and game['is_upcoming'] and game.get('start_time_utc') and \
|
||||
game['start_time_utc'] >= now_utc and game['start_time_utc'] <= cutoff_time:
|
||||
game['start_time_utc'] >= now_utc:
|
||||
self._fetch_odds(game)
|
||||
new_upcoming_games.append(game)
|
||||
|
||||
@@ -1046,8 +1041,9 @@ class SoccerUpcomingManager(BaseSoccerManager):
|
||||
else:
|
||||
team_games = new_upcoming_games
|
||||
|
||||
# Sort games by start time, soonest first
|
||||
# Sort games by start time, soonest first, then limit to configured count
|
||||
team_games.sort(key=lambda x: x['start_time_utc'])
|
||||
team_games = team_games[:self.upcoming_games_to_show]
|
||||
|
||||
# Update only if the list content changes
|
||||
new_ids = {g['id'] for g in team_games}
|
||||
|
||||
Reference in New Issue
Block a user