mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-04-12 05:42:59 +00:00
Modify game rotation to show all games for one team before switching to the other team
This commit is contained in:
@@ -423,6 +423,7 @@ class NHLRecentManager(BaseNHLManager):
|
|||||||
self.current_game = None
|
self.current_game = None
|
||||||
self.games_list = [] # List to store all recent games
|
self.games_list = [] # List to store all recent games
|
||||||
self.current_game_index = 0 # Index to track which game to show
|
self.current_game_index = 0 # Index to track which game to show
|
||||||
|
self.current_team_index = 0 # Index to track which team we're showing
|
||||||
# Override test_mode to always use real data for recent games
|
# Override test_mode to always use real data for recent games
|
||||||
self.test_mode = False
|
self.test_mode = False
|
||||||
logging.info("[NHL] Initialized NHLRecentManager in live mode")
|
logging.info("[NHL] Initialized NHLRecentManager in live mode")
|
||||||
@@ -479,26 +480,67 @@ class NHLRecentManager(BaseNHLManager):
|
|||||||
details["home_abbr"] in self.favorite_teams or
|
details["home_abbr"] in self.favorite_teams or
|
||||||
details["away_abbr"] in self.favorite_teams
|
details["away_abbr"] in self.favorite_teams
|
||||||
):
|
):
|
||||||
|
# Verify logo files exist for both teams
|
||||||
|
home_logo_path = os.path.join(self.logo_dir, f"{details['home_abbr']}.png")
|
||||||
|
away_logo_path = os.path.join(self.logo_dir, f"{details['away_abbr']}.png")
|
||||||
|
|
||||||
|
if not os.path.exists(home_logo_path):
|
||||||
|
logging.warning(f"[NHL] Home logo not found: {home_logo_path}")
|
||||||
|
continue
|
||||||
|
if not os.path.exists(away_logo_path):
|
||||||
|
logging.warning(f"[NHL] Away logo not found: {away_logo_path}")
|
||||||
|
continue
|
||||||
|
|
||||||
recent_games.append(details)
|
recent_games.append(details)
|
||||||
|
|
||||||
# Sort games by start time, most recent first
|
# Sort games by start time, most recent first
|
||||||
recent_games.sort(key=lambda x: x["start_time_utc"], reverse=True)
|
recent_games.sort(key=lambda x: x["start_time_utc"], reverse=True)
|
||||||
|
|
||||||
if recent_games:
|
if recent_games:
|
||||||
self.games_list = recent_games
|
# Group games by team
|
||||||
|
team_games = {}
|
||||||
|
for game in recent_games:
|
||||||
|
for team in self.favorite_teams:
|
||||||
|
if game["home_abbr"] == team or game["away_abbr"] == team:
|
||||||
|
if team not in team_games:
|
||||||
|
team_games[team] = []
|
||||||
|
team_games[team].append(game)
|
||||||
|
|
||||||
# If we don't have a current game or it's not in the new list, start from the beginning
|
# If we don't have a current game or it's not in the new list, start from the beginning
|
||||||
if not self.current_game or self.current_game not in self.games_list:
|
if not self.current_game or self.current_game not in recent_games:
|
||||||
|
self.current_team_index = 0
|
||||||
self.current_game_index = 0
|
self.current_game_index = 0
|
||||||
else:
|
else:
|
||||||
# Keep the same index if possible, otherwise reset to 0
|
# Find which team we're currently showing
|
||||||
try:
|
for i, team in enumerate(self.favorite_teams):
|
||||||
self.current_game_index = self.games_list.index(self.current_game)
|
if team in team_games and self.current_game in team_games[team]:
|
||||||
except ValueError:
|
self.current_team_index = i
|
||||||
self.current_game_index = 0
|
self.current_game_index = team_games[team].index(self.current_game)
|
||||||
|
break
|
||||||
|
|
||||||
|
# Get the current team's games
|
||||||
|
current_team = self.favorite_teams[self.current_team_index]
|
||||||
|
current_team_games = team_games.get(current_team, [])
|
||||||
|
|
||||||
|
if current_team_games:
|
||||||
|
# Move to next game for current team
|
||||||
|
self.current_game_index = (self.current_game_index + 1) % len(current_team_games)
|
||||||
|
self.current_game = current_team_games[self.current_game_index]
|
||||||
|
|
||||||
|
# If we've shown all games for this team, move to next team
|
||||||
|
if self.current_game_index == 0:
|
||||||
|
self.current_team_index = (self.current_team_index + 1) % len(self.favorite_teams)
|
||||||
|
next_team = self.favorite_teams[self.current_team_index]
|
||||||
|
if next_team in team_games and team_games[next_team]:
|
||||||
|
self.current_game = team_games[next_team][0]
|
||||||
|
|
||||||
|
# Debug: Print all favorite team games we found
|
||||||
|
print("\nDEBUG - Favorite team games found:")
|
||||||
|
for team, games in team_games.items():
|
||||||
|
print(f"\n{team} games:")
|
||||||
|
for game in games:
|
||||||
|
print(f" {game['away_abbr']} vs {game['home_abbr']}")
|
||||||
|
|
||||||
# Rotate to the next game
|
|
||||||
self.current_game_index = (self.current_game_index + 1) % len(self.games_list)
|
|
||||||
self.current_game = self.games_list[self.current_game_index]
|
|
||||||
logging.info(f"[NHL] Rotating to recent game: {self.current_game['away_abbr']} vs {self.current_game['home_abbr']}")
|
logging.info(f"[NHL] Rotating to recent game: {self.current_game['away_abbr']} vs {self.current_game['home_abbr']}")
|
||||||
else:
|
else:
|
||||||
logging.info("[NHL] No recent games found")
|
logging.info("[NHL] No recent games found")
|
||||||
@@ -522,6 +564,7 @@ class NHLUpcomingManager(BaseNHLManager):
|
|||||||
self.current_game = None
|
self.current_game = None
|
||||||
self.games_list = [] # List to store all upcoming games
|
self.games_list = [] # List to store all upcoming games
|
||||||
self.current_game_index = 0 # Index to track which game to show
|
self.current_game_index = 0 # Index to track which game to show
|
||||||
|
self.current_team_index = 0 # Index to track which team we're showing
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Update upcoming game data."""
|
"""Update upcoming game data."""
|
||||||
@@ -563,26 +606,67 @@ class NHLUpcomingManager(BaseNHLManager):
|
|||||||
details["home_abbr"] in self.favorite_teams or
|
details["home_abbr"] in self.favorite_teams or
|
||||||
details["away_abbr"] in self.favorite_teams
|
details["away_abbr"] in self.favorite_teams
|
||||||
):
|
):
|
||||||
|
# Verify logo files exist for both teams
|
||||||
|
home_logo_path = os.path.join(self.logo_dir, f"{details['home_abbr']}.png")
|
||||||
|
away_logo_path = os.path.join(self.logo_dir, f"{details['away_abbr']}.png")
|
||||||
|
|
||||||
|
if not os.path.exists(home_logo_path):
|
||||||
|
logging.warning(f"[NHL] Home logo not found: {home_logo_path}")
|
||||||
|
continue
|
||||||
|
if not os.path.exists(away_logo_path):
|
||||||
|
logging.warning(f"[NHL] Away logo not found: {away_logo_path}")
|
||||||
|
continue
|
||||||
|
|
||||||
upcoming_games.append(details)
|
upcoming_games.append(details)
|
||||||
|
|
||||||
# Sort games by start time
|
# Sort games by start time
|
||||||
upcoming_games.sort(key=lambda x: x["start_time_utc"])
|
upcoming_games.sort(key=lambda x: x["start_time_utc"])
|
||||||
|
|
||||||
if upcoming_games:
|
if upcoming_games:
|
||||||
self.games_list = upcoming_games
|
# Group games by team
|
||||||
|
team_games = {}
|
||||||
|
for game in upcoming_games:
|
||||||
|
for team in self.favorite_teams:
|
||||||
|
if game["home_abbr"] == team or game["away_abbr"] == team:
|
||||||
|
if team not in team_games:
|
||||||
|
team_games[team] = []
|
||||||
|
team_games[team].append(game)
|
||||||
|
|
||||||
# If we don't have a current game or it's not in the new list, start from the beginning
|
# If we don't have a current game or it's not in the new list, start from the beginning
|
||||||
if not self.current_game or self.current_game not in self.games_list:
|
if not self.current_game or self.current_game not in upcoming_games:
|
||||||
|
self.current_team_index = 0
|
||||||
self.current_game_index = 0
|
self.current_game_index = 0
|
||||||
else:
|
else:
|
||||||
# Keep the same index if possible, otherwise reset to 0
|
# Find which team we're currently showing
|
||||||
try:
|
for i, team in enumerate(self.favorite_teams):
|
||||||
self.current_game_index = self.games_list.index(self.current_game)
|
if team in team_games and self.current_game in team_games[team]:
|
||||||
except ValueError:
|
self.current_team_index = i
|
||||||
self.current_game_index = 0
|
self.current_game_index = team_games[team].index(self.current_game)
|
||||||
|
break
|
||||||
|
|
||||||
|
# Get the current team's games
|
||||||
|
current_team = self.favorite_teams[self.current_team_index]
|
||||||
|
current_team_games = team_games.get(current_team, [])
|
||||||
|
|
||||||
|
if current_team_games:
|
||||||
|
# Move to next game for current team
|
||||||
|
self.current_game_index = (self.current_game_index + 1) % len(current_team_games)
|
||||||
|
self.current_game = current_team_games[self.current_game_index]
|
||||||
|
|
||||||
|
# If we've shown all games for this team, move to next team
|
||||||
|
if self.current_game_index == 0:
|
||||||
|
self.current_team_index = (self.current_team_index + 1) % len(self.favorite_teams)
|
||||||
|
next_team = self.favorite_teams[self.current_team_index]
|
||||||
|
if next_team in team_games and team_games[next_team]:
|
||||||
|
self.current_game = team_games[next_team][0]
|
||||||
|
|
||||||
|
# Debug: Print all favorite team games we found
|
||||||
|
print("\nDEBUG - Favorite team games found:")
|
||||||
|
for team, games in team_games.items():
|
||||||
|
print(f"\n{team} games:")
|
||||||
|
for game in games:
|
||||||
|
print(f" {game['away_abbr']} vs {game['home_abbr']}")
|
||||||
|
|
||||||
# Rotate to the next game
|
|
||||||
self.current_game_index = (self.current_game_index + 1) % len(self.games_list)
|
|
||||||
self.current_game = self.games_list[self.current_game_index]
|
|
||||||
logging.info(f"[NHL] Rotating to upcoming game: {self.current_game['away_abbr']} vs {self.current_game['home_abbr']}")
|
logging.info(f"[NHL] Rotating to upcoming game: {self.current_game['away_abbr']} vs {self.current_game['home_abbr']}")
|
||||||
else:
|
else:
|
||||||
logging.info("[NHL] No upcoming games found")
|
logging.info("[NHL] No upcoming games found")
|
||||||
|
|||||||
Reference in New Issue
Block a user