analytics

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package analytics records and reports local concept retrieval events.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseSince

func ParseSince(value string, now time.Time) (*time.Time, error)

ParseSince converts a user-facing duration into an absolute UTC cutoff. It accepts time.ParseDuration values and day values such as 7d.

Types

type ConceptLoad

type ConceptLoad struct {
	OccurredAt time.Time
	BatchID    string
	ConceptID  string
	EntryPoint EntryPoint
}

ConceptLoad is one successfully rendered concept retrieval event.

func NewBatch

func NewBatch(entryPoint EntryPoint, conceptIDs []string) ([]ConceptLoad, error)

NewBatch creates one timestamped, deduplicated batch of concept loads.

type ConceptUsage

type ConceptUsage struct {
	ConceptID string
	LoadCount int
}

ConceptUsage contains one concept's retrieval count.

type EntryPoint

type EntryPoint string

EntryPoint identifies the command that returned a concept body.

const (
	EntryPointShow    EntryPoint = "show"
	EntryPointContext EntryPoint = "context"
)

type Provider

type Provider string

Provider identifies a local analytics storage format.

const (
	ProviderSQLite Provider = "sqlite"
	ProviderCSV    Provider = "csv"
)

type Reader

type Reader interface {
	Report(context.Context, ReportOptions) (Report, error)
}

Reader produces aggregate analytics reports.

type Recorder

type Recorder interface {
	RecordConceptLoads(context.Context, []ConceptLoad) error
}

Recorder persists concept retrieval events.

type Report

type Report struct {
	Enabled                 bool
	Provider                Provider
	Since                   *time.Time
	ConceptLoads            int
	RetrievalBatches        int
	AverageConceptsPerBatch float64
	EntryPoints             map[EntryPoint]int
	TopConcepts             []ConceptUsage
	RecentBatches           []RetrievalBatch
}

Report contains aggregate concept usage and retrieval batches.

type ReportOptions

type ReportOptions struct {
	Since *time.Time
	Limit int
}

ReportOptions controls analytics report filtering and result limits.

type RetrievalBatch

type RetrievalBatch struct {
	BatchID    string
	OccurredAt time.Time
	EntryPoint EntryPoint
	ConceptIDs []string
}

RetrievalBatch groups concepts returned by one retrieval invocation.

type Service

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

Service isolates analytics persistence from retrieval commands.

func New

func New(settings Settings) *Service

New creates a lazy analytics service. Provider initialization is deferred until recording or reporting so unrelated commands do not create storage.

func (*Service) Close

func (service *Service) Close() error

Close releases provider resources when they were initialized.

func (*Service) RecordConceptLoads

func (service *Service) RecordConceptLoads(ctx context.Context, loads []ConceptLoad) error

RecordConceptLoads records events when analytics is enabled.

func (*Service) Report

func (service *Service) Report(ctx context.Context, options ReportOptions) (Report, error)

Report reads analytics when enabled. Initialization and storage errors are returned because reporting is the primary purpose of this command.

type Settings

type Settings struct {
	Enabled   bool
	Provider  Provider
	Directory string
}

Settings configures the local analytics service.

Jump to

Keyboard shortcuts

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