Skip to content

fix: _query_transfer_stats and _query_invalid_scans in report_service return hardcoded zeros #123

@BigBen-7

Description

@BigBen-7

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

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingreportsReport generation and delivery

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions