Documentation
¶
Overview ¶
Package analytics provides the analytics service interface. This service handles token tracking, metrics, and economics calculations.
Index ¶
- type AnalyticsRepository
- type AnalyticsService
- type CommandStats
- type EconomicsResponse
- type FilterUsage
- type HourlyCount
- type MetricsRequest
- type MetricsResponse
- type RecordRequest
- type Service
- func (s *Service) GetEconomics(ctx context.Context) (*EconomicsResponse, error)
- func (s *Service) GetMetrics(ctx context.Context, req *MetricsRequest) (*MetricsResponse, error)
- func (s *Service) GetTopCommands(ctx context.Context, limit int) ([]CommandStats, error)
- func (s *Service) Record(ctx context.Context, req *RecordRequest) error
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 ¶
FilterUsage represents filter usage statistics.
type HourlyCount ¶
HourlyCount represents hourly distribution.
type MetricsRequest ¶
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 ¶
GetTopCommands implements AnalyticsService.