Add data layer support for real-time usage visualization: - MinuteStats type: holds token counts for 5-minute buckets, enabling granular recent-activity views (12 buckets covering the last hour). - AggregateTodayHourly(): computes 24 hourly token buckets for the current local day by filtering sessions to today's date boundary and slotting each into the correct hour index. Tracks prompts, sessions, and total tokens per hour. - AggregateLastHour(): computes 12 five-minute token buckets for the last 60 minutes using reverse-offset bucketing (bucket 11 = most recent 5 minutes, bucket 0 = 55-60 minutes ago). Bounds-clamped to prevent off-by-one at the edges. Both functions filter on StartTime locality and skip zero-time sessions, consistent with existing aggregation patterns in the pipeline package. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
101 lines
2.2 KiB
Go
101 lines
2.2 KiB
Go
package model
|
|
|
|
import "time"
|
|
|
|
// SummaryStats holds the top-level aggregate across all sessions.
|
|
type SummaryStats struct {
|
|
TotalSessions int
|
|
TotalPrompts int
|
|
TotalAPICalls int
|
|
TotalDurationSecs int64
|
|
ActiveDays int
|
|
|
|
InputTokens int64
|
|
OutputTokens int64
|
|
CacheCreation5mTokens int64
|
|
CacheCreation1hTokens int64
|
|
CacheReadTokens int64
|
|
TotalBilledTokens int64
|
|
|
|
EstimatedCost float64
|
|
ActualCost *float64
|
|
CacheSavings float64
|
|
CacheHitRate float64
|
|
|
|
CostPerDay float64
|
|
TokensPerDay int64
|
|
SessionsPerDay float64
|
|
PromptsPerDay float64
|
|
MinutesPerDay float64
|
|
}
|
|
|
|
// DailyStats holds metrics for a single calendar day.
|
|
type DailyStats struct {
|
|
Date time.Time
|
|
Sessions int
|
|
Prompts int
|
|
APICalls int
|
|
DurationSecs int64
|
|
InputTokens int64
|
|
OutputTokens int64
|
|
CacheCreation5m int64
|
|
CacheCreation1h int64
|
|
CacheReadTokens int64
|
|
EstimatedCost float64
|
|
ActualCost *float64
|
|
}
|
|
|
|
// ModelStats holds aggregated metrics for a single model.
|
|
type ModelStats struct { //nolint:revive // renaming would break many call sites
|
|
Model string
|
|
APICalls int
|
|
InputTokens int64
|
|
OutputTokens int64
|
|
CacheCreation5m int64
|
|
CacheCreation1h int64
|
|
CacheReadTokens int64
|
|
EstimatedCost float64
|
|
SharePercent float64
|
|
TrendDirection int // -1, 0, +1 vs previous period
|
|
}
|
|
|
|
// ProjectStats holds aggregated metrics for a single project.
|
|
type ProjectStats struct {
|
|
Project string
|
|
Sessions int
|
|
Prompts int
|
|
TotalTokens int64
|
|
EstimatedCost float64
|
|
TrendDirection int
|
|
}
|
|
|
|
// HourlyStats holds prompt/session counts for one hour of the day.
|
|
type HourlyStats struct {
|
|
Hour int
|
|
Prompts int
|
|
Sessions int
|
|
Tokens int64
|
|
}
|
|
|
|
// WeeklyStats holds metrics for one calendar week.
|
|
type WeeklyStats struct {
|
|
WeekStart time.Time
|
|
Sessions int
|
|
Prompts int
|
|
TotalTokens int64
|
|
DurationSecs int64
|
|
EstimatedCost float64
|
|
}
|
|
|
|
// PeriodComparison holds current and previous period data for delta computation.
|
|
type PeriodComparison struct {
|
|
Current SummaryStats
|
|
Previous SummaryStats
|
|
}
|
|
|
|
// MinuteStats holds token counts for a 5-minute bucket.
|
|
type MinuteStats struct {
|
|
Minute int // 0-11 (bucket index within the hour)
|
|
Tokens int64
|
|
}
|