WAGERBABE DOCS
All Stories
4-5-1-velocity-checksDoneEpic 4.5

Story 4.5.1: Velocity Checks

Status: done

Tasks

  • **Task 1: Redis Velocity Tracking Infrastructure** (AC: 1)
    • 1.1 Create VelocityChecker class in `server/app/services/fraud/velocity_checker.py`
    • 1.2 Implement `check_and_record(user_id)` method with atomic Redis INCR
    • 1.3 Configure Redis key patterns with appropriate TTLs
    • 1.4 Add rolling average calculation for spike detection
  • **Task 2: Velocity Violation Detection** (AC: 2, 3)
    • 2.1 Implement threshold checks (10/min, 50/hr, 3x spike)
    • 2.2 Create ViolationType enum: HIGH_FREQUENCY_MINUTE, HIGH_FREQUENCY_HOUR, SUDDEN_SPIKE
    • 2.3 Create VelocityResult dataclass with allowed, violations, counts
    • 2.4 Add database migration for velocity_violations table
  • **Task 3: Fraud Review Queue Integration** (AC: 4)
    • 3.1 Create fraud_reviews table migration
    • 3.2 Implement `_flag_for_review(user_id, violations)` method
    • 3.3 Calculate composite velocity_score (0-100)
    • 3.4 Add indexes for efficient agent queries
  • **Task 4: Temporary Betting Locks** (AC: 5)
    • 4.1 Create temporary_locks table migration
    • 4.2 Implement `_apply_temporary_lock(user_id, duration)` method
    • 4.3 Add lock check middleware to bet placement endpoint
    • 4.4 Return 403 with Retry-After header when locked
    • 4.5 Create `check_user_lock(user_id)` helper function
    • 4.6 Add agent ability to lift locks early
  • **Task 5: Agent Dashboard Velocity Alerts** (AC: 6)
    • 5.1 Create GET /api/v1/agent/fraud/velocity-alerts endpoint
    • 5.2 Create VelocityAlertsTable React component
    • 5.3 Add real-time refresh (30s polling or SSE)
    • 5.4 Implement mobile-first responsive design
    • 5.5 Add resolve/dismiss actions for agents
  • **Task 6: Testing**
    • 6.1 Unit tests for VelocityChecker class
    • 6.2 Integration tests for Redis operations
    • 6.3 API endpoint tests with mock violations
    • 6.4 Frontend component tests

Progress

Tasks6/6
Acceptance Criteria0
Total Tasks6