fix: Enhance inning half detection with more robust parsing and detailed logging

This commit is contained in:
ChuckBuilds
2025-04-27 15:22:27 -05:00
parent 4ad0ac1de9
commit 1c641c0e27

View File

@@ -298,20 +298,29 @@ class BaseMLBManager:
inning = linescore.get('value', 1) inning = linescore.get('value', 1)
inning_display = linescore.get('displayValue', '').lower() inning_display = linescore.get('displayValue', '').lower()
# Add debug logging for inning data # Add detailed debug logging for inning data
if is_favorite_game: if is_favorite_game:
self.logger.debug(f"[MLB] Raw inning data - value: {inning}, displayValue: {inning_display}") self.logger.debug(f"[MLB] Raw inning data - value: {inning}, displayValue: {inning_display}")
self.logger.debug(f"[MLB] Full linescore data: {linescore}")
self.logger.debug(f"[MLB] Raw displayValue: {linescore.get('displayValue')}")
# Determine inning half from display value # Determine inning half from display value
if 'top' in inning_display: inning_half = 'top' # Default to top
inning_half = 'top'
elif 'bottom' in inning_display: # Check various possible formats for inning half
inning_half = 'bottom' if inning_display:
else: if any(x in inning_display for x in ['top', 't', '1st']):
# Default to top of inning if we can't determine inning_half = 'top'
inning_half = 'top' elif any(x in inning_display for x in ['bottom', 'b', '2nd']):
if is_favorite_game: inning_half = 'bottom'
self.logger.warning(f"[MLB] Could not determine inning half from display value: {inning_display}, defaulting to top")
# Additional check for inning number in display
if inning_display.isdigit():
inning = int(inning_display)
inning_half = 'top' # If just a number, assume top
if is_favorite_game:
self.logger.debug(f"[MLB] Determined inning half: {inning_half} (from display: {inning_display})")
# Get count and bases from situation # Get count and bases from situation
situation = event['competitions'][0].get('situation', {}) situation = event['competitions'][0].get('situation', {})