Documentation
¶
Overview ¶
Package abtest provides A/B testing capabilities for TokMan
Index ¶
- type CI
- type Experiment
- type ExperimentConfig
- type ExperimentType
- type InMemoryStorage
- type Manager
- func (m *Manager) Analyze(ctx context.Context, id string) (*Results, error)
- func (m *Manager) AssignVariant(ctx context.Context, experimentID, userID string) (*Variant, error)
- func (m *Manager) CreateExperiment(config ExperimentConfig) (*Experiment, error)
- func (m *Manager) GetExperiment(id string) (*Experiment, error)
- func (m *Manager) ListExperiments() []*Experiment
- func (m *Manager) RecordEvent(ctx context.Context, experimentID, userID, eventType string, value float64) error
- func (m *Manager) Start(ctx context.Context, id string) error
- func (m *Manager) Stop(ctx context.Context, id string) error
- type RandomizationMethod
- type Results
- type Segment
- type SegmentCondition
- type Status
- type Storage
- type Variant
- type VariantConfig
- type VariantMetrics
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Experiment ¶
type Experiment struct {
ID string
Name string
Description string
Hypothesis string
Status Status
Type ExperimentType
Variants []Variant
TrafficAllocation float64
PrimaryMetric string
SecondaryMetrics []string
SampleSize int
Duration time.Duration
StartTime time.Time
EndTime time.Time
Segments []Segment
Randomization RandomizationMethod
Results *Results
// contains filtered or unexported fields
}
Experiment represents an A/B test experiment
type ExperimentConfig ¶
type ExperimentConfig struct {
Name string
Description string
Hypothesis string
Type ExperimentType
Variants []VariantConfig
TrafficAllocation float64
PrimaryMetric string
SecondaryMetrics []string
SampleSize int
Duration time.Duration
Segments []Segment
Randomization RandomizationMethod
}
ExperimentConfig holds experiment configuration
type ExperimentType ¶
type ExperimentType string
ExperimentType defines the type of experiment
const ( TypeAB ExperimentType = "ab" TypeMultivariate ExperimentType = "multivariate" TypeBandit ExperimentType = "bandit" TypeSwitchback ExperimentType = "switchback" )
type InMemoryStorage ¶
type InMemoryStorage struct {
// contains filtered or unexported fields
}
InMemoryStorage provides in-memory storage for experiments
func NewInMemoryStorage ¶
func NewInMemoryStorage() *InMemoryStorage
NewInMemoryStorage creates in-memory storage
func (*InMemoryStorage) List ¶
func (s *InMemoryStorage) List() ([]*Experiment, error)
List lists all experiments
func (*InMemoryStorage) Load ¶
func (s *InMemoryStorage) Load(id string) (*Experiment, error)
Load loads an experiment
func (*InMemoryStorage) Save ¶
func (s *InMemoryStorage) Save(exp *Experiment) error
Save saves an experiment
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager manages A/B test experiments
func (*Manager) AssignVariant ¶
AssignVariant assigns a user to a variant
func (*Manager) CreateExperiment ¶
func (m *Manager) CreateExperiment(config ExperimentConfig) (*Experiment, error)
CreateExperiment creates a new experiment
func (*Manager) GetExperiment ¶
func (m *Manager) GetExperiment(id string) (*Experiment, error)
GetExperiment returns experiment details
func (*Manager) ListExperiments ¶
func (m *Manager) ListExperiments() []*Experiment
ListExperiments returns all experiments
func (*Manager) RecordEvent ¶
func (m *Manager) RecordEvent(ctx context.Context, experimentID, userID, eventType string, value float64) error
RecordEvent records an event for a user in an experiment
type RandomizationMethod ¶
type RandomizationMethod string
RandomizationMethod defines how users are assigned to variants
const ( RandomizationRandom RandomizationMethod = "random" RandomizationUserID RandomizationMethod = "user_id" RandomizationSession RandomizationMethod = "session" RandomizationDevice RandomizationMethod = "device" RandomizationWeighted RandomizationMethod = "weighted" )
type Results ¶
type Results struct {
StartTime time.Time
EndTime time.Time
TotalParticipants int64
Winner *Variant
ConfidenceLevel float64
StatisticalPower float64
PValues map[string]float64
EffectSizes map[string]float64
ConfidenceIntervals map[string]CI
Recommendation string
}
Results holds experiment results
type Segment ¶
type Segment struct {
Name string
Condition SegmentCondition
TrafficAllocation float64
}
Segment defines user segments
type SegmentCondition ¶
SegmentCondition defines a segment condition
type Storage ¶
type Storage interface {
Save(experiment *Experiment) error
Load(id string) (*Experiment, error)
List() ([]*Experiment, error)
}
Storage interface for persisting experiments
type Variant ¶
type Variant struct {
ID string
Name string
Description string
TrafficPercent float64
Config map[string]interface{}
Metrics VariantMetrics
IsControl bool
IsWinner bool
}
Variant represents an experiment variant