Fix overlay fixtures API to use same query as Qt player

- Use timezone-aware date filtering (get_today_venue_date, venue_to_utc_datetime)
- Query today's matches and yesterday's incomplete matches
- Exclude terminal states (done, end, cancelled, failed, paused)
- Limit to 5 matches total, same as Qt player
- Add debug logging for match counts
parent 10fb640e
......@@ -10721,21 +10721,57 @@ def get_overlay_fixtures():
Equivalent to Qt WebChannel getFixtureData() method.
Returns upcoming and live matches for fixtures overlay.
Uses the same timezone-aware date filtering as Qt player.
"""
try:
from ..database.models import MatchModel, MatchOutcomeModel
from datetime import datetime, timedelta
from ..utils.timezone_utils import get_today_venue_date, venue_to_utc_datetime
session = api_bp.db_manager.get_session()
try:
# Get upcoming and live matches (using correct status values)
matches = session.query(MatchModel).filter(
MatchModel.status.in_(['pending', 'scheduled', 'bet', 'ingame', 'done']),
# Get today's date in venue timezone for proper date handling (same as Qt player)
today_venue = get_today_venue_date(api_bp.db_manager)
yesterday_venue = today_venue - timedelta(days=1)
# Convert venue dates to UTC datetime ranges for database queries
today_start_utc = venue_to_utc_datetime(datetime.combine(today_venue, datetime.min.time()), api_bp.db_manager)
today_end_utc = venue_to_utc_datetime(datetime.combine(today_venue, datetime.max.time()), api_bp.db_manager)
yesterday_start_utc = venue_to_utc_datetime(datetime.combine(yesterday_venue, datetime.min.time()), api_bp.db_manager)
yesterday_end_utc = venue_to_utc_datetime(datetime.combine(yesterday_venue, datetime.max.time()), api_bp.db_manager)
# Get active matches for today (non-terminal states) - same as Qt player
today_matches = session.query(MatchModel).filter(
MatchModel.start_time.isnot(None),
MatchModel.start_time >= today_start_utc,
MatchModel.start_time < today_end_utc,
MatchModel.status.notin_(['done', 'end', 'cancelled', 'failed', 'paused']),
MatchModel.active_status == True
).order_by(MatchModel.start_time.asc()).all()
# Check if there are any incomplete matches from yesterday - same as Qt player
yesterday_incomplete_matches = session.query(MatchModel).filter(
MatchModel.start_time.isnot(None),
MatchModel.start_time >= yesterday_start_utc,
MatchModel.start_time < yesterday_end_utc,
MatchModel.status.notin_(['done', 'end', 'cancelled', 'failed', 'paused']),
MatchModel.active_status == True
).order_by(MatchModel.match_number).all()
).order_by(MatchModel.start_time.asc()).all()
# Combine matches: yesterday first (if any incomplete), then today
all_matches = []
if yesterday_incomplete_matches:
logger.debug(f"Found {len(yesterday_incomplete_matches)} incomplete matches from yesterday - including them")
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 matches:
for match in display_matches:
# Get outcomes from MatchOutcomeModel
outcomes = session.query(MatchOutcomeModel).filter_by(match_id=match.id).all()
......@@ -10777,6 +10813,7 @@ def get_overlay_fixtures():
}
fixtures_data.append(match_data)
logger.debug(f"Retrieved {len(fixtures_data)} matches from database (yesterday: {len(yesterday_incomplete_matches)}, today: {len(today_matches)})")
return jsonify(fixtures_data)
finally:
......
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