Add matches to incremental report sync payload

- Collect unique match IDs from bets being synced
- Query and include match data for all matches referenced by bets
- Add 'matches' array to report sync payload with full match details
- Fixes issue where extraction_stats was empty and matches were not sent with bets
parent 7039ed6d
......@@ -1155,6 +1155,51 @@ class ReportsSyncResponseHandler(ResponseHandler):
except Exception as e:
logger.warning(f"Failed to get cap compensation balance: {e}")
# Collect unique match IDs from bets to sync
unique_match_ids = set()
for bet in bets_to_sync:
bet_details = session.query(BetDetailModel).filter_by(
bet_id=bet.uuid
).filter(BetDetailModel.result != 'cancelled').all()
for detail in bet_details:
unique_match_ids.add(detail.match_id)
# Collect match data for all matches referenced by bets
matches_to_sync = []
if unique_match_ids:
matches = session.query(MatchModel).filter(
MatchModel.id.in_(unique_match_ids)
).all()
for match in matches:
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,
'start_time': match.start_time.isoformat() if match.start_time else None,
'end_time': match.end_time.isoformat() if match.end_time else None,
'result': match.result,
'winning_outcomes': match.winning_outcomes,
'under_over_result': match.under_over_result,
'done': match.done,
'running': match.running,
'status': match.status,
'filename': match.filename,
'file_sha1sum': match.file_sha1sum,
'active_status': match.active_status,
'zip_filename': match.zip_filename,
'zip_sha1sum': match.zip_sha1sum,
'zip_upload_status': match.zip_upload_status,
'zip_upload_progress': match.zip_upload_progress,
'zip_validation_status': match.zip_validation_status,
'fixture_active_time': match.fixture_active_time,
'accumulated_shortfall': float(match.accumulated_shortfall) if match.accumulated_shortfall else 0.0,
'cap_percent': float(match.cap_percent) if match.cap_percent else 70.0
}
matches_to_sync.append(match_data)
# Build report data payload (incremental - only new/changed data)
report_data = {
'sync_id': self._generate_sync_id(),
......@@ -1164,6 +1209,7 @@ class ReportsSyncResponseHandler(ResponseHandler):
'start_date': start_date.isoformat(),
'end_date': end_date.isoformat(),
'bets': [],
'matches': matches_to_sync, # Include matches associated with bets
'extraction_stats': [],
'cap_compensation_balance': cap_compensation_balance,
'summary': self._calculate_summary(bets_to_sync, stats), # Use bets_to_sync which have bet_details loaded
......
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