WAGERBABE DOCS
All Stories
4-5-2-unusual-pattern-detectionReviewEpic 4.5

Story 4.5.2: Unusual Pattern Detection

Status: review

Tasks

  • **Task 1: PatternDetector Class** (AC: 1, 2, 3)
    • 1.1 Create PatternDetector in `server/app/services/fraud/pattern_detector.py`
    • 1.2 Implement `analyze_bet(user_id, bet)` main entry point
    • 1.3 Implement `_check_opposite_side_betting()` method
    • 1.4 Implement `_check_max_bet_consistency()` method
    • 1.5 Implement `_check_suspicious_timing()` timing analysis
    • 1.6 Create PatternType enum and PatternResult dataclass
  • **Task 2: Database Schema** (AC: 4)
    • 2.1 Create pattern_detections table migration
    • 2.2 Add indexes on user_id, pattern_type, created_at
    • 2.3 Add fixture_id index for correlation queries (GIN index on metadata)
    • 2.4 Add RLS policies for agent/user access
  • **Task 3: Risk Score Integration** (AC: 5)
    • 3.1 Define PATTERN_WEIGHTS constant mapping
    • 3.2 Implement `get_risk_score(user_id)` method
    • 3.3 Integrate with risk score endpoint (40% weight)
    • 3.4 Add confidence-based score scaling
  • **Task 4: Pattern History API** (AC: 6)
    • 4.1 Create GET /api/v1/agent/fraud/customers/{user_id}/patterns endpoint
    • 4.2 Add pagination and pattern_type/severity filtering
    • 4.3 Include related bet details in response metadata
    • 4.4 Validate agent has access to customer
  • **Task 5: Agent Dashboard UI** (AC: 6)
    • 5.1 Create BettingPatternHistory React component
    • 5.2 Implement pattern type badges with severity colors
    • 5.3 Add expandable row for bet details
    • 5.4 Mobile-optimized card layout for small screens
  • **Task 6: Background Processing**
    • 6.1 Create hourly pattern analysis job
    • 6.2 Implement batch processing for efficiency
    • 6.3 Add lightweight real-time check on bet placement
  • **Task 7: Testing**
    • 7.1 Unit tests for each detection algorithm
    • 7.2 Integration tests with test bet data
    • 7.3 API endpoint tests
    • 7.4 Frontend component tests

Progress

Tasks6/7
Acceptance Criteria0
Total Tasks7