Add detailed logging to fixtures API to debug match processing

parent 80a5421b
...@@ -10777,59 +10777,68 @@ def get_overlay_fixtures(): ...@@ -10777,59 +10777,68 @@ def get_overlay_fixtures():
# Combine matches: yesterday first (if any incomplete), then today # Combine matches: yesterday first (if any incomplete), then today
all_matches = [] all_matches = []
if yesterday_incomplete_matches: if yesterday_incomplete_matches:
logger.debug(f"Found {len(yesterday_incomplete_matches)} incomplete matches from yesterday - including them") logger.info(f"[FIXTURES API] Found {len(yesterday_incomplete_matches)} incomplete matches from yesterday - including them")
all_matches.extend(yesterday_incomplete_matches) all_matches.extend(yesterday_incomplete_matches)
all_matches.extend(today_matches)
# Limit to 5 matches total
display_matches = all_matches[:5]
fixtures_data = []
for match in display_matches:
# Get outcomes from MatchOutcomeModel
outcomes = session.query(MatchOutcomeModel).filter_by(match_id=match.id).all()
# Format outcomes as array expected by template all_matches.extend(today_matches)
outcomes_array = []
for outcome in outcomes:
outcomes_array.append({
'outcome_name': outcome.column_name,
'outcome_value': outcome.float_value
})
# If no outcomes in database, create default ones from match odds # Limit to 5 matches total
if not outcomes_array: display_matches = all_matches[:5]
outcomes_array = [ logger.info(f"[FIXTURES API] Processing {len(display_matches)} matches for display")
{'outcome_name': 'WIN1', 'outcome_value': float(match.odds_fighter1) if match.odds_fighter1 else 1.0},
{'outcome_name': 'X', 'outcome_value': float(match.odds_draw) if match.odds_draw else 3.0},
{'outcome_name': 'WIN2', 'outcome_value': float(match.odds_fighter2) if match.odds_fighter2 else 1.0},
{'outcome_name': 'UNDER', 'outcome_value': 1.75},
{'outcome_name': 'OVER', 'outcome_value': 2.05}
]
match_data = { fixtures_data = []
'id': match.id, for i, match in enumerate(display_matches):
'match_number': match.match_number, try:
'fixture_id': match.fixture_id, logger.info(f"[FIXTURES API] Processing match {i+1}: id={match.id}, match_number={match.match_number}")
'fighter1_township': match.fighter1_township,
'fighter2_township': match.fighter2_township, # Get outcomes from MatchOutcomeModel
'venue_kampala_township': match.venue_kampala_township, outcomes = session.query(MatchOutcomeModel).filter_by(match_id=match.id).all()
'status': match.status, logger.info(f"[FIXTURES API] Found {len(outcomes)} outcomes for match {match.id}")
'start_time': match.start_time.isoformat() if match.start_time else None,
'result': match.result, # Format outcomes as array expected by template
'outcomes': outcomes_array, # Array format expected by template outcomes_array = []
# Keep odds for backwards compatibility for outcome in outcomes:
'odds': { outcomes_array.append({
'fighter1': float(match.odds_fighter1) if match.odds_fighter1 else 1.0, 'outcome_name': outcome.column_name,
'fighter2': float(match.odds_fighter2) if match.odds_fighter2 else 1.0, 'outcome_value': outcome.float_value
'draw': float(match.odds_draw) if match.odds_draw else 3.0 })
}
} # If no outcomes in database, create default ones from match odds
fixtures_data.append(match_data) if not outcomes_array:
outcomes_array = [
logger.debug(f"Retrieved {len(fixtures_data)} matches from database (yesterday: {len(yesterday_incomplete_matches)}, today: {len(today_matches)})") {'outcome_name': 'WIN1', 'outcome_value': float(match.odds_fighter1) if match.odds_fighter1 else 1.0},
return jsonify(fixtures_data) {'outcome_name': 'X', 'outcome_value': float(match.odds_draw) if match.odds_draw else 3.0},
{'outcome_name': 'WIN2', 'outcome_value': float(match.odds_fighter2) if match.odds_fighter2 else 1.0},
{'outcome_name': 'UNDER', 'outcome_value': 1.75},
{'outcome_name': 'OVER', 'outcome_value': 2.05}
]
match_data = {
'id': match.id,
'match_number': match.match_number,
'fixture_id': match.fixture_id,
'fighter1_township': match.fighter1_township,
'fighter2_township': match.fighter2_township,
'venue_kampala_township': match.venue_kampala_township,
'status': match.status,
'start_time': match.start_time.isoformat() if match.start_time else None,
'result': match.result,
'outcomes': outcomes_array, # Array format expected by template
# Keep odds for backwards compatibility
'odds': {
'fighter1': float(match.odds_fighter1) if match.odds_fighter1 else 1.0,
'fighter2': float(match.odds_fighter2) if match.odds_fighter2 else 1.0,
'draw': float(match.odds_draw) if match.odds_draw else 3.0
}
}
fixtures_data.append(match_data)
logger.info(f"[FIXTURES API] Successfully processed match {match.id}")
except Exception as match_error:
logger.error(f"[FIXTURES API] Error processing match {match.id}: {match_error}")
continue
logger.info(f"[FIXTURES API] Returning {len(fixtures_data)} matches")
return jsonify(fixtures_data)
finally: finally:
session.close() session.close()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment