feat(stats): add daily statistics aggregation job and model

- Create `DailyStat` model for immutable daily metrics including
  request counts, tokens, latency, and top models.
- Implement `DailyStatsJob` to aggregate `log_records` from the previous
  day, running daily at 00:05 UTC.
- Register database migrations and schedule the job in the server.
- Add `last7d` and `last30d` period support to stats handler.
This commit is contained in:
zenfun
2026-01-02 22:20:37 +08:00
parent 7b20c35fba
commit 5b2b176a55
4 changed files with 296 additions and 3 deletions

View File

@@ -264,6 +264,12 @@ func periodWindow(period string) (time.Time, time.Time) {
case "month":
start := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, time.UTC)
return start, now
case "last7d":
start := now.AddDate(0, 0, -7)
return start, now
case "last30d":
start := now.AddDate(0, 0, -30)
return start, now
default:
return time.Time{}, time.Time{}
}