mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-04-12 05:42:59 +00:00
Leaderboard hangs at end due to overestimate of time (#53)
* Leaderboard overestimates time --------- Co-authored-by: Alex Resnick <adr8282@gmail.com>
This commit is contained in:
@@ -75,6 +75,7 @@ class DisplayController:
|
|||||||
logger.info(f"News Manager initialized: {'Object' if self.news_manager else 'None'}")
|
logger.info(f"News Manager initialized: {'Object' if self.news_manager else 'None'}")
|
||||||
logger.info("Display modes initialized in %.3f seconds", time.time() - init_time)
|
logger.info("Display modes initialized in %.3f seconds", time.time() - init_time)
|
||||||
|
|
||||||
|
self.force_change = False
|
||||||
# Initialize Music Manager
|
# Initialize Music Manager
|
||||||
music_init_time = time.time()
|
music_init_time = time.time()
|
||||||
self.music_manager = None
|
self.music_manager = None
|
||||||
@@ -1248,7 +1249,8 @@ class DisplayController:
|
|||||||
# Reset logged duration when mode changes
|
# Reset logged duration when mode changes
|
||||||
if hasattr(self, '_last_logged_duration'):
|
if hasattr(self, '_last_logged_duration'):
|
||||||
delattr(self, '_last_logged_duration')
|
delattr(self, '_last_logged_duration')
|
||||||
elif current_time - self.last_switch >= self.get_current_duration():
|
elif current_time - self.last_switch >= self.get_current_duration() or self.force_change:
|
||||||
|
self.force_change = False
|
||||||
if self.current_display_mode == 'calendar' and self.calendar:
|
if self.current_display_mode == 'calendar' and self.calendar:
|
||||||
self.calendar.advance_event()
|
self.calendar.advance_event()
|
||||||
elif self.current_display_mode == 'of_the_day' and self.of_the_day:
|
elif self.current_display_mode == 'of_the_day' and self.of_the_day:
|
||||||
@@ -1397,8 +1399,11 @@ class DisplayController:
|
|||||||
manager_to_display.display_stocks(force_clear=self.force_clear)
|
manager_to_display.display_stocks(force_clear=self.force_clear)
|
||||||
elif self.current_display_mode == 'stock_news':
|
elif self.current_display_mode == 'stock_news':
|
||||||
manager_to_display.display_news() # Assumes internal clearing
|
manager_to_display.display_news() # Assumes internal clearing
|
||||||
elif self.current_display_mode == 'odds_ticker':
|
elif self.current_display_mode in {'odds_ticker', 'leaderboard'}:
|
||||||
manager_to_display.display(force_clear=self.force_clear)
|
try:
|
||||||
|
manager_to_display.display(force_clear=self.force_clear)
|
||||||
|
except StopIteration:
|
||||||
|
self.force_change = True
|
||||||
elif self.current_display_mode == 'calendar':
|
elif self.current_display_mode == 'calendar':
|
||||||
manager_to_display.display(force_clear=self.force_clear)
|
manager_to_display.display(force_clear=self.force_clear)
|
||||||
elif self.current_display_mode == 'youtube':
|
elif self.current_display_mode == 'youtube':
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import logging
|
|||||||
import requests
|
import requests
|
||||||
from typing import Dict, Any, List, Optional
|
from typing import Dict, Any, List, Optional
|
||||||
import os
|
import os
|
||||||
|
import time
|
||||||
from PIL import Image, ImageDraw, ImageFont
|
from PIL import Image, ImageDraw, ImageFont
|
||||||
try:
|
try:
|
||||||
from .display_manager import DisplayManager
|
from .display_manager import DisplayManager
|
||||||
@@ -42,7 +43,7 @@ class LeaderboardManager:
|
|||||||
self.display_duration = self.leaderboard_config.get('display_duration', 30)
|
self.display_duration = self.leaderboard_config.get('display_duration', 30)
|
||||||
self.loop = self.leaderboard_config.get('loop', True)
|
self.loop = self.leaderboard_config.get('loop', True)
|
||||||
self.request_timeout = self.leaderboard_config.get('request_timeout', 30)
|
self.request_timeout = self.leaderboard_config.get('request_timeout', 30)
|
||||||
|
self.time_over = 0
|
||||||
# Dynamic duration settings
|
# Dynamic duration settings
|
||||||
self.dynamic_duration_enabled = self.leaderboard_config.get('dynamic_duration', True)
|
self.dynamic_duration_enabled = self.leaderboard_config.get('dynamic_duration', True)
|
||||||
self.min_duration = self.leaderboard_config.get('min_duration', 30)
|
self.min_duration = self.leaderboard_config.get('min_duration', 30)
|
||||||
@@ -1355,6 +1356,11 @@ class LeaderboardManager:
|
|||||||
# Signal that scrolling has stopped
|
# Signal that scrolling has stopped
|
||||||
self.display_manager.set_scrolling_state(False)
|
self.display_manager.set_scrolling_state(False)
|
||||||
logger.info("Leaderboard scrolling stopped - reached end of content")
|
logger.info("Leaderboard scrolling stopped - reached end of content")
|
||||||
|
if self.time_over == 0:
|
||||||
|
self.time_over = time.time()
|
||||||
|
elif time.time() - self.time_over >= 2:
|
||||||
|
self.time_over = 0
|
||||||
|
raise StopIteration
|
||||||
|
|
||||||
# Check if we're at a natural break point for mode switching
|
# Check if we're at a natural break point for mode switching
|
||||||
elapsed_time = current_time - self._display_start_time
|
elapsed_time = current_time - self._display_start_time
|
||||||
@@ -1402,6 +1408,8 @@ class LeaderboardManager:
|
|||||||
self.display_manager.draw = ImageDraw.Draw(self.display_manager.image)
|
self.display_manager.draw = ImageDraw.Draw(self.display_manager.image)
|
||||||
self.display_manager.update_display()
|
self.display_manager.update_display()
|
||||||
|
|
||||||
|
except StopIteration as e:
|
||||||
|
raise e
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Error in leaderboard display: {e}")
|
logger.error(f"Error in leaderboard display: {e}")
|
||||||
self._display_fallback_message()
|
self._display_fallback_message()
|
||||||
|
|||||||
Reference in New Issue
Block a user