stats

package
v0.8.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 23, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyRange

func ApplyRange(data usage.Data, from, to time.Time) usage.Data

ApplyRange filters data to events with timestamps in [from, to) local time. Zero values mean unbounded on that side.

func ParseRange

func ParseRange(s string, loc *time.Location) (from, to time.Time, err error)

ParseRange accepts "YYYY-MM-DD" (single day) or "YYYY-MM-DD:YYYY-MM-DD" (inclusive range) in local time and returns the [from, to) half-open window.

Types

type Comparison added in v0.6.0

type Comparison struct {
	Prompts             Delta
	Turns               Delta
	InputTokens         Delta
	CacheCreationTokens Delta
	CacheReadTokens     Delta
	OutputTokens        Delta
	TotalTokens         Delta
	CostUSD             Delta
}

Comparison holds per-metric Deltas comparing two Totals snapshots.

func Compare added in v0.6.0

func Compare(a, b Totals) Comparison

Compare builds a Comparison from two Totals (a = baseline, b = current).

type CostBreakdownReport added in v0.8.2

type CostBreakdownReport struct {
	Overall   ModelBreakdown // Model = "overall"
	ByModel   []ModelBreakdown
	TotalCost float64
}

CostBreakdownReport aggregates per-model breakdowns plus an overall row.

func BuildCostBreakdown added in v0.8.2

func BuildCostBreakdown(r Report) CostBreakdownReport

BuildCostBreakdown derives the 5-bucket breakdown per model (sorted by cost descending) plus an "overall" aggregate.

type CostBucket added in v0.8.2

type CostBucket struct {
	Kind   string // "input" | "cache_write_5m" | "cache_write_1h" | "cache_read" | "output"
	Tokens int
	Rate   float64
	Cost   float64
	Pct    float64 // 0..100, share of total cost (the parent ModelBreakdown.TotalCost or overall)
}

CostBucket is a per-kind cost row decorated with percent-of-total.

type DayStat

type DayStat struct {
	Day     string
	Totals  Totals
	ByModel map[string]Totals
}

type Delta added in v0.6.0

type Delta struct {
	A     float64 // value for range A
	B     float64 // value for range B
	Delta float64 // B - A (absolute; negative means B < A)
	Pct   float64 // (B - A) / A * 100; 0.0 when A == 0
	Gt    bool    // true when B > A strictly
}

Delta holds the A value, B value, and derived diff metrics between two ranges for a single metric. When A is zero, Pct is 0.0 (division-by-zero guard).

type FilterPreset

type FilterPreset int
const (
	FilterAll FilterPreset = iota
	FilterToday
	FilterYesterday
	FilterLast7Days
	FilterLast30Days
	FilterLast90Days
	FilterThisWeek
	FilterThisMonth
)

func ResolvePreset added in v0.3.0

func ResolvePreset(name string) (FilterPreset, bool)

ResolvePreset maps common range aliases (today, last-7d, this-month, ...) to a FilterPreset. Returns false if the alias is unknown.

func (FilterPreset) Apply

func (p FilterPreset) Apply(data usage.Data) usage.Data

func (FilterPreset) Label

func (p FilterPreset) Label() string

func (FilterPreset) Next

func (p FilterPreset) Next() FilterPreset

func (FilterPreset) Prev

func (p FilterPreset) Prev() FilterPreset

func (FilterPreset) Range

func (p FilterPreset) Range(now time.Time) (time.Time, time.Time)

Range returns [from, to) in local time. Zero values mean unbounded.

type ModelBreakdown added in v0.8.2

type ModelBreakdown struct {
	Model     string
	Buckets   []CostBucket
	TotalCost float64
	Pct       float64 // share of grand total across all models
}

ModelBreakdown holds the 5-bucket breakdown for a single model.

type ModelStat

type ModelStat struct {
	Model  string
	Totals Totals
}

type ProjectStat

type ProjectStat struct {
	Cwd    string
	Totals Totals
}

type Report

type Report struct {
	Overall       Totals
	ByDay         []DayStat
	ByModel       []ModelStat
	BySession     []SessionStat
	ByProject     []ProjectStat
	Tools         ToolStats
	Models        []string // stable list of model names seen (sorted by total usage desc)
	DateRange     [2]time.Time
	PromptsByHour [24]int // prompts per hour-of-day aggregated across all filtered data
}

func Build

func Build(data usage.Data) Report

type SessionDetail added in v0.6.0

type SessionDetail struct {
	SessionID string
	Cwd       string
	FirstSeen time.Time
	LastSeen  time.Time
	Models    []string      // sorted, unique
	Totals    Totals        // session totals
	Turns     []SessionTurn // chronological, oldest first
}

SessionDetail is the per-session drill-down report.

func BuildSessionDetail added in v0.6.0

func BuildSessionDetail(data usage.Data, sessionID string) (SessionDetail, bool)

BuildSessionDetail returns the detail for a specific session. If sessionID has length >= 8 it also matches by prefix (so short ids work). Returns (SessionDetail{}, false) when no session matches.

type SessionStat

type SessionStat struct {
	SessionID string
	Cwd       string
	FirstSeen time.Time
	LastSeen  time.Time
	Models    map[string]struct{}
	Totals    Totals
}

type SessionTurn added in v0.6.0

type SessionTurn struct {
	Timestamp time.Time
	Model     string
	// Totals is the usage of this single Event (not cumulative).
	Totals Totals
	// Tools contains the tool_use items the assistant emitted in this turn.
	// Empty if the turn had no tool calls.
	Tools []string
}

SessionTurn captures one assistant turn inside a session.

type ToolEntry

type ToolEntry struct {
	Name  string
	Count int
}

type ToolStats

type ToolStats struct {
	Builtins []ToolEntry
	MCPs     []ToolEntry // aggregated per tool name ("server/tool")
	Servers  []ToolEntry // aggregated per MCP server
	Skills   []ToolEntry
	Agents   []ToolEntry
	Total    int
}

type Totals

type Totals struct {
	InputTokens           int
	OutputTokens          int
	CacheCreationTokens   int // total = 5m + 1h (kept for backwards compat)
	CacheCreation5mTokens int
	CacheCreation1hTokens int
	CacheReadTokens       int
	Turns                 int
	Prompts               int
	Cost                  float64 // USD, summed per-event
}

func (Totals) GrandTotal

func (t Totals) GrandTotal() int

func (Totals) TotalInput

func (t Totals) TotalInput() int

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL