Reduce NHL warning message spam - Add 5-minute cooldown for 'No game data available' warnings - Use instance variable for warning time tracking - Improve warning message logging logic

This commit is contained in:
ChuckBuilds
2025-04-18 11:20:57 -05:00
parent 6914f068a1
commit 96b6ef3b34

View File

@@ -193,20 +193,21 @@ class BaseNHLManager:
logging.error(f"[NHL] Error extracting game details: {e}") logging.error(f"[NHL] Error extracting game details: {e}")
return None return None
def display(self, force_clear: bool = False): def display(self, force_clear: bool = False) -> None:
"""Display game information.""" """Common display method for all NHL managers"""
if not self.current_game: if not self.current_game:
current_time = time.time() current_time = time.time()
# Only log a warning if we haven't logged one recently if not hasattr(self, '_last_warning_time'):
if not BaseNHLManager._no_data_warning_logged and (current_time - BaseNHLManager._last_warning_time) > BaseNHLManager._warning_cooldown: self._last_warning_time = 0
logging.warning("[NHL] No game data available to display") if current_time - self._last_warning_time > 300: # 5 minutes cooldown
BaseNHLManager._no_data_warning_logged = True self.logger.warning("[NHL] No game data available to display")
BaseNHLManager._last_warning_time = current_time self._last_warning_time = current_time
return return
# Reset the warning flag when we have data self._draw_scorebug_layout()
BaseNHLManager._no_data_warning_logged = False
def _draw_scorebug_layout(self):
"""Draw the scorebug layout for the current game."""
try: try:
# Create a new black image # Create a new black image
img = Image.new('RGB', (self.display_width, self.display_height), 'black') img = Image.new('RGB', (self.display_width, self.display_height), 'black')