Description
src/report_service.py contains two stub functions that always return placeholder zeros:
def _query_transfer_stats(target_date=None) -> Dict[str, int]:
return {"total_transfers": 0} # ← always zero
def _query_invalid_scans(target_date=None) -> Dict[str, int]:
return {"invalid_scans": 0} # ← always zero
Every generated daily report therefore shows zero transfers and zero invalid scans regardless of actual activity, making the report misleading and useless for operations.
Requirements & context
- Implement
_query_transfer_stats(target_date) to query the ticket_transfers table (already modelled in src/analytics/models.py) filtering by transfer_timestamp::date = target_date
- Implement
_query_invalid_scans(target_date) to query the invalid_attempts table filtering by attempt_timestamp::date = target_date
- Both functions must handle
DATABASE_URL not set gracefully (return zeros with a warning log, as the existing pattern does)
- Add unit tests for both functions using a mocked SQLAlchemy engine
Suggested execution
git checkout -b fix/report-service-real-queries
- Implement both query functions using the existing
_pg_engine() helper
- Match the existing query style (raw
text() with named params)
- Write tests in
tests/test_report_service.py
Guidelines
- PR must include:
Closes #[issue_id]
- Timeframe: 48 hours
Description
src/report_service.pycontains two stub functions that always return placeholder zeros:Every generated daily report therefore shows zero transfers and zero invalid scans regardless of actual activity, making the report misleading and useless for operations.
Requirements & context
_query_transfer_stats(target_date)to query theticket_transferstable (already modelled insrc/analytics/models.py) filtering bytransfer_timestamp::date = target_date_query_invalid_scans(target_date)to query theinvalid_attemptstable filtering byattempt_timestamp::date = target_dateDATABASE_URLnot set gracefully (return zeros with a warning log, as the existing pattern does)Suggested execution
_pg_engine()helpertext()with named params)tests/test_report_service.pyGuidelines
Closes #[issue_id]