stats

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package stats computes aggregate statistics from nightshift run data. It reads from existing report JSONs, run_history, snapshots, and projects tables.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BudgetProjection

type BudgetProjection struct {
	Provider               string     `json:"provider"`
	WeeklyBudget           int64      `json:"weekly_budget"`
	CurrentUsedPct         float64    `json:"current_used_pct"`
	AvgDailyUsage          int64      `json:"avg_daily_usage"`
	AvgHourlyUsage         float64    `json:"avg_hourly_usage"`
	RemainingTokens        int64      `json:"remaining_tokens"`
	EstDaysRemaining       int        `json:"est_days_remaining"`
	EstHoursRemaining      float64    `json:"est_hours_remaining,omitempty"`
	EstExhaustAt           *time.Time `json:"est_exhaust_at,omitempty"`
	ResetAt                *time.Time `json:"reset_at,omitempty"`
	TimeUntilResetSec      int64      `json:"time_until_reset_sec,omitempty"`
	ResetHint              string     `json:"reset_hint,omitempty"`
	WillExhaustBeforeReset *bool      `json:"will_exhaust_before_reset,omitempty"`
	Source                 string     `json:"source"`
}

BudgetProjection estimates remaining budget days from snapshot data.

type Duration

type Duration struct {
	time.Duration
}

Duration wraps time.Duration for clean JSON serialization as seconds.

func (Duration) MarshalJSON

func (d Duration) MarshalJSON() ([]byte, error)

MarshalJSON serializes Duration as integer seconds.

func (Duration) String

func (d Duration) String() string

String returns a human-readable duration string.

func (*Duration) UnmarshalJSON

func (d *Duration) UnmarshalJSON(b []byte) error

UnmarshalJSON deserializes Duration from integer seconds.

type ProjectStats

type ProjectStats struct {
	Name      string `json:"name"`
	RunCount  int    `json:"run_count"`
	TaskCount int    `json:"task_count"`
}

ProjectStats summarizes activity for a single project.

type Stats

type Stats struct {
	// contains filtered or unexported fields
}

Stats computes aggregate statistics from nightshift data sources.

func New

func New(database *db.DB, reportsDir string) *Stats

New creates a Stats instance.

func NewWithBudgetSource added in v0.3.0

func NewWithBudgetSource(database *db.DB, reportsDir string, source budget.BudgetSource) *Stats

NewWithBudgetSource creates a Stats instance with a calibrated budget source.

func (*Stats) Compute

func (s *Stats) Compute() (*StatsResult, error)

Compute aggregates all available data into a StatsResult.

type StatsResult

type StatsResult struct {
	// Run overview
	TotalRuns      int        `json:"total_runs"`
	FirstRunAt     *time.Time `json:"first_run_at,omitempty"`
	LastRunAt      *time.Time `json:"last_run_at,omitempty"`
	TotalDuration  Duration   `json:"total_duration"`
	AvgRunDuration Duration   `json:"avg_run_duration"`

	// Task outcomes
	TasksCompleted int     `json:"tasks_completed"`
	TasksFailed    int     `json:"tasks_failed"`
	TasksSkipped   int     `json:"tasks_skipped"`
	SuccessRate    float64 `json:"success_rate"`

	// PR output
	PRsCreated int      `json:"prs_created"`
	PRURLs     []string `json:"pr_urls,omitempty"`

	// Token usage
	TotalTokensUsed int `json:"total_tokens_used"`
	AvgTokensPerRun int `json:"avg_tokens_per_run"`

	// Budget
	BudgetProjection  *BudgetProjection  `json:"budget_projection,omitempty"` // Deprecated: use BudgetProjections.
	BudgetProjections []BudgetProjection `json:"budget_projections,omitempty"`

	// Projects
	TotalProjects    int            `json:"total_projects"`
	ProjectBreakdown []ProjectStats `json:"project_breakdown,omitempty"`

	// Task types
	TaskTypeBreakdown map[string]int `json:"task_type_breakdown,omitempty"`
}

StatsResult holds all computed statistics, JSON-serializable.

Jump to

Keyboard shortcuts

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