Statistics Service
Component Detail
Service Layer
medium complexity
mobile
1
Dependencies
1
Dependents
4
Entities
0
Integrations
Description
Riverpod AsyncNotifierProvider that queries the local Drift database to aggregate the current user's activity data into typed statistics models. Handles client-side date bucketing (week/month/year) entirely offline, computes streaks and personal bests, and invalidates automatically on sync-completion events so figures update without a manual refresh.
statistics-service
Responsibilities
- Query the Drift activities table filtered by current user ID and the selected time-range bucket
- Aggregate total activity count, total hours, unique contacts supported, and per-bucket series data
- Compute current streak (consecutive days/weeks with at least one activity) and personal-best record
- Calculate month-over-month delta for the motivational comparison card
- Listen to sync-completion events from the background sync service and invalidate provider state
Interfaces
watch(TimeBucket) → AsyncValue<PersonalStatsModel>
getStreak() → StreakModel
getPersonalBest() → PersonalBestModel
getMonthDelta() → MonthDeltaModel
invalidateOnSyncComplete() → void
Relationships
Related Data Entities (4)
Data entities managed by this component