mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-04-10 13:02:59 +00:00
update logic on all sports displays that upcoming and recent games to show are based on each team, not just the first X # of games found
This commit is contained in:
@@ -1502,8 +1502,27 @@ class MiLBRecentManager(BaseMiLBManager):
|
||||
logger.info(f"[MiLB] All games found ({len(all_games_log)}): {all_games_log}")
|
||||
logger.info(f"[MiLB] Favorite team games found ({len(favorite_games_log)}): {favorite_games_log}")
|
||||
|
||||
# Sort by game time (most recent first) and limit to recent_games_to_show
|
||||
# Sort by game time (most recent first) and apply per-team logic
|
||||
new_recent_games.sort(key=lambda x: x.get('start_time', ''), reverse=True)
|
||||
|
||||
# If showing favorite teams only, select one game per team
|
||||
if self.milb_config.get("show_favorite_teams_only", False):
|
||||
# Select one game per favorite team (most recent game for each team)
|
||||
team_games = []
|
||||
for team in self.favorite_teams:
|
||||
# Find games where this team is playing
|
||||
team_specific_games = [game for game in new_recent_games
|
||||
if game.get('home_team') == team or game.get('away_team') == team]
|
||||
|
||||
if team_specific_games:
|
||||
# Take the most recent (first in sorted list)
|
||||
team_games.append(team_specific_games[0])
|
||||
|
||||
# Sort the final list by game time (most recent first)
|
||||
team_games.sort(key=lambda x: x.get('start_time', ''), reverse=True)
|
||||
new_recent_games = team_games
|
||||
else:
|
||||
# Limit to configured number if not using favorite teams only
|
||||
new_recent_games = new_recent_games[:self.recent_games_to_show]
|
||||
|
||||
if new_recent_games:
|
||||
@@ -1716,8 +1735,27 @@ class MiLBUpcomingManager(BaseMiLBManager):
|
||||
self.logger.info(f"[MiLB] Added upcoming game: {game.get('away_team')} @ {game.get('home_team')} at {game_time}")
|
||||
self.logger.debug(f"[MiLB] Game data for upcoming: {game}")
|
||||
|
||||
# Sort by game time (soonest first) and limit to upcoming_games_to_show
|
||||
# Sort by game time (soonest first) and apply per-team logic
|
||||
new_upcoming_games.sort(key=lambda x: x.get('start_time', ''))
|
||||
|
||||
# If showing favorite teams only, select one game per team
|
||||
if self.milb_config.get("show_favorite_teams_only", False):
|
||||
# Select one game per favorite team (earliest upcoming game for each team)
|
||||
team_games = []
|
||||
for team in self.favorite_teams:
|
||||
# Find games where this team is playing
|
||||
team_specific_games = [game for game in new_upcoming_games
|
||||
if game.get('home_team') == team or game.get('away_team') == team]
|
||||
|
||||
if team_specific_games:
|
||||
# Take the earliest (first in sorted list)
|
||||
team_games.append(team_specific_games[0])
|
||||
|
||||
# Sort the final list by game time
|
||||
team_games.sort(key=lambda x: x.get('start_time', ''))
|
||||
new_upcoming_games = team_games
|
||||
else:
|
||||
# Limit to configured number if not using favorite teams only
|
||||
new_upcoming_games = new_upcoming_games[:self.upcoming_games_to_show]
|
||||
self.logger.info(f"[MiLB] Found {len(new_upcoming_games)} upcoming games after processing")
|
||||
|
||||
|
||||
@@ -1223,8 +1223,27 @@ class MLBRecentManager(BaseMLBManager):
|
||||
self.logger.info(f"[MLB] All games found ({len(all_games_log)}): {all_games_log}")
|
||||
self.logger.info(f"[MLB] Favorite team games found ({len(favorite_games_log)}): {favorite_games_log}")
|
||||
|
||||
# Sort by game time (most recent first) and limit to recent_games_to_show
|
||||
# Sort by game time (most recent first) and apply per-team logic
|
||||
new_recent_games.sort(key=lambda x: x['start_time'], reverse=True)
|
||||
|
||||
# If showing favorite teams only, select one game per team
|
||||
if self.mlb_config.get("show_favorite_teams_only", False):
|
||||
# Select one game per favorite team (most recent game for each team)
|
||||
team_games = []
|
||||
for team in self.favorite_teams:
|
||||
# Find games where this team is playing
|
||||
team_specific_games = [game for game in new_recent_games
|
||||
if game['home_team'] == team or game['away_team'] == team]
|
||||
|
||||
if team_specific_games:
|
||||
# Take the most recent (first in sorted list)
|
||||
team_games.append(team_specific_games[0])
|
||||
|
||||
# Sort the final list by game time (most recent first)
|
||||
team_games.sort(key=lambda x: x['start_time'], reverse=True)
|
||||
new_recent_games = team_games
|
||||
else:
|
||||
# Limit to configured number if not using favorite teams only
|
||||
new_recent_games = new_recent_games[:self.recent_games_to_show]
|
||||
|
||||
if new_recent_games:
|
||||
@@ -1345,8 +1364,27 @@ class MLBUpcomingManager(BaseMLBManager):
|
||||
else:
|
||||
self.logger.info(f"[MLB] Skipping game {game_id} - not upcoming.")
|
||||
|
||||
# Sort by game time (soonest first) and limit to upcoming_games_to_show
|
||||
# Sort by game time (soonest first) and apply per-team logic
|
||||
new_upcoming_games.sort(key=lambda x: x['start_time'])
|
||||
|
||||
# If showing favorite teams only, select one game per team
|
||||
if self.mlb_config.get("show_favorite_teams_only", False):
|
||||
# Select one game per favorite team (earliest upcoming game for each team)
|
||||
team_games = []
|
||||
for team in self.favorite_teams:
|
||||
# Find games where this team is playing
|
||||
team_specific_games = [game for game in new_upcoming_games
|
||||
if game['home_team'] == team or game['away_team'] == team]
|
||||
|
||||
if team_specific_games:
|
||||
# Take the earliest (first in sorted list)
|
||||
team_games.append(team_specific_games[0])
|
||||
|
||||
# Sort the final list by game time
|
||||
team_games.sort(key=lambda x: x['start_time'])
|
||||
new_upcoming_games = team_games
|
||||
else:
|
||||
# Limit to configured number if not using favorite teams only
|
||||
new_upcoming_games = new_upcoming_games[:self.upcoming_games_to_show]
|
||||
|
||||
if new_upcoming_games:
|
||||
|
||||
@@ -759,12 +759,27 @@ class NBARecentManager(BaseNBAManager):
|
||||
|
||||
# Filter for favorite teams only if the config is set
|
||||
if self.nba_config.get("show_favorite_teams_only", False):
|
||||
team_games = [game for game in new_recent_games
|
||||
# Get all games involving favorite teams
|
||||
favorite_team_games = [game for game in new_recent_games
|
||||
if game['home_abbr'] in self.favorite_teams or
|
||||
game['away_abbr'] in self.favorite_teams]
|
||||
|
||||
# Select one game per favorite team (most recent game for each team)
|
||||
team_games = []
|
||||
for team in self.favorite_teams:
|
||||
# Find games where this team is playing
|
||||
team_specific_games = [game for game in favorite_team_games
|
||||
if game['home_abbr'] == team or game['away_abbr'] == team]
|
||||
|
||||
if team_specific_games:
|
||||
# Sort by game time and take the most recent
|
||||
team_specific_games.sort(key=lambda g: g.get('start_time_utc') or datetime.min.replace(tzinfo=timezone.utc), reverse=True)
|
||||
team_games.append(team_specific_games[0])
|
||||
|
||||
# Sort the final list 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)
|
||||
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]
|
||||
@@ -838,12 +853,27 @@ class NBAUpcomingManager(BaseNBAManager):
|
||||
|
||||
# Filter for favorite teams only if the config is set
|
||||
if self.nba_config.get("show_favorite_teams_only", False):
|
||||
team_games = [game for game in new_upcoming_games
|
||||
# Get all games involving favorite teams
|
||||
favorite_team_games = [game for game in new_upcoming_games
|
||||
if game['home_abbr'] in self.favorite_teams or
|
||||
game['away_abbr'] in self.favorite_teams]
|
||||
|
||||
# Select one game per favorite team (earliest upcoming game for each team)
|
||||
team_games = []
|
||||
for team in self.favorite_teams:
|
||||
# Find games where this team is playing
|
||||
team_specific_games = [game for game in favorite_team_games
|
||||
if game['home_abbr'] == team or game['away_abbr'] == team]
|
||||
|
||||
if team_specific_games:
|
||||
# Sort by game time and take the earliest
|
||||
team_specific_games.sort(key=lambda g: g.get('start_time_utc') or datetime.max.replace(tzinfo=timezone.utc))
|
||||
team_games.append(team_specific_games[0])
|
||||
|
||||
# Sort the final list by game time
|
||||
team_games.sort(key=lambda g: g.get('start_time_utc') or datetime.max.replace(tzinfo=timezone.utc))
|
||||
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]
|
||||
|
||||
@@ -908,14 +908,32 @@ class NCAABaseballRecentManager(BaseNCAABaseballManager):
|
||||
|
||||
# Filter for favorite teams only if the config is set
|
||||
if self.ncaa_baseball_config.get("show_favorite_teams_only", False):
|
||||
team_games = [game for game in new_recent_games if game['home_team'] in self.favorite_teams or game['away_team'] in self.favorite_teams]
|
||||
# Get all games involving favorite teams
|
||||
favorite_team_games = [game for game in new_recent_games
|
||||
if game['home_team'] in self.favorite_teams or
|
||||
game['away_team'] in self.favorite_teams]
|
||||
|
||||
# Select one game per favorite team (most recent game for each team)
|
||||
team_games = []
|
||||
for team in self.favorite_teams:
|
||||
# Find games where this team is playing
|
||||
team_specific_games = [game for game in favorite_team_games
|
||||
if game['home_team'] == team or game['away_team'] == team]
|
||||
|
||||
if team_specific_games:
|
||||
# Sort by game time and take the most recent
|
||||
team_specific_games.sort(key=lambda g: g.get('start_time'), reverse=True)
|
||||
team_games.append(team_specific_games[0])
|
||||
|
||||
# Sort the final list by game time (most recent first)
|
||||
team_games.sort(key=lambda g: g.get('start_time'), reverse=True)
|
||||
else:
|
||||
team_games = new_recent_games
|
||||
|
||||
if team_games:
|
||||
# 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]
|
||||
|
||||
if team_games:
|
||||
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]:
|
||||
@@ -1010,14 +1028,32 @@ class NCAABaseballUpcomingManager(BaseNCAABaseballManager):
|
||||
|
||||
# Filter for favorite teams only if the config is set
|
||||
if self.ncaa_baseball_config.get("show_favorite_teams_only", False):
|
||||
team_games = [game for game in new_upcoming_games if game['home_team'] in self.favorite_teams or game['away_team'] in self.favorite_teams]
|
||||
# Get all games involving favorite teams
|
||||
favorite_team_games = [game for game in new_upcoming_games
|
||||
if game['home_team'] in self.favorite_teams or
|
||||
game['away_team'] in self.favorite_teams]
|
||||
|
||||
# Select one game per favorite team (earliest upcoming game for each team)
|
||||
team_games = []
|
||||
for team in self.favorite_teams:
|
||||
# Find games where this team is playing
|
||||
team_specific_games = [game for game in favorite_team_games
|
||||
if game['home_team'] == team or game['away_team'] == team]
|
||||
|
||||
if team_specific_games:
|
||||
# Sort by game time and take the earliest
|
||||
team_specific_games.sort(key=lambda g: g.get('start_time'))
|
||||
team_games.append(team_specific_games[0])
|
||||
|
||||
# Sort the final list by game time
|
||||
team_games.sort(key=lambda g: g.get('start_time'))
|
||||
else:
|
||||
team_games = new_upcoming_games
|
||||
|
||||
if team_games:
|
||||
# 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]
|
||||
|
||||
if team_games:
|
||||
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]:
|
||||
|
||||
@@ -828,12 +828,27 @@ class NCAAMBasketballRecentManager(BaseNCAAMBasketballManager):
|
||||
|
||||
# Filter for favorite teams only if the config is set
|
||||
if self.ncaam_basketball_config.get("show_favorite_teams_only", False):
|
||||
new_team_games = [game for game in new_recent_games
|
||||
# Get all games involving favorite teams
|
||||
favorite_team_games = [game for game in new_recent_games
|
||||
if game['home_abbr'] in self.favorite_teams or
|
||||
game['away_abbr'] in self.favorite_teams]
|
||||
|
||||
# Select one game per favorite team (most recent game for each team)
|
||||
new_team_games = []
|
||||
for team in self.favorite_teams:
|
||||
# Find games where this team is playing
|
||||
team_specific_games = [game for game in favorite_team_games
|
||||
if game['home_abbr'] == team or game['away_abbr'] == team]
|
||||
|
||||
if team_specific_games:
|
||||
# Sort by game time and take the most recent
|
||||
team_specific_games.sort(key=lambda g: g.get('start_time_utc', datetime.min.replace(tzinfo=timezone.utc)), reverse=True)
|
||||
new_team_games.append(team_specific_games[0])
|
||||
|
||||
# Sort the final list by game time (most recent first)
|
||||
new_team_games.sort(key=lambda g: g.get('start_time_utc', datetime.min.replace(tzinfo=timezone.utc)), reverse=True)
|
||||
else:
|
||||
new_team_games = new_recent_games
|
||||
|
||||
# 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]
|
||||
@@ -964,12 +979,27 @@ class NCAAMBasketballUpcomingManager(BaseNCAAMBasketballManager):
|
||||
|
||||
# Filter for favorite teams only if the config is set
|
||||
if self.ncaam_basketball_config.get("show_favorite_teams_only", False):
|
||||
team_games = [game for game in new_upcoming_games
|
||||
# Get all games involving favorite teams
|
||||
favorite_team_games = [game for game in new_upcoming_games
|
||||
if game['home_abbr'] in self.favorite_teams or
|
||||
game['away_abbr'] in self.favorite_teams]
|
||||
|
||||
# Select one game per favorite team (earliest upcoming game for each team)
|
||||
team_games = []
|
||||
for team in self.favorite_teams:
|
||||
# Find games where this team is playing
|
||||
team_specific_games = [game for game in favorite_team_games
|
||||
if game['home_abbr'] == team or game['away_abbr'] == team]
|
||||
|
||||
if team_specific_games:
|
||||
# Sort by game time and take the earliest
|
||||
team_specific_games.sort(key=lambda g: g.get('start_time_utc', datetime.max.replace(tzinfo=timezone.utc)))
|
||||
team_games.append(team_specific_games[0])
|
||||
|
||||
# Sort the final list by game time
|
||||
team_games.sort(key=lambda g: g.get('start_time_utc', datetime.max.replace(tzinfo=timezone.utc)))
|
||||
else:
|
||||
team_games = new_upcoming_games
|
||||
|
||||
# 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]
|
||||
|
||||
@@ -700,12 +700,27 @@ class NHLRecentManager(BaseNHLManager):
|
||||
|
||||
# Filter for favorite teams only if the config is set
|
||||
if self.nhl_config.get("show_favorite_teams_only", False):
|
||||
team_games = [game for game in processed_games
|
||||
# Get all games involving favorite teams
|
||||
favorite_team_games = [game for game in processed_games
|
||||
if game['home_abbr'] in self.favorite_teams or
|
||||
game['away_abbr'] in self.favorite_teams]
|
||||
|
||||
# Select one game per favorite team (most recent game for each team)
|
||||
team_games = []
|
||||
for team in self.favorite_teams:
|
||||
# Find games where this team is playing
|
||||
team_specific_games = [game for game in favorite_team_games
|
||||
if game['home_abbr'] == team or game['away_abbr'] == team]
|
||||
|
||||
if team_specific_games:
|
||||
# Sort by game time and take the most recent
|
||||
team_specific_games.sort(key=lambda g: g.get('start_time_utc') or datetime.min.replace(tzinfo=timezone.utc), reverse=True)
|
||||
team_games.append(team_specific_games[0])
|
||||
|
||||
# Sort the final list 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)
|
||||
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]
|
||||
@@ -805,12 +820,27 @@ class NHLUpcomingManager(BaseNHLManager):
|
||||
|
||||
# Filter for favorite teams only if the config is set
|
||||
if self.nhl_config.get("show_favorite_teams_only", False):
|
||||
team_games = [game for game in new_upcoming_games
|
||||
# Get all games involving favorite teams
|
||||
favorite_team_games = [game for game in new_upcoming_games
|
||||
if game['home_abbr'] in self.favorite_teams or
|
||||
game['away_abbr'] in self.favorite_teams]
|
||||
|
||||
# Select one game per favorite team (earliest upcoming game for each team)
|
||||
team_games = []
|
||||
for team in self.favorite_teams:
|
||||
# Find games where this team is playing
|
||||
team_specific_games = [game for game in favorite_team_games
|
||||
if game['home_abbr'] == team or game['away_abbr'] == team]
|
||||
|
||||
if team_specific_games:
|
||||
# Sort by game time and take the earliest
|
||||
team_specific_games.sort(key=lambda g: g.get('start_time_utc') or datetime.max.replace(tzinfo=timezone.utc))
|
||||
team_games.append(team_specific_games[0])
|
||||
|
||||
# Sort the final list by game time
|
||||
team_games.sort(key=lambda g: g.get('start_time_utc') or datetime.max.replace(tzinfo=timezone.utc))
|
||||
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]
|
||||
|
||||
@@ -971,10 +971,27 @@ class SoccerRecentManager(BaseSoccerManager):
|
||||
|
||||
# Filter for favorite teams only if the config is set
|
||||
if self.soccer_config.get("show_favorite_teams_only", False):
|
||||
team_games = [game for game in new_recent_games if game['home_abbr'] in self.favorite_teams or game['away_abbr'] in self.favorite_teams]
|
||||
# Get all games involving favorite teams
|
||||
favorite_team_games = [game for game in new_recent_games
|
||||
if game['home_abbr'] in self.favorite_teams or
|
||||
game['away_abbr'] in self.favorite_teams]
|
||||
|
||||
# Select one game per favorite team (most recent game for each team)
|
||||
team_games = []
|
||||
for team in self.favorite_teams:
|
||||
# Find games where this team is playing
|
||||
team_specific_games = [game for game in favorite_team_games
|
||||
if game['home_abbr'] == team or game['away_abbr'] == team]
|
||||
|
||||
if team_specific_games:
|
||||
# Sort by game time and take the most recent
|
||||
team_specific_games.sort(key=lambda g: g['start_time_utc'], reverse=True)
|
||||
team_games.append(team_specific_games[0])
|
||||
|
||||
# Sort the final list by game time (most recent first)
|
||||
team_games.sort(key=lambda g: g['start_time_utc'], reverse=True)
|
||||
else:
|
||||
team_games = new_recent_games
|
||||
|
||||
# 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]
|
||||
@@ -1078,10 +1095,27 @@ class SoccerUpcomingManager(BaseSoccerManager):
|
||||
|
||||
# Filter for favorite teams only if the config is set
|
||||
if self.soccer_config.get("show_favorite_teams_only", False):
|
||||
team_games = [game for game in new_upcoming_games if game['home_abbr'] in self.favorite_teams or game['away_abbr'] in self.favorite_teams]
|
||||
# Get all games involving favorite teams
|
||||
favorite_team_games = [game for game in new_upcoming_games
|
||||
if game['home_abbr'] in self.favorite_teams or
|
||||
game['away_abbr'] in self.favorite_teams]
|
||||
|
||||
# Select one game per favorite team (earliest upcoming game for each team)
|
||||
team_games = []
|
||||
for team in self.favorite_teams:
|
||||
# Find games where this team is playing
|
||||
team_specific_games = [game for game in favorite_team_games
|
||||
if game['home_abbr'] == team or game['away_abbr'] == team]
|
||||
|
||||
if team_specific_games:
|
||||
# Sort by game time and take the earliest
|
||||
team_specific_games.sort(key=lambda g: g['start_time_utc'])
|
||||
team_games.append(team_specific_games[0])
|
||||
|
||||
# Sort the final list by game time
|
||||
team_games.sort(key=lambda g: g['start_time_utc'])
|
||||
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['start_time_utc'])
|
||||
team_games = team_games[:self.upcoming_games_to_show]
|
||||
|
||||
Reference in New Issue
Block a user