analytics

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package analytics provides the analytics service interface. This service handles token tracking, metrics, and economics calculations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AnalyticsRepository

type AnalyticsRepository interface {
	Save(ctx context.Context, record *RecordRequest) error
	Query(ctx context.Context, req *MetricsRequest) (*MetricsResponse, error)
	GetTopCommands(ctx context.Context, limit int) ([]CommandStats, error)
}

AnalyticsRepository defines the storage interface.

type AnalyticsService

type AnalyticsService interface {
	// Record saves a command execution record.
	Record(ctx context.Context, req *RecordRequest) error

	// GetMetrics returns aggregated metrics.
	GetMetrics(ctx context.Context, req *MetricsRequest) (*MetricsResponse, error)

	// GetEconomics returns cost analysis.
	GetEconomics(ctx context.Context) (*EconomicsResponse, error)

	// GetTopCommands returns the most used commands.
	GetTopCommands(ctx context.Context, limit int) ([]CommandStats, error)
}

AnalyticsService defines the interface for the analytics service.

type CommandStats

type CommandStats struct {
	Command    string
	Count      int64
	AvgSavings float64
	TotalSaved int64
	LastUsed   time.Time
}

CommandStats represents statistics for a command.

type EconomicsResponse

type EconomicsResponse struct {
	TokensSaved        int64
	EstimatedCostSaved float64
	ModelUsed          string
	CostPerToken       float64
	QuotaUsed          float64
	QuotaRemaining     float64
}

EconomicsResponse contains cost analysis.

type FilterUsage

type FilterUsage struct {
	FilterName string
	Count      int64
	AvgSavings float64
}

FilterUsage represents filter usage statistics.

type HourlyCount

type HourlyCount struct {
	Hour  int
	Count int64
}

HourlyCount represents hourly distribution.

type MetricsRequest

type MetricsRequest struct {
	StartTime time.Time
	EndTime   time.Time
	SessionID string
}

MetricsRequest filters metrics by time range.

type MetricsResponse

type MetricsResponse struct {
	TotalCommands      int64
	TotalTokensSaved   int64
	TotalTokensIn      int64
	TotalTokensOut     int64
	AverageSavings     float64
	P50LatencyMs       float64
	P99LatencyMs       float64
	TopFilters         []FilterUsage
	HourlyDistribution []HourlyCount
}

MetricsResponse contains aggregated metrics.

type RecordRequest

type RecordRequest struct {
	Command        string        // Command executed
	OriginalTokens int           // Tokens before compression
	FilteredTokens int           // Tokens after compression
	Duration       time.Duration // Execution duration
	ExitCode       int           // Command exit code
	FilterMode     string        // Filter mode used
	SessionID      string        // Session identifier
}

RecordRequest is the input for recording a command.

type Service

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

Service implements AnalyticsService.

func NewService

func NewService(db AnalyticsRepository) *Service

NewService creates a new analytics service.

func (*Service) GetEconomics

func (s *Service) GetEconomics(ctx context.Context) (*EconomicsResponse, error)

GetEconomics implements AnalyticsService.

func (*Service) GetMetrics

func (s *Service) GetMetrics(ctx context.Context, req *MetricsRequest) (*MetricsResponse, error)

GetMetrics implements AnalyticsService.

func (*Service) GetTopCommands

func (s *Service) GetTopCommands(ctx context.Context, limit int) ([]CommandStats, error)

GetTopCommands implements AnalyticsService.

func (*Service) Record

func (s *Service) Record(ctx context.Context, req *RecordRequest) error

Record implements AnalyticsService.

Directories

Path Synopsis
Package grpc provides gRPC server implementation for the analytics service.
Package grpc provides gRPC server implementation for the analytics service.

Jump to

Keyboard shortcuts

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