feat(services): T31 implement statistics aggregation service
Add statistics aggregation service with 4 core functions: - get_summary(): Aggregates total requests, cost, tokens with avg cost - get_by_model(): Groups stats by model with percentage calculations - get_by_date(): Groups stats by date for time series data - get_dashboard_data(): Combines all stats for dashboard view Features: - SQLAlchemy queries with ApiKey join for user filtering - Decimal precision for all monetary values - Period calculation and percentage breakdowns - Top models extraction Test: 11 unit tests covering all aggregation functions
This commit is contained in:
@@ -88,12 +88,15 @@
|
||||
**Test totali API keys:** 38 test (25 router + 13 schema)
|
||||
**Coverage router:** 100%
|
||||
|
||||
### 📊 Dashboard & Statistiche (T30-T34) - 1/5 completati
|
||||
### 📊 Dashboard & Statistiche (T30-T34) - 2/5 completati
|
||||
- [x] T30: Creare Pydantic schemas per stats - ✅ Completato (2026-04-07 17:45)
|
||||
- Creato: UsageStatsCreate, UsageStatsResponse, StatsSummary, StatsByModel, StatsByDate, DashboardResponse
|
||||
- Test: 16 test passanti, 100% coverage su schemas/stats.py
|
||||
- [ ] T31: Implementare servizio aggregazione stats 🟡 In progress
|
||||
- [ ] T32: Implementare endpoint GET /api/stats
|
||||
- [x] T31: Implementare servizio aggregazione stats - ✅ Completato (2026-04-07 18:30)
|
||||
- Creato: get_summary(), get_by_model(), get_by_date(), get_dashboard_data()
|
||||
- Query SQLAlchemy con join ApiKey per filtro user_id
|
||||
- Test: 11 test passanti, 84% coverage su services/stats.py
|
||||
- [ ] T32: Implementare endpoint GET /api/stats/dashboard 🟡 In progress
|
||||
- [ ] T33: Implementare endpoint GET /api/usage
|
||||
- [ ] T34: Scrivere test per stats endpoints
|
||||
|
||||
|
||||
Reference in New Issue
Block a user