mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-04-11 05:13:01 +00:00
Add debug features and reduce logging in NHL manager - Add colored overlays for logo debugging - Save debug layout image for visual inspection - Remove excessive logging messages - Upgrade warnings to errors for missing logos
This commit is contained in:
@@ -80,14 +80,10 @@ class BaseNHLManager:
|
||||
|
||||
def _load_and_resize_logo(self, team_abbrev: str) -> Optional[Image.Image]:
|
||||
"""Load and resize a team logo, with caching."""
|
||||
self.logger.info(f"Loading logo for team: {team_abbrev}")
|
||||
|
||||
if team_abbrev in self._logo_cache:
|
||||
self.logger.info(f"Using cached logo for {team_abbrev}")
|
||||
return self._logo_cache[team_abbrev]
|
||||
|
||||
logo_path = os.path.join(self.logo_dir, f"{team_abbrev}.png")
|
||||
self.logger.info(f"Loading logo from path: {logo_path}")
|
||||
|
||||
try:
|
||||
# Create test logos if they don't exist
|
||||
@@ -106,14 +102,11 @@ class BaseNHLManager:
|
||||
# Add team abbreviation
|
||||
draw.text((8, 8), team_abbrev, fill=(255, 255, 255, 255))
|
||||
logo.save(logo_path)
|
||||
self.logger.info(f"Created and saved test logo for {team_abbrev}")
|
||||
|
||||
logo = Image.open(logo_path)
|
||||
self.logger.info(f"Opened logo for {team_abbrev}, initial size: {logo.size}, mode: {logo.mode}")
|
||||
|
||||
# Convert to RGBA if not already
|
||||
if logo.mode != 'RGBA':
|
||||
self.logger.info(f"Converting {team_abbrev} logo from {logo.mode} to RGBA")
|
||||
logo = logo.convert('RGBA')
|
||||
|
||||
# Calculate max size based on display dimensions
|
||||
@@ -122,7 +115,6 @@ class BaseNHLManager:
|
||||
|
||||
# Resize maintaining aspect ratio
|
||||
logo.thumbnail((max_width, max_height), Image.Resampling.LANCZOS)
|
||||
self.logger.info(f"Resized {team_abbrev} logo to: {logo.size}")
|
||||
|
||||
# Cache the resized logo
|
||||
self._logo_cache[team_abbrev] = logo
|
||||
@@ -232,46 +224,41 @@ class BaseNHLManager:
|
||||
def _draw_scorebug_layout(self):
|
||||
"""Draw the scorebug layout for the current game."""
|
||||
try:
|
||||
self.logger.info(f"Drawing scorebug for {self.current_game['away_abbr']} vs {self.current_game['home_abbr']}")
|
||||
|
||||
# Create a new black image for the main display
|
||||
main_img = Image.new('RGBA', (self.display_width, self.display_height), (0, 0, 0, 255))
|
||||
|
||||
# Load logos once
|
||||
home_logo = self._load_and_resize_logo(self.current_game["home_abbr"])
|
||||
away_logo = self._load_and_resize_logo(self.current_game["away_abbr"])
|
||||
|
||||
self.logger.info(f"Home logo loaded: {home_logo is not None}, Away logo loaded: {away_logo is not None}")
|
||||
if home_logo:
|
||||
self.logger.info(f"Home logo size: {home_logo.size}, mode: {home_logo.mode}")
|
||||
if away_logo:
|
||||
self.logger.info(f"Away logo size: {away_logo.size}, mode: {away_logo.mode}")
|
||||
|
||||
# Draw home team logo (right side)
|
||||
if home_logo:
|
||||
home_x = 3 * self.display_width // 4 - home_logo.width // 2
|
||||
home_y = self.display_height // 4 - home_logo.height // 2
|
||||
self.logger.info(f"Pasting home logo at ({home_x}, {home_y})")
|
||||
|
||||
# Create a temporary image for the home logo
|
||||
home_overlay = Image.new('RGBA', (self.display_width, self.display_height), (0, 0, 0, 0))
|
||||
# Create a temporary image for the home logo with red background for debugging
|
||||
home_overlay = Image.new('RGBA', (self.display_width, self.display_height), (255, 0, 0, 128))
|
||||
home_overlay.paste(home_logo, (home_x, home_y), home_logo)
|
||||
main_img = Image.alpha_composite(main_img, home_overlay)
|
||||
else:
|
||||
self.logger.warning(f"Home logo is None for team {self.current_game['home_abbr']}")
|
||||
self.logger.error(f"Home logo is None for team {self.current_game['home_abbr']}")
|
||||
|
||||
# Draw away team logo (left side)
|
||||
if away_logo:
|
||||
away_x = self.display_width // 4 - away_logo.width // 2
|
||||
away_y = self.display_height // 4 - away_logo.height // 2
|
||||
self.logger.info(f"Pasting away logo at ({away_x}, {away_y})")
|
||||
|
||||
# Create a temporary image for the away logo
|
||||
away_overlay = Image.new('RGBA', (self.display_width, self.display_height), (0, 0, 0, 0))
|
||||
# Create a temporary image for the away logo with blue background for debugging
|
||||
away_overlay = Image.new('RGBA', (self.display_width, self.display_height), (0, 0, 255, 128))
|
||||
away_overlay.paste(away_logo, (away_x, away_y), away_logo)
|
||||
main_img = Image.alpha_composite(main_img, away_overlay)
|
||||
else:
|
||||
self.logger.warning(f"Away logo is None for team {self.current_game['away_abbr']}")
|
||||
self.logger.error(f"Away logo is None for team {self.current_game['away_abbr']}")
|
||||
|
||||
# Save debug image to check logo positions
|
||||
debug_path = os.path.join(os.path.dirname(self.logo_dir), "debug_layout.png")
|
||||
main_img.save(debug_path)
|
||||
self.logger.info(f"Saved debug layout to: {debug_path}")
|
||||
|
||||
# Convert to RGB for final display
|
||||
main_img = main_img.convert('RGB')
|
||||
@@ -280,30 +267,24 @@ class BaseNHLManager:
|
||||
# Draw scores in the format "AWAY - HOME"
|
||||
home_score = str(self.current_game["home_score"])
|
||||
away_score = str(self.current_game["away_score"])
|
||||
|
||||
# Format the score string with a hyphen separator
|
||||
score_text = f"{away_score} - {home_score}"
|
||||
|
||||
# Calculate position for the score text (centered at the bottom)
|
||||
score_width = draw.textlength(score_text, font=self.fonts['score'])
|
||||
score_x = (self.display_width - score_width) // 2
|
||||
score_y = 3 * self.display_height // 4 - 10
|
||||
|
||||
# Draw the score text
|
||||
draw.text((score_x, score_y), score_text, font=self.fonts['score'], fill=(255, 255, 255))
|
||||
|
||||
# Draw game status (period and time or "FINAL")
|
||||
# Draw game status
|
||||
status_text = self.current_game.get("status_text", "")
|
||||
status_width = draw.textlength(status_text, font=self.fonts['status'])
|
||||
status_x = (self.display_width - status_width) // 2
|
||||
status_y = self.display_height // 2 - 5
|
||||
|
||||
draw.text((status_x, status_y), status_text, font=self.fonts['status'], fill=(255, 255, 255))
|
||||
|
||||
# Display the image
|
||||
self.display_manager.image.paste(main_img, (0, 0))
|
||||
self.display_manager.update_display()
|
||||
self.logger.info("Scorebug display completed")
|
||||
|
||||
except Exception as e:
|
||||
self.logger.error(f"Error displaying game: {e}", exc_info=True)
|
||||
|
||||
Reference in New Issue
Block a user