ensure game rotation count respects user defined variable

This commit is contained in:
ChuckBuilds
2025-08-14 13:01:23 -05:00
parent 6152969340
commit 54635fee3c
8 changed files with 158 additions and 23 deletions

View File

@@ -248,8 +248,8 @@
"live_odds_update_interval": 3600,
"odds_update_interval": 3600,
"season_cache_duration_seconds": 86400,
"recent_games_to_show": 1,
"upcoming_games_to_show": 1,
"recent_games_to_show": 2,
"upcoming_games_to_show": 2,
"show_favorite_teams_only": true,
"favorite_teams": [
"UGA",
@@ -296,8 +296,8 @@
"test_mode": false,
"update_interval_seconds": 3600,
"live_update_interval": 30,
"recent_games_to_show": 1,
"upcoming_games_to_show": 1,
"recent_games_to_show": 2,
"upcoming_games_to_show": 2,
"show_favorite_teams_only": true,
"favorite_teams": [
"UGA",
@@ -327,8 +327,8 @@
"odds_update_interval": 3600,
"recent_update_interval": 3600,
"upcoming_update_interval": 3600,
"recent_games_to_show": 1,
"upcoming_games_to_show": 1,
"recent_games_to_show": 2,
"upcoming_games_to_show": 2,
"show_favorite_teams_only": true,
"favorite_teams": [
"TB",
@@ -351,8 +351,8 @@
"live_update_interval": 30,
"recent_update_interval": 3600,
"upcoming_update_interval": 3600,
"recent_games_to_show": 1,
"upcoming_games_to_show": 1,
"recent_games_to_show": 2,
"upcoming_games_to_show": 2,
"favorite_teams": [
"TAM"
],

View File

@@ -1095,7 +1095,7 @@ class MiLBRecentManager(BaseMiLBManager):
current_time = time.time()
# Check if it's time to switch games
if current_time - self.last_game_switch >= self.game_display_duration:
if len(self.recent_games) > 1 and current_time - self.last_game_switch >= self.game_display_duration:
# Move to next game
self.current_game_index = (self.current_game_index + 1) % len(self.recent_games)
self.current_game = self.recent_games[self.current_game_index]
@@ -1212,7 +1212,7 @@ class MiLBUpcomingManager(BaseMiLBManager):
current_time = time.time()
# Check if it's time to switch games
if current_time - self.last_game_switch >= self.game_display_duration:
if len(self.upcoming_games) > 1 and current_time - self.last_game_switch >= self.game_display_duration:
# Move to next game
self.current_game_index = (self.current_game_index + 1) % len(self.upcoming_games)
self.current_game = self.upcoming_games[self.current_game_index]

View File

@@ -1562,7 +1562,7 @@ class MiLBRecentManager(BaseMiLBManager):
current_time = time.time()
# Check if it's time to switch games
if current_time - self.last_game_switch >= self.game_display_duration:
if len(self.recent_games) > 1 and current_time - self.last_game_switch >= self.game_display_duration:
# Move to next game
self.current_game_index = (self.current_game_index + 1) % len(self.recent_games)
self.current_game = self.recent_games[self.current_game_index]
@@ -1760,7 +1760,7 @@ class MiLBUpcomingManager(BaseMiLBManager):
current_time = time.time()
# Check if it's time to switch games
if current_time - self.last_game_switch >= self.game_display_duration:
if len(self.upcoming_games) > 1 and current_time - self.last_game_switch >= self.game_display_duration:
# Move to next game
self.current_game_index = (self.current_game_index + 1) % len(self.upcoming_games)
self.current_game = self.upcoming_games[self.current_game_index]

View File

@@ -1255,7 +1255,7 @@ class MLBRecentManager(BaseMLBManager):
current_time = time.time()
# Check if it's time to switch games
if current_time - self.last_game_switch >= self.game_display_duration:
if len(self.recent_games) > 1 and current_time - self.last_game_switch >= self.game_display_duration:
# Move to next game
self.current_game_index = (self.current_game_index + 1) % len(self.recent_games)
self.current_game = self.recent_games[self.current_game_index]
@@ -1377,7 +1377,7 @@ class MLBUpcomingManager(BaseMLBManager):
current_time = time.time()
# Check if it's time to switch games
if current_time - self.last_game_switch >= self.game_display_duration:
if len(self.upcoming_games) > 1 and current_time - self.last_game_switch >= self.game_display_duration:
# Move to next game
self.current_game_index = (self.current_game_index + 1) % len(self.upcoming_games)
self.current_game = self.upcoming_games[self.current_game_index]

View File

@@ -794,7 +794,7 @@ class NBARecentManager(BaseNBAManager):
current_time = time.time()
# Check if it's time to switch games
if current_time - self.last_game_switch >= self.game_display_duration:
if len(self.recent_games) > 1 and current_time - self.last_game_switch >= self.game_display_duration:
self.current_game_index = (self.current_game_index + 1) % len(self.recent_games)
self.current_game = self.recent_games[self.current_game_index]
self.last_game_switch = current_time
@@ -816,6 +816,8 @@ class NBAUpcomingManager(BaseNBAManager):
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
self.last_game_switch = 0
self.game_display_duration = 15 # Display each game for 15 seconds
def update(self):
"""Update upcoming games data."""
@@ -867,12 +869,18 @@ class NBAUpcomingManager(BaseNBAManager):
return
try:
# Draw the scorebug layout
self._draw_scorebug_layout(self.current_game, force_clear)
current_time = time.time()
# Check if it's time to switch games
if len(self.upcoming_games) > 1 and current_time - self.last_game_switch >= self.game_display_duration:
# Move to next game
self.current_game_index = (self.current_game_index + 1) % len(self.upcoming_games)
self.current_game = self.upcoming_games[self.current_game_index]
self.last_game_switch = current_time
force_clear = True
# Draw the scorebug layout
self._draw_scorebug_layout(self.current_game, force_clear)
except Exception as e:
self.logger.error(f"[NBA] Error displaying upcoming game: {e}", exc_info=True)

View File

@@ -935,7 +935,7 @@ class NCAABaseballRecentManager(BaseNCAABaseballManager):
return
try:
current_time = time.time()
if current_time - self.last_game_switch >= self.game_display_duration:
if len(self.recent_games) > 1 and current_time - self.last_game_switch >= self.game_display_duration:
self.current_game_index = (self.current_game_index + 1) % len(self.recent_games)
self.current_game = self.recent_games[self.current_game_index]
self.last_game_switch = current_time
@@ -1035,7 +1035,7 @@ class NCAABaseballUpcomingManager(BaseNCAABaseballManager):
return
try:
current_time = time.time()
if current_time - self.last_game_switch >= self.game_display_duration:
if len(self.upcoming_games) > 1 and current_time - self.last_game_switch >= self.game_display_duration:
self.current_game_index = (self.current_game_index + 1) % len(self.upcoming_games)
self.current_game = self.upcoming_games[self.current_game_index]
self.last_game_switch = current_time

View File

@@ -741,7 +741,7 @@ class NHLRecentManager(BaseNHLManager):
current_time = time.time()
# Check if it's time to switch games
if current_time - self.last_game_switch >= self.game_display_duration:
if len(self.games_list) > 1 and current_time - self.last_game_switch >= self.game_display_duration:
# Move to 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]
@@ -859,7 +859,7 @@ class NHLUpcomingManager(BaseNHLManager):
current_time = time.time()
# Check if it's time to switch games
if current_time - self.last_game_switch >= self.game_display_duration:
if len(self.upcoming_games) > 1 and current_time - self.last_game_switch >= self.game_display_duration:
# Move to next game
self.current_game_index = (self.current_game_index + 1) % len(self.upcoming_games)
self.current_game = self.upcoming_games[self.current_game_index]

View File

@@ -0,0 +1,127 @@
#!/usr/bin/env python3
"""
Test script to verify that *_games_to_show configuration settings are working correctly
across all sports managers.
"""
import json
import sys
import os
# Add the src directory to the path
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', 'src'))
def load_config():
"""Load the configuration file."""
config_path = os.path.join(os.path.dirname(__file__), '..', 'config', 'config.json')
with open(config_path, 'r') as f:
return json.load(f)
def test_config_values():
"""Test that config values are set correctly."""
config = load_config()
print("Testing *_games_to_show configuration values:")
print("=" * 50)
sports_configs = [
("NHL", config.get('nhl_scoreboard', {})),
("NBA", config.get('nba_scoreboard', {})),
("NFL", config.get('nfl_scoreboard', {})),
("NCAA Football", config.get('ncaa_fb_scoreboard', {})),
("NCAA Baseball", config.get('ncaa_baseball_scoreboard', {})),
("NCAA Basketball", config.get('ncaam_basketball_scoreboard', {})),
("MLB", config.get('mlb', {})),
("MiLB", config.get('milb', {})),
("Soccer", config.get('soccer_scoreboard', {}))
]
for sport_name, sport_config in sports_configs:
recent_games = sport_config.get('recent_games_to_show', 'NOT_SET')
upcoming_games = sport_config.get('upcoming_games_to_show', 'NOT_SET')
print(f"{sport_name:15} | Recent: {recent_games:2} | Upcoming: {upcoming_games:2}")
print("\nExpected behavior:")
print("- When recent_games_to_show = 1: Only show 1 most recent game")
print("- When upcoming_games_to_show = 1: Only show 1 next upcoming game")
print("- When values > 1: Show multiple games and rotate through them")
def test_manager_defaults():
"""Test that managers have correct default values."""
print("\n" + "=" * 50)
print("Testing manager default values:")
print("=" * 50)
# Test the default values that managers use when config is not set
manager_defaults = {
"NHL": {"recent": 5, "upcoming": 5},
"NBA": {"recent": 5, "upcoming": 5},
"NFL": {"recent": 5, "upcoming": 10},
"NCAA Football": {"recent": 5, "upcoming": 10},
"NCAA Baseball": {"recent": 5, "upcoming": 5},
"NCAA Basketball": {"recent": 5, "upcoming": 5},
"MLB": {"recent": 5, "upcoming": 10},
"MiLB": {"recent": 5, "upcoming": 10},
"Soccer": {"recent": 5, "upcoming": 5}
}
for sport_name, defaults in manager_defaults.items():
print(f"{sport_name:15} | Recent default: {defaults['recent']:2} | Upcoming default: {defaults['upcoming']:2}")
def test_config_consistency():
"""Test for consistency between config values and expected behavior."""
config = load_config()
print("\n" + "=" * 50)
print("Testing config consistency:")
print("=" * 50)
sports_configs = [
("NHL", config.get('nhl_scoreboard', {})),
("NBA", config.get('nba_scoreboard', {})),
("NFL", config.get('nfl_scoreboard', {})),
("NCAA Football", config.get('ncaa_fb_scoreboard', {})),
("NCAA Baseball", config.get('ncaa_baseball_scoreboard', {})),
("NCAA Basketball", config.get('ncaam_basketball_scoreboard', {})),
("MLB", config.get('mlb', {})),
("MiLB", config.get('milb', {})),
("Soccer", config.get('soccer_scoreboard', {}))
]
issues_found = []
for sport_name, sport_config in sports_configs:
recent_games = sport_config.get('recent_games_to_show')
upcoming_games = sport_config.get('upcoming_games_to_show')
if recent_games is None:
issues_found.append(f"{sport_name}: recent_games_to_show not set")
if upcoming_games is None:
issues_found.append(f"{sport_name}: upcoming_games_to_show not set")
if recent_games == 1:
print(f"{sport_name:15} | Recent: {recent_games} (Single game mode)")
elif recent_games > 1:
print(f"{sport_name:15} | Recent: {recent_games} (Multi-game rotation)")
else:
issues_found.append(f"{sport_name}: Invalid recent_games_to_show value: {recent_games}")
if upcoming_games == 1:
print(f"{sport_name:15} | Upcoming: {upcoming_games} (Single game mode)")
elif upcoming_games > 1:
print(f"{sport_name:15} | Upcoming: {upcoming_games} (Multi-game rotation)")
else:
issues_found.append(f"{sport_name}: Invalid upcoming_games_to_show value: {upcoming_games}")
if issues_found:
print("\nIssues found:")
for issue in issues_found:
print(f" - {issue}")
else:
print("\nNo configuration issues found!")
if __name__ == "__main__":
test_config_values()
test_manager_defaults()
test_config_consistency()