ab

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2025 License: BSD-3-Clause Imports: 10 Imported by: 1

README ΒΆ

Enhanced A/B Testing and Recommendation Framework

This Go package provides a comprehensive A/B testing and recommendation system with advanced features for experimentation, analytics, and configuration management.

Features

πŸ§ͺ A/B Testing Engine
  • Experiment Management: Create, manage, and analyze A/B tests
  • Consistent User Assignment: Hash-based user assignment ensuring consistency
  • Statistical Analysis: Built-in statistical significance testing
  • Multi-variate Testing: Support for experiments with multiple variants
  • Quality Control: Sample ratio mismatch detection and bias analysis
🎯 Multi-Armed Bandits
  • Multiple Algorithms: Epsilon-greedy, UCB, Thompson Sampling, Bayesian bandits
  • Real-time Optimization: Dynamic allocation based on performance
  • Regret Analysis: Track and minimize exploration costs
  • Automated Stopping: Smart recommendations for when to stop experiments
πŸ” Recommendation Engine
  • Multiple Algorithms: Content-based, collaborative filtering, popularity, trending
  • Hybrid Recommendations: Combine multiple algorithms with configurable weights
  • Real-time Learning: Update preferences based on user interactions
  • Contextual Recommendations: Support for contextual information
πŸ“Š Advanced Analytics
  • Comprehensive Metrics: Conversion, revenue, engagement, retention metrics
  • Statistical Testing: T-tests, confidence intervals, effect size calculations
  • Segmentation Analysis: Analyze performance across user segments
  • Time Series Data: Track metrics over time for trend analysis
  • Export Capabilities: JSON and CSV export formats
βš™οΈ Configuration Management
  • Feature Flags: Dynamic feature toggling with targeting rules
  • Experiment Configuration: Centralized experiment settings
  • Real-time Updates: Watch for configuration changes
  • Rollout Control: Gradual feature rollouts with percentage-based targeting

Quick Start

Basic A/B Testing
package main

import (
    "context"
    "fmt"
    "time"
    
    "github.com/alextanhongpin/core/ab"
)

func main() {
    ctx := context.Background()
    engine := ab.NewExperimentEngine()
    
    // Create an experiment
    exp := &ab.Experiment{
        ID:          "button_color_test",
        Name:        "Button Color Experiment",
        Description: "Testing blue vs red button colors",
        Status:      ab.StatusActive,
        Variants: []ab.Variant{
            {ID: "control", Name: "Blue Button", Weight: 0.5},
            {ID: "treatment", Name: "Red Button", Weight: 0.5},
        },
        TargetPercentage: 1.0, // 100% of users
        ConfidenceLevel:  0.95,
    }
    
    engine.CreateExperiment(exp)
    
    // Assign a user to a variant
    userAttributes := map[string]string{"country": "US"}
    assignment, _ := engine.AssignVariant(ctx, "user123", "button_color_test", userAttributes)
    
    fmt.Printf("User assigned to variant: %s\n", assignment.VariantID)
    
    // Record a conversion
    conversion := &ab.ConversionEvent{
        UserID:       "user123",
        ExperimentID: "button_color_test",
        VariantID:    assignment.VariantID,
        EventType:    "button_click",
        Value:        1.0,
    }
    
    engine.RecordConversion(ctx, conversion)
    
    // Get results
    results, _ := engine.GetExperimentResults("button_color_test")
    fmt.Printf("Experiment results: %+v\n", results)
}
Multi-Armed Bandits
// Create a bandit experiment
banditEngine := ab.NewBanditEngine()

exp := &ab.BanditExperiment{
    ID:        "ad_banner_test",
    Name:      "Ad Banner Optimization",
    Algorithm: ab.EpsilonGreedy,
    Arms: []ab.BanditArm{
        {ID: "banner_a", Name: "Banner A"},
        {ID: "banner_b", Name: "Banner B"},
        {ID: "banner_c", Name: "Banner C"},
    },
    Epsilon: 0.1, // 10% exploration
}

banditEngine.CreateBanditExperiment(exp)

// Select an arm for a user
arm, _ := banditEngine.SelectArm("ad_banner_test", "user123", nil)
fmt.Printf("Selected arm: %s\n", arm.ID)

// Record reward
banditEngine.RecordReward("ad_banner_test", arm.ID, "user123", 1.0, true, nil)
Recommendations
// Create recommendation engine
recEngine := ab.NewRecommendationEngine()

// Add users and items
user := &ab.User{
    ID: "user123",
    Preferences: map[string]float64{
        "action": 0.8,
        "comedy": 0.3,
    },
}
recEngine.AddUser(user)

item := &ab.Item{
    ID:    "movie1",
    Title: "Action Movie",
    Features: map[string]float64{
        "action": 0.9,
        "comedy": 0.1,
    },
}
recEngine.AddItem(item)

// Get recommendations
recommendations, _ := recEngine.GetRecommendations(
    ctx, "user123", 5, ab.RecommendationContentBased)

for _, rec := range recommendations {
    fmt.Printf("Recommended: %s (Score: %.2f)\n", rec.ItemID, rec.Score)
}
Feature Flags
// Setup configuration
provider := ab.NewInMemoryConfigProvider()
configManager := ab.NewConfigManager(provider)

// Create feature flag
flag := &ab.FeatureFlag{
    ID:      "new_checkout",
    Name:    "New Checkout Flow",
    Enabled: true,
    Rules: []ab.FeatureFlagRule{
        {
            Conditions: []ab.RuleCondition{
                {
                    Attribute: "user_type",
                    Operator:  "equals",
                    Value:     "premium",
                },
            },
            Action: ab.RuleAction{Type: "enable"},
        },
    },
}

configManager.CreateFeatureFlag(ctx, flag)

// Evaluate flag for user
userAttrs := map[string]interface{}{"user_type": "premium"}
result, _ := configManager.EvaluateFeatureFlag(ctx, "new_checkout", "user123", userAttrs)

if result.Enabled {
    fmt.Println("Show new checkout flow")
}

Advanced Features

Statistical Analysis

The framework includes comprehensive statistical testing:

  • T-tests: Compare means between variants
  • Confidence Intervals: Calculate confidence intervals for metrics
  • Effect Size: Measure practical significance of differences
  • Power Analysis: Determine required sample sizes
Quality Control

Built-in quality control mechanisms:

  • Sample Ratio Mismatch (SRM): Detect unexpected traffic distribution
  • Outlier Detection: Identify and handle outliers in data
  • Bias Detection: Check for biases across user segments
  • Novelty Effect: Monitor for short-term novelty effects
Analytics and Reporting

Comprehensive analytics capabilities:

  • Custom Metrics: Define and track custom business metrics
  • Segmentation: Analyze results across different user segments
  • Time Series: Track metric trends over time
  • Export: Export data in JSON or CSV formats

Architecture

The framework is designed with modularity and extensibility in mind:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Experiment    β”‚  β”‚     Bandit      β”‚  β”‚ Recommendation  β”‚
β”‚     Engine      β”‚  β”‚     Engine      β”‚  β”‚     Engine      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚                     β”‚                     β”‚
         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                               β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Analytics     β”‚  β”‚     Config      β”‚  β”‚   Storage       β”‚
β”‚     Engine      β”‚  β”‚    Manager      β”‚  β”‚   Providers     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
Components
  1. Experiment Engine: Core A/B testing functionality
  2. Bandit Engine: Multi-armed bandit algorithms
  3. Recommendation Engine: Personalization and recommendations
  4. Analytics Engine: Statistical analysis and reporting
  5. Config Manager: Feature flags and experiment configuration
  6. Storage Providers: Pluggable storage backends

Configuration

Environment Variables
# Redis configuration (if using Redis provider)
REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_PASSWORD=

# Analytics settings
ANALYTICS_BATCH_SIZE=100
ANALYTICS_FLUSH_INTERVAL=60s

# Experiment settings
DEFAULT_CONFIDENCE_LEVEL=0.95
MIN_SAMPLE_SIZE=100
Provider Configuration

The framework supports multiple storage providers:

  • In-Memory: For testing and development
  • Redis: For production with Redis backend
  • Database: For SQL database storage
  • Custom: Implement your own storage provider

Best Practices

A/B Testing
  1. Plan Your Experiments: Define clear hypotheses and success metrics
  2. Sample Size Calculation: Use power analysis to determine required sample sizes
  3. Randomization: Ensure proper randomization to avoid bias
  4. Statistical Significance: Wait for sufficient data before making decisions
  5. Multiple Testing: Adjust for multiple comparisons when running multiple tests
Feature Flags
  1. Gradual Rollouts: Start with small percentages and gradually increase
  2. Monitoring: Monitor key metrics during rollouts
  3. Rollback Plans: Have clear rollback procedures for problematic releases
  4. Documentation: Document flag purposes and cleanup schedules
Recommendations
  1. Cold Start: Handle new users and items gracefully
  2. Diversity: Balance relevance with diversity in recommendations
  3. Freshness: Include recent and trending content
  4. Feedback Loops: Collect and incorporate user feedback

Testing

Run the test suite:

go test ./...

Run specific tests:

go test -run TestExperimentEngine
go test -run TestRecommendationEngine
go test -run TestBanditEngine

Performance Considerations

Scalability
  • Horizontal Scaling: All engines are stateless and can be scaled horizontally
  • Caching: Built-in caching reduces database load
  • Batch Processing: Analytics support batch processing for high-throughput scenarios
Memory Usage
  • Efficient Data Structures: Optimized for memory usage
  • Configurable Cache: Adjustable cache sizes and TTL
  • Garbage Collection: Minimal allocations to reduce GC pressure

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Add tests for new functionality
  4. Ensure all tests pass
  5. Submit a pull request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support

For questions and support:

  • Create an issue on GitHub
  • Check the documentation
  • Review the test files for examples

Roadmap

  • Additional bandit algorithms (Contextual bandits)
  • Deep learning-based recommendations
  • Real-time streaming analytics
  • Advanced statistical tests (Bayesian A/B testing)
  • Mobile SDK support
  • Dashboard and UI components

Documentation ΒΆ

Index ΒΆ

Constants ΒΆ

This section is empty.

Variables ΒΆ

This section is empty.

Functions ΒΆ

func Hash ΒΆ

func Hash(key string, size uint64) uint64

Hash generates a consistent hash for a given key within the specified size

func Rollout ΒΆ

func Rollout(key string, percentage uint64) bool

Rollout determines if a user should be included in a rollout based on percentage

Types ΒΆ

type AnalyticsEngine ΒΆ

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

AnalyticsEngine provides comprehensive analytics capabilities Now supports pluggable storage and metrics

func NewAnalyticsEngine ΒΆ

func NewAnalyticsEngine() *AnalyticsEngine

NewAnalyticsEngine creates a new analytics engine (default in-memory)

func NewAnalyticsEngineWithStorage ΒΆ

func NewAnalyticsEngineWithStorage(storage AnalyticsStorage, metricsObs *AnalyticsMetrics) *AnalyticsEngine

NewAnalyticsEngine creates a new analytics engine with storage and metrics

func (*AnalyticsEngine) CreateMetric ΒΆ

func (a *AnalyticsEngine) CreateMetric(metric *Metric) error

CreateMetric creates a new metric definition

func (*AnalyticsEngine) CreateSegment ΒΆ

func (a *AnalyticsEngine) CreateSegment(segment *Segment) error

CreateSegment creates a new user segment (now uses storage and metrics)

func (*AnalyticsEngine) ExportAnalytics ΒΆ

func (a *AnalyticsEngine) ExportAnalytics(ctx context.Context, analytics *ExperimentAnalytics, format string) ([]byte, error)

ExportAnalytics exports analytics data in various formats

func (*AnalyticsEngine) GenerateAnalytics ΒΆ

func (a *AnalyticsEngine) GenerateAnalytics(ctx context.Context, experimentID string, timeRange TimeRange) (*ExperimentAnalytics, error)

GenerateAnalytics generates comprehensive analytics for an experiment (now uses storage)

func (*AnalyticsEngine) RecordMetricValue ΒΆ

func (a *AnalyticsEngine) RecordMetricValue(ctx context.Context, value MetricValue) error

RecordMetricValue records a value for a metric (now uses storage and metrics)

type AnalyticsMetrics ΒΆ

type AnalyticsMetrics struct {
	MetricValueCount int64
	SegmentCount     int64
	LastError        error
	LastOperation    string
}

AnalyticsMetrics holds operational metrics for observability (e.g., counts, error rates, latency, etc.)

type AnalyticsStorage ΒΆ

type AnalyticsStorage interface {
	SaveMetricValue(ctx context.Context, value MetricValue) error
	GetMetricValues(ctx context.Context, experimentID string, timeRange TimeRange) ([]MetricValue, error)
	SaveSegment(ctx context.Context, segment *Segment) error
	GetSegments(ctx context.Context) ([]*Segment, error)
}

AnalyticsStorage defines the interface for persistent analytics storage (e.g., for metric values, segments, etc.)

type Assignment ΒΆ

type Assignment struct {
	UserID       string            `json:"user_id"`
	ExperimentID string            `json:"experiment_id"`
	VariantID    string            `json:"variant_id"`
	AssignedAt   time.Time         `json:"assigned_at"`
	Attributes   map[string]string `json:"attributes"`
}

Assignment represents a user's assignment to an experiment variant

type BanditAlgorithm ΒΆ

type BanditAlgorithm string

BanditAlgorithm represents different bandit algorithms

const (
	EpsilonGreedy    BanditAlgorithm = "epsilon_greedy"
	UCB              BanditAlgorithm = "ucb"      // Upper Confidence Bound
	ThompsonSampling BanditAlgorithm = "thompson" // Thompson Sampling
	BayesianBandit   BanditAlgorithm = "bayesian" // Bayesian Bandit
)

type BanditAnalysis ΒΆ

type BanditAnalysis struct {
	ExperimentID string              `json:"experiment_id"`
	TotalPulls   int64               `json:"total_pulls"`
	TotalRegret  float64             `json:"total_regret"`
	Arms         []BanditArmAnalysis `json:"arms"`
}

BanditAnalysis contains analysis results for a bandit experiment

type BanditArm ΒΆ

type BanditArm struct {
	ID          string  `json:"id"`
	Name        string  `json:"name"`
	Pulls       int64   `json:"pulls"`        // Number of times this arm was pulled
	Rewards     int64   `json:"rewards"`      // Number of successful outcomes
	TotalReward float64 `json:"total_reward"` // Sum of all rewards

	// Bayesian parameters (for Thompson Sampling and Bayesian bandits)
	Alpha float64 `json:"alpha"` // Success count + 1 (prior)
	Beta  float64 `json:"beta"`  // Failure count + 1 (prior)

	// Configuration
	Config    map[string]any `json:"config"`
	CreatedAt time.Time      `json:"created_at"`
	UpdatedAt time.Time      `json:"updated_at"`
}

BanditArm represents a single arm in a multi-armed bandit

type BanditArmAnalysis ΒΆ

type BanditArmAnalysis struct {
	ArmID              string             `json:"arm_id"`
	Pulls              int64              `json:"pulls"`
	Rewards            int64              `json:"rewards"`
	ConversionRate     float64            `json:"conversion_rate"`
	AverageReward      float64            `json:"average_reward"`
	ConfidenceInterval ConfidenceInterval `json:"confidence_interval"`
	PosteriorMean      float64            `json:"posterior_mean"`
	Regret             float64            `json:"regret"`
}

BanditArmAnalysis contains analysis for a single bandit arm

type BanditEngine ΒΆ

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

BanditEngine manages multi-armed bandit experiments

func NewBanditEngine ΒΆ

func NewBanditEngine() *BanditEngine

NewBanditEngine creates a new bandit engine

func NewBanditEngineWithStorage ΒΆ

func NewBanditEngineWithStorage(storage BanditStorage, metrics *BanditMetrics) *BanditEngine

NewBanditEngineWithStorage creates a new bandit engine with custom storage and metrics

func (*BanditEngine) CreateBanditExperiment ΒΆ

func (b *BanditEngine) CreateBanditExperiment(exp *BanditExperiment) error

CreateBanditExperiment creates a new bandit experiment

func (*BanditEngine) DeleteExperiment ΒΆ

func (b *BanditEngine) DeleteExperiment(id string) bool

func (*BanditEngine) Experiments ΒΆ

func (b *BanditEngine) Experiments() []*BanditExperiment

func (*BanditEngine) GetBanditResults ΒΆ

func (b *BanditEngine) GetBanditResults(experimentID string) (*BanditAnalysis, error)

GetBanditResults returns analysis of bandit experiment results

func (*BanditEngine) GetExperimentRecommendation ΒΆ

func (b *BanditEngine) GetExperimentRecommendation(experimentID string) (*BanditRecommendation, error)

GetExperimentRecommendation provides recommendations for experiment decisions

func (*BanditEngine) Metrics ΒΆ

func (b *BanditEngine) Metrics() BanditMetrics

func (*BanditEngine) RecordReward ΒΆ

func (b *BanditEngine) RecordReward(experimentID, armID, userID string, reward float64, success bool, context map[string]any) error

RecordReward records the reward for a bandit arm pull

func (*BanditEngine) SelectArm ΒΆ

func (b *BanditEngine) SelectArm(experimentID, userID string, context map[string]any) (*BanditArm, error)

SelectArm selects an arm based on the bandit algorithm

func (*BanditEngine) StopExperiment ΒΆ

func (b *BanditEngine) StopExperiment(experimentID string) error

StopExperiment stops a bandit experiment

type BanditExperiment ΒΆ

type BanditExperiment struct {
	ID          string          `json:"id"`
	Name        string          `json:"name"`
	Description string          `json:"description"`
	Algorithm   BanditAlgorithm `json:"algorithm"`
	Arms        []BanditArm     `json:"arms"`

	// Algorithm parameters
	Epsilon      float64 `json:"epsilon"`       // For epsilon-greedy
	Confidence   float64 `json:"confidence"`    // For UCB
	ExploreRatio float64 `json:"explore_ratio"` // General exploration parameter

	// Experiment state
	TotalPulls int64      `json:"total_pulls"`
	Status     string     `json:"status"`
	StartTime  time.Time  `json:"start_time"`
	EndTime    *time.Time `json:"end_time,omitempty"`
	CreatedAt  time.Time  `json:"created_at"`
	UpdatedAt  time.Time  `json:"updated_at"`
}

BanditExperiment represents a multi-armed bandit experiment

type BanditMetrics ΒΆ

type BanditMetrics struct {
	Pulls   int64
	Rewards int64
	Errors  int64
	Regret  []float64
}

BanditMetrics tracks operational metrics for bandit engine

type BanditRecommendation ΒΆ

type BanditRecommendation struct {
	ExperimentID string   `json:"experiment_id"`
	Decision     string   `json:"decision"` // "continue", "stop", "need_more_data"
	WinnerArmID  string   `json:"winner_arm_id,omitempty"`
	Confidence   string   `json:"confidence"` // "low", "medium", "high"
	Reasons      []string `json:"reasons"`
}

BanditRecommendation provides recommendations for bandit experiment decisions

type BanditResult ΒΆ

type BanditResult struct {
	ExperimentID string         `json:"experiment_id"`
	ArmID        string         `json:"arm_id"`
	UserID       string         `json:"user_id"`
	Reward       float64        `json:"reward"`
	Success      bool           `json:"success"`
	Context      map[string]any `json:"context"`
	Timestamp    time.Time      `json:"timestamp"`
}

BanditResult represents the result of pulling a bandit arm

type BanditStorage ΒΆ

type BanditStorage interface {
	SaveExperiment(exp *BanditExperiment) error
	SaveArm(expID string, arm *BanditArm) error
	SaveResult(result BanditResult) error
	ListResults(expID string, limit int) ([]BanditResult, error)
}

BanditStorage defines interface for persisting bandit experiments, arms, and results In production, implement with Redis, SQL, etc.

type BiasDetectionConfig ΒΆ

type BiasDetectionConfig struct {
	Enabled           bool     `json:"enabled"`
	CheckSegments     []string `json:"check_segments"` // Segments to check for bias
	SignificanceLevel float64  `json:"significance_level"`
}

BiasDetectionConfig defines bias detection parameters

type ConfidenceInterval ΒΆ

type ConfidenceInterval struct {
	Lower float64 `json:"lower"`
	Upper float64 `json:"upper"`
}

ConfidenceInterval represents a confidence interval

type ConfigChange ΒΆ

type ConfigChange struct {
	Key       string      `json:"key"`
	OldValue  interface{} `json:"old_value"`
	NewValue  interface{} `json:"new_value"`
	Timestamp time.Time   `json:"timestamp"`
	Source    string      `json:"source"`
}

ConfigChange represents a configuration change event

type ConfigManager ΒΆ

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

ConfigManager manages all configuration for A/B testing

func NewConfigManager ΒΆ

func NewConfigManager(provider ConfigProvider) *ConfigManager

NewConfigManager creates a new configuration manager

func NewConfigManagerWithStorage ΒΆ

func NewConfigManagerWithStorage(storage ConfigStorage, metrics *ConfigMetrics) *ConfigManager

NewConfigManagerWithStorage creates a new config manager with custom storage and metrics

func (*ConfigManager) CreateExperimentConfig ΒΆ

func (c *ConfigManager) CreateExperimentConfig(ctx context.Context, config *ExperimentConfig) error

CreateExperimentConfig creates experiment configuration

func (*ConfigManager) CreateFeatureFlag ΒΆ

func (c *ConfigManager) CreateFeatureFlag(ctx context.Context, flag *FeatureFlag) error

CreateFeatureFlag creates a new feature flag

func (*ConfigManager) DeleteExperimentConfig ΒΆ

func (c *ConfigManager) DeleteExperimentConfig(ctx context.Context, experimentID string) error

DeleteExperimentConfig deletes an experiment config by ID

func (*ConfigManager) DeleteFeatureFlag ΒΆ

func (c *ConfigManager) DeleteFeatureFlag(ctx context.Context, flagID string) error

DeleteFeatureFlag deletes a feature flag by ID

func (*ConfigManager) EvaluateFeatureFlag ΒΆ

func (c *ConfigManager) EvaluateFeatureFlag(ctx context.Context, flagID, userID string, userAttributes map[string]interface{}) (*FeatureFlagResult, error)

EvaluateFeatureFlag evaluates a feature flag for a user

func (*ConfigManager) GetExperimentConfig ΒΆ

func (c *ConfigManager) GetExperimentConfig(ctx context.Context, experimentID string) (*ExperimentConfig, error)

GetExperimentConfig retrieves experiment configuration

func (*ConfigManager) GetFeatureFlag ΒΆ

func (c *ConfigManager) GetFeatureFlag(ctx context.Context, flagID string) (*FeatureFlag, error)

GetFeatureFlag retrieves a feature flag

func (*ConfigManager) GetMetrics ΒΆ

func (c *ConfigManager) GetMetrics() ConfigMetrics

GetMetrics returns config manager metrics

func (*ConfigManager) ListExperimentConfigs ΒΆ

func (c *ConfigManager) ListExperimentConfigs(ctx context.Context) ([]*ExperimentConfig, error)

ListExperimentConfigs returns all experiment configs

func (*ConfigManager) ListFeatureFlags ΒΆ

func (c *ConfigManager) ListFeatureFlags(ctx context.Context) ([]*FeatureFlag, error)

ListFeatureFlags returns all feature flags

func (*ConfigManager) ValidateConfig ΒΆ

func (c *ConfigManager) ValidateConfig(config interface{}) error

ValidateConfig validates configuration before saving

func (*ConfigManager) WatchConfig ΒΆ

func (c *ConfigManager) WatchConfig(ctx context.Context, key string) (<-chan ConfigChange, error)

WatchConfig watches for configuration changes

type ConfigMetrics ΒΆ

type ConfigMetrics struct {
	FeatureFlagEvaluations int64
	FeatureFlagErrors      int64
	ConfigChanges          int64
}

ConfigMetrics tracks operational metrics for config manager

type ConfigProvider ΒΆ

type ConfigProvider interface {
	GetConfig(ctx context.Context, key string) (interface{}, error)
	SetConfig(ctx context.Context, key string, value interface{}) error
	DeleteConfig(ctx context.Context, key string) error
	ListConfigs(ctx context.Context, prefix string) (map[string]interface{}, error)
	Watch(ctx context.Context, key string) (<-chan ConfigChange, error)
}

ConfigProvider defines interface for configuration providers

type ConfigStorage ΒΆ

type ConfigStorage interface {
	SaveFeatureFlag(flag *FeatureFlag) error
	SaveExperimentConfig(config *ExperimentConfig) error
	ListFeatureFlags() ([]*FeatureFlag, error)
	ListExperimentConfigs() ([]*ExperimentConfig, error)
}

ConfigStorage defines interface for persisting feature flags and experiment configs In production, implement with Redis, SQL, etc.

type ConversionEvent ΒΆ

type ConversionEvent struct {
	UserID       string                 `json:"user_id"`
	ExperimentID string                 `json:"experiment_id"`
	VariantID    string                 `json:"variant_id"`
	EventType    string                 `json:"event_type"`
	Value        float64                `json:"value,omitempty"`
	Properties   map[string]interface{} `json:"properties,omitempty"`
	Timestamp    time.Time              `json:"timestamp"`
}

ConversionEvent represents a conversion event for analytics

type Experiment ΒΆ

type Experiment struct {
	ID          string           `json:"id"`
	Name        string           `json:"name"`
	Description string           `json:"description"`
	Status      ExperimentStatus `json:"status"`
	Variants    []Variant        `json:"variants"`
	StartTime   *time.Time       `json:"start_time,omitempty"`
	EndTime     *time.Time       `json:"end_time,omitempty"`
	CreatedAt   time.Time        `json:"created_at"`
	UpdatedAt   time.Time        `json:"updated_at"`

	// Targeting criteria
	TargetPercentage float64           `json:"target_percentage"` // 0.0 to 1.0
	Filters          map[string]string `json:"filters"`           // User attributes for targeting

	// Analytics
	MinSampleSize       int     `json:"min_sample_size"`
	ConfidenceLevel     float64 `json:"confidence_level"` // e.g., 0.95 for 95%
	MinDetectableEffect float64 `json:"min_detectable_effect"`
}

Experiment represents an A/B test experiment

type ExperimentAnalytics ΒΆ

type ExperimentAnalytics struct {
	ExperimentID     string                     `json:"experiment_id"`
	TimeRange        TimeRange                  `json:"time_range"`
	OverallMetrics   []MetricSummary            `json:"overall_metrics"`
	VariantMetrics   map[string][]MetricSummary `json:"variant_metrics"`  // variant_id -> metrics
	SegmentAnalysis  map[string]SegmentAnalysis `json:"segment_analysis"` // segment_id -> analysis
	TimeSeriesData   []TimeSeriesPoint          `json:"time_series_data"`
	StatisticalTests []StatisticalTest          `json:"statistical_tests"`
	GeneratedAt      time.Time                  `json:"generated_at"`
}

ExperimentAnalytics provides comprehensive analytics for experiments

type ExperimentConfig ΒΆ

type ExperimentConfig struct {
	ExperimentID   string                  `json:"experiment_id"`
	TrafficSplit   map[string]float64      `json:"traffic_split"` // variant_id -> percentage
	TargetingRules []TargetingRule         `json:"targeting_rules"`
	SampleSize     *SampleSizeConfig       `json:"sample_size,omitempty"`
	StoppingRules  []StoppingRule          `json:"stopping_rules"`
	MetricConfig   map[string]MetricConfig `json:"metric_config"`
	QualityControl *QualityControlConfig   `json:"quality_control,omitempty"`
	CreatedAt      time.Time               `json:"created_at"`
	UpdatedAt      time.Time               `json:"updated_at"`
}

ExperimentConfig represents configuration for an experiment

type ExperimentEngine ΒΆ

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

ExperimentEngine manages A/B test experiments

func NewExperimentEngine ΒΆ

func NewExperimentEngine(store ExperimentStore) *ExperimentEngine

NewExperimentEngine creates a new experiment engine

func (*ExperimentEngine) AssignVariant ΒΆ

func (e *ExperimentEngine) AssignVariant(ctx context.Context, userID, experimentID string, userAttributes map[string]string) (*Assignment, error)

AssignVariant assigns a user to a variant in an experiment

func (*ExperimentEngine) CreateExperiment ΒΆ

func (e *ExperimentEngine) CreateExperiment(exp *Experiment) error

CreateExperiment creates a new experiment

func (*ExperimentEngine) GetExperimentResults ΒΆ

func (e *ExperimentEngine) GetExperimentResults(experimentID string) (*ExperimentResults, error)

GetExperimentResults calculates statistical results for an experiment

func (*ExperimentEngine) RecordConversion ΒΆ

func (e *ExperimentEngine) RecordConversion(ctx context.Context, event *ConversionEvent) error

RecordConversion records a conversion event for analytics

type ExperimentResults ΒΆ

type ExperimentResults struct {
	ExperimentID string           `json:"experiment_id"`
	Variants     []VariantResults `json:"variants"`
}

ExperimentResults contains the statistical results of an experiment

type ExperimentStatus ΒΆ

type ExperimentStatus string

ExperimentStatus represents the status of an experiment

const (
	StatusDraft    ExperimentStatus = "draft"
	StatusActive   ExperimentStatus = "active"
	StatusPaused   ExperimentStatus = "paused"
	StatusComplete ExperimentStatus = "complete"
)

type ExperimentStore ΒΆ

type ExperimentStore interface {
	SaveExperiment(exp *Experiment) error
	GetExperiment(id string) (*Experiment, error)
	ListExperiments() ([]*Experiment, error)
	SaveAssignment(assignment *Assignment) error
	GetAssignment(userID, experimentID string) (*Assignment, error)
	ListAssignments(experimentID string) ([]*Assignment, error)
	SaveConversion(event *ConversionEvent) error
	ListConversions(experimentID string) ([]*ConversionEvent, error)
}

ExperimentStore defines the interface for persisting experiments, variants, assignments, and conversions In production, implement with Redis, SQL, etc.

type FeatureFlag ΒΆ

type FeatureFlag struct {
	ID          string                 `json:"id"`
	Name        string                 `json:"name"`
	Description string                 `json:"description"`
	Enabled     bool                   `json:"enabled"`
	Rules       []FeatureFlagRule      `json:"rules"`
	Rollout     *RolloutConfig         `json:"rollout,omitempty"`
	Metadata    map[string]interface{} `json:"metadata"`
	CreatedAt   time.Time              `json:"created_at"`
	UpdatedAt   time.Time              `json:"updated_at"`
	CreatedBy   string                 `json:"created_by"`
}

FeatureFlag represents a feature flag configuration

type FeatureFlagResult ΒΆ

type FeatureFlagResult struct {
	FlagID      string                 `json:"flag_id"`
	UserID      string                 `json:"user_id"`
	Enabled     bool                   `json:"enabled"`
	Variant     string                 `json:"variant"`
	Config      map[string]interface{} `json:"config"`
	RuleMatched string                 `json:"rule_matched"`
	Reason      string                 `json:"reason"`
	EvaluatedAt time.Time              `json:"evaluated_at"`
}

FeatureFlagResult represents the result of feature flag evaluation

type FeatureFlagRule ΒΆ

type FeatureFlagRule struct {
	ID         string                 `json:"id"`
	Name       string                 `json:"name"`
	Conditions []RuleCondition        `json:"conditions"`
	Action     RuleAction             `json:"action"`
	Weight     float64                `json:"weight"`   // 0.0 to 1.0
	Priority   int                    `json:"priority"` // Higher number = higher priority
	Metadata   map[string]interface{} `json:"metadata"`
}

FeatureFlagRule defines targeting rules for feature flags

type InMemoryAnalyticsStorage ΒΆ

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

InMemoryAnalyticsStorage is an in-memory implementation of AnalyticsStorage (for testing and development)

func NewInMemoryAnalyticsStorage ΒΆ

func NewInMemoryAnalyticsStorage() *InMemoryAnalyticsStorage

func (*InMemoryAnalyticsStorage) GetMetricValues ΒΆ

func (s *InMemoryAnalyticsStorage) GetMetricValues(ctx context.Context, experimentID string, timeRange TimeRange) ([]MetricValue, error)

func (*InMemoryAnalyticsStorage) GetSegments ΒΆ

func (s *InMemoryAnalyticsStorage) GetSegments(ctx context.Context) ([]*Segment, error)

func (*InMemoryAnalyticsStorage) SaveMetricValue ΒΆ

func (s *InMemoryAnalyticsStorage) SaveMetricValue(ctx context.Context, value MetricValue) error

func (*InMemoryAnalyticsStorage) SaveSegment ΒΆ

func (s *InMemoryAnalyticsStorage) SaveSegment(ctx context.Context, segment *Segment) error

type InMemoryBanditStorage ΒΆ

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

InMemoryBanditStorage is a simple in-memory implementation

func NewInMemoryBanditStorage ΒΆ

func NewInMemoryBanditStorage() *InMemoryBanditStorage

func (*InMemoryBanditStorage) ListResults ΒΆ

func (s *InMemoryBanditStorage) ListResults(expID string, limit int) ([]BanditResult, error)

func (*InMemoryBanditStorage) SaveArm ΒΆ

func (s *InMemoryBanditStorage) SaveArm(expID string, arm *BanditArm) error

func (*InMemoryBanditStorage) SaveExperiment ΒΆ

func (s *InMemoryBanditStorage) SaveExperiment(exp *BanditExperiment) error

func (*InMemoryBanditStorage) SaveResult ΒΆ

func (s *InMemoryBanditStorage) SaveResult(result BanditResult) error

type InMemoryConfigProvider ΒΆ

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

InMemoryConfigProvider provides an in-memory configuration store

func NewInMemoryConfigProvider ΒΆ

func NewInMemoryConfigProvider() *InMemoryConfigProvider

NewInMemoryConfigProvider creates a new in-memory config provider

func (*InMemoryConfigProvider) DeleteConfig ΒΆ

func (p *InMemoryConfigProvider) DeleteConfig(ctx context.Context, key string) error

DeleteConfig deletes a configuration value

func (*InMemoryConfigProvider) GetConfig ΒΆ

func (p *InMemoryConfigProvider) GetConfig(ctx context.Context, key string) (interface{}, error)

GetConfig retrieves a configuration value

func (*InMemoryConfigProvider) ListConfigs ΒΆ

func (p *InMemoryConfigProvider) ListConfigs(ctx context.Context, prefix string) (map[string]interface{}, error)

ListConfigs lists all configurations with a given prefix

func (*InMemoryConfigProvider) SetConfig ΒΆ

func (p *InMemoryConfigProvider) SetConfig(ctx context.Context, key string, value interface{}) error

SetConfig sets a configuration value

func (*InMemoryConfigProvider) Watch ΒΆ

func (p *InMemoryConfigProvider) Watch(ctx context.Context, key string) (<-chan ConfigChange, error)

Watch watches for changes to a configuration key

type InMemoryConfigStorage ΒΆ

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

InMemoryConfigStorage is a simple in-memory implementation

func NewInMemoryConfigStorage ΒΆ

func NewInMemoryConfigStorage() *InMemoryConfigStorage

func (*InMemoryConfigStorage) ListExperimentConfigs ΒΆ

func (s *InMemoryConfigStorage) ListExperimentConfigs() ([]*ExperimentConfig, error)

func (*InMemoryConfigStorage) ListFeatureFlags ΒΆ

func (s *InMemoryConfigStorage) ListFeatureFlags() ([]*FeatureFlag, error)

func (*InMemoryConfigStorage) SaveExperimentConfig ΒΆ

func (s *InMemoryConfigStorage) SaveExperimentConfig(config *ExperimentConfig) error

func (*InMemoryConfigStorage) SaveFeatureFlag ΒΆ

func (s *InMemoryConfigStorage) SaveFeatureFlag(flag *FeatureFlag) error

type InMemoryExperimentStore ΒΆ

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

InMemoryExperimentStore is a simple in-memory implementation (for testing and development)

func NewInMemoryExperimentStore ΒΆ

func NewInMemoryExperimentStore() *InMemoryExperimentStore

func (*InMemoryExperimentStore) GetAssignment ΒΆ

func (s *InMemoryExperimentStore) GetAssignment(userID, experimentID string) (*Assignment, error)

func (*InMemoryExperimentStore) GetExperiment ΒΆ

func (s *InMemoryExperimentStore) GetExperiment(id string) (*Experiment, error)

func (*InMemoryExperimentStore) ListAssignments ΒΆ

func (s *InMemoryExperimentStore) ListAssignments(experimentID string) ([]*Assignment, error)

func (*InMemoryExperimentStore) ListConversions ΒΆ

func (s *InMemoryExperimentStore) ListConversions(experimentID string) ([]*ConversionEvent, error)

func (*InMemoryExperimentStore) ListExperiments ΒΆ

func (s *InMemoryExperimentStore) ListExperiments() ([]*Experiment, error)

func (*InMemoryExperimentStore) SaveAssignment ΒΆ

func (s *InMemoryExperimentStore) SaveAssignment(assignment *Assignment) error

func (*InMemoryExperimentStore) SaveConversion ΒΆ

func (s *InMemoryExperimentStore) SaveConversion(event *ConversionEvent) error

func (*InMemoryExperimentStore) SaveExperiment ΒΆ

func (s *InMemoryExperimentStore) SaveExperiment(exp *Experiment) error

type InMemoryRecommendationStorage ΒΆ

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

InMemoryRecommendationStorage is a simple in-memory implementation Not for production use

func NewInMemoryRecommendationStorage ΒΆ

func NewInMemoryRecommendationStorage() *InMemoryRecommendationStorage

func (*InMemoryRecommendationStorage) ListRecommendations ΒΆ

func (s *InMemoryRecommendationStorage) ListRecommendations(userID string, limit int) ([]Recommendation, error)

func (*InMemoryRecommendationStorage) SaveInteraction ΒΆ

func (s *InMemoryRecommendationStorage) SaveInteraction(interaction Interaction) error

func (*InMemoryRecommendationStorage) SaveItem ΒΆ

func (s *InMemoryRecommendationStorage) SaveItem(item *Item) error

func (*InMemoryRecommendationStorage) SaveRecommendation ΒΆ

func (s *InMemoryRecommendationStorage) SaveRecommendation(rec Recommendation) error

func (*InMemoryRecommendationStorage) SaveUser ΒΆ

func (s *InMemoryRecommendationStorage) SaveUser(user *User) error

type Interaction ΒΆ

type Interaction struct {
	UserID        string                 `json:"user_id"`
	ItemID        string                 `json:"item_id"`
	Type          string                 `json:"type"`           // view, click, purchase, like, etc.
	Rating        float64                `json:"rating"`         // explicit rating if available
	ImplicitScore float64                `json:"implicit_score"` // implicit rating derived from behavior
	Timestamp     time.Time              `json:"timestamp"`
	Context       map[string]interface{} `json:"context"` // contextual information
}

Interaction represents a user-item interaction

type Item ΒΆ

type Item struct {
	ID         string                 `json:"id"`
	Title      string                 `json:"title"`
	Category   string                 `json:"category"`
	Tags       []string               `json:"tags"`
	Features   map[string]float64     `json:"features"`    // Feature vector for content-based filtering
	Popularity float64                `json:"popularity"`  // Popularity score
	TrendScore float64                `json:"trend_score"` // Trending score
	CreatedAt  time.Time              `json:"created_at"`
	Metadata   map[string]interface{} `json:"metadata"`
}

Item represents an item that can be recommended

type Metric ΒΆ

type Metric struct {
	ID          string                 `json:"id"`
	Name        string                 `json:"name"`
	Type        MetricType             `json:"type"`
	Description string                 `json:"description"`
	Unit        string                 `json:"unit"`       // e.g., "percent", "dollars", "count"
	IsPrimary   bool                   `json:"is_primary"` // Primary metric for the experiment
	Properties  map[string]interface{} `json:"properties"`
	CreatedAt   time.Time              `json:"created_at"`
}

Metric represents a metric definition

type MetricConfig ΒΆ

type MetricConfig struct {
	MetricID  string  `json:"metric_id"`
	IsPrimary bool    `json:"is_primary"`
	Weight    float64 `json:"weight"`    // For composite metrics
	Threshold float64 `json:"threshold"` // Alert threshold
	Direction string  `json:"direction"` // "increase", "decrease", "either"
}

MetricConfig defines configuration for metrics

type MetricSummary ΒΆ

type MetricSummary struct {
	MetricID           string             `json:"metric_id"`
	MetricName         string             `json:"metric_name"`
	Count              int64              `json:"count"`
	Sum                float64            `json:"sum"`
	Mean               float64            `json:"mean"`
	Median             float64            `json:"median"`
	StandardDev        float64            `json:"standard_deviation"`
	Percentiles        map[int]float64    `json:"percentiles"` // 25th, 75th, 90th, 95th, 99th
	ConfidenceInterval ConfidenceInterval `json:"confidence_interval"`
}

MetricSummary provides summary statistics for a metric

type MetricType ΒΆ

type MetricType string

MetricType represents different types of metrics

const (
	MetricConversion   MetricType = "conversion"
	MetricRevenue      MetricType = "revenue"
	MetricEngagement   MetricType = "engagement"
	MetricRetention    MetricType = "retention"
	MetricClickThrough MetricType = "click_through"
	MetricCustom       MetricType = "custom"
)

type MetricValue ΒΆ

type MetricValue struct {
	MetricID     string                 `json:"metric_id"`
	ExperimentID string                 `json:"experiment_id"`
	VariantID    string                 `json:"variant_id"`
	UserID       string                 `json:"user_id"`
	Value        float64                `json:"value"`
	Properties   map[string]interface{} `json:"properties"`
	Timestamp    time.Time              `json:"timestamp"`
}

MetricValue represents a measured value for a metric

type NoveltyConfig ΒΆ

type NoveltyConfig struct {
	Enabled        bool          `json:"enabled"`
	MonitorPeriod  time.Duration `json:"monitor_period"`  // How long to monitor for novelty
	BaselinePeriod time.Duration `json:"baseline_period"` // Period to establish baseline
}

NoveltyConfig defines novelty effect detection

type OutlierConfig ΒΆ

type OutlierConfig struct {
	Enabled   bool    `json:"enabled"`
	Method    string  `json:"method"`    // "iqr", "zscore", "isolation_forest"
	Threshold float64 `json:"threshold"` // Method-specific threshold
	Action    string  `json:"action"`    // "exclude", "flag", "transform"
}

OutlierConfig defines outlier detection parameters

type PowerAnalysisConfig ΒΆ

type PowerAnalysisConfig struct {
	Alpha                  float64 `json:"alpha"`                 // Type I error rate (e.g., 0.05)
	Beta                   float64 `json:"beta"`                  // Type II error rate (e.g., 0.2)
	MinDetectableEffect    float64 `json:"min_detectable_effect"` // Minimum effect size to detect
	BaselineConversionRate float64 `json:"baseline_conversion_rate"`
}

PowerAnalysisConfig defines power analysis parameters

type QualityControlConfig ΒΆ

type QualityControlConfig struct {
	SampleRatioMismatch *SRMConfig           `json:"sample_ratio_mismatch,omitempty"`
	OutlierDetection    *OutlierConfig       `json:"outlier_detection,omitempty"`
	NoveltyEffect       *NoveltyConfig       `json:"novelty_effect,omitempty"`
	BiasDetection       *BiasDetectionConfig `json:"bias_detection,omitempty"`
}

QualityControlConfig defines quality control parameters

type Recommendation ΒΆ

type Recommendation struct {
	UserID      string                 `json:"user_id"`
	ItemID      string                 `json:"item_id"`
	Score       float64                `json:"score"`
	Reason      string                 `json:"reason"`
	Algorithm   RecommendationType     `json:"algorithm"`
	Context     map[string]interface{} `json:"context"`
	GeneratedAt time.Time              `json:"generated_at"`
}

Recommendation represents a recommended item for a user

type RecommendationEngine ΒΆ

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

RecommendationEngine provides personalized recommendations

func NewRecommendationEngine ΒΆ

func NewRecommendationEngine() *RecommendationEngine

NewRecommendationEngine creates a new recommendation engine

func NewRecommendationEngineWithStorage ΒΆ

func NewRecommendationEngineWithStorage(storage RecommendationStorage, metrics *RecommendationMetrics) *RecommendationEngine

NewRecommendationEngineWithStorage creates a new recommendation engine with custom storage and metrics

func (*RecommendationEngine) AddItem ΒΆ

func (r *RecommendationEngine) AddItem(item *Item)

AddItem adds an item to the recommendation system

func (*RecommendationEngine) AddUser ΒΆ

func (r *RecommendationEngine) AddUser(user *User)

AddUser adds a user to the recommendation system

func (*RecommendationEngine) GetRecommendations ΒΆ

func (r *RecommendationEngine) GetRecommendations(ctx context.Context, userID string, count int, algorithm RecommendationType) ([]Recommendation, error)

GetRecommendations generates recommendations for a user

func (*RecommendationEngine) RecordInteraction ΒΆ

func (r *RecommendationEngine) RecordInteraction(interaction Interaction)

RecordInteraction records a user-item interaction

func (*RecommendationEngine) SetAlgorithmWeights ΒΆ

func (r *RecommendationEngine) SetAlgorithmWeights(content, collaborative, popularity, trending float64) error

SetAlgorithmWeights sets the weights for hybrid recommendation algorithms

type RecommendationMetrics ΒΆ

type RecommendationMetrics struct {
	RecommendationsServed int64
	RecommendationErrors  int64
	RecommendationLatency []float64
}

RecommendationMetrics tracks operational metrics for recommendations

type RecommendationStorage ΒΆ

type RecommendationStorage interface {
	SaveUser(user *User) error
	SaveItem(item *Item) error
	SaveInteraction(interaction Interaction) error
	SaveRecommendation(rec Recommendation) error
	ListRecommendations(userID string, limit int) ([]Recommendation, error)
}

RecommendationStorage defines interface for persisting recommendations, users, items, and interactions In production, implement this with Redis, SQL, or other backends

type RecommendationType ΒΆ

type RecommendationType string

RecommendationType represents the type of recommendation algorithm

const (
	RecommendationContentBased  RecommendationType = "content_based"
	RecommendationCollaborative RecommendationType = "collaborative"
	RecommendationHybrid        RecommendationType = "hybrid"
	RecommendationPopularity    RecommendationType = "popularity"
	RecommendationTrending      RecommendationType = "trending"
)

type RolloutConfig ΒΆ

type RolloutConfig struct {
	Strategy   string            `json:"strategy"`   // "percentage", "user_list", "attributes"
	Percentage float64           `json:"percentage"` // 0.0 to 100.0
	UserList   []string          `json:"user_list,omitempty"`
	Attributes map[string]string `json:"attributes,omitempty"`
	StartTime  *time.Time        `json:"start_time,omitempty"`
	EndTime    *time.Time        `json:"end_time,omitempty"`
}

RolloutConfig defines gradual rollout configuration

type RuleAction ΒΆ

type RuleAction struct {
	Type   string                 `json:"type"`   // "enable", "disable", "variant", "redirect"
	Value  interface{}            `json:"value"`  // Variant ID, URL, etc.
	Config map[string]interface{} `json:"config"` // Additional configuration
}

RuleAction defines the action to take when a rule matches

type RuleCondition ΒΆ

type RuleCondition struct {
	Attribute     string      `json:"attribute"`
	Operator      string      `json:"operator"` // "equals", "not_equals", "contains", "in", "not_in", "greater_than", "less_than"
	Value         interface{} `json:"value"`
	CaseSensitive bool        `json:"case_sensitive"`
}

RuleCondition defines a condition for feature flag rules

type SRMConfig ΒΆ

type SRMConfig struct {
	Enabled          bool    `json:"enabled"`
	TolerancePercent float64 `json:"tolerance_percent"` // Allowed deviation from expected ratio
	AlertThreshold   float64 `json:"alert_threshold"`   // P-value threshold for alerts
}

SRMConfig defines Sample Ratio Mismatch detection

type SampleSizeConfig ΒΆ

type SampleSizeConfig struct {
	MinSamplePerVariant int                  `json:"min_sample_per_variant"`
	MaxSamplePerVariant int                  `json:"max_sample_per_variant"`
	PowerAnalysis       *PowerAnalysisConfig `json:"power_analysis,omitempty"`
}

SampleSizeConfig defines sample size requirements

type Segment ΒΆ

type Segment struct {
	ID          string            `json:"id"`
	Name        string            `json:"name"`
	Description string            `json:"description"`
	Criteria    []SegmentCriteria `json:"criteria"`
	CreatedAt   time.Time         `json:"created_at"`
}

Segment represents a user segment for analysis

type SegmentAnalysis ΒΆ

type SegmentAnalysis struct {
	SegmentID      string                     `json:"segment_id"`
	SegmentName    string                     `json:"segment_name"`
	UserCount      int64                      `json:"user_count"`
	VariantMetrics map[string][]MetricSummary `json:"variant_metrics"`
	Insights       []string                   `json:"insights"`
}

SegmentAnalysis provides analysis for a specific segment

type SegmentCriteria ΒΆ

type SegmentCriteria struct {
	Attribute string      `json:"attribute"`
	Operator  string      `json:"operator"` // "equals", "contains", "greater_than", etc.
	Value     interface{} `json:"value"`
}

SegmentCriteria defines criteria for user segmentation

type SimilarUser ΒΆ

type SimilarUser struct {
	UserID     string  `json:"user_id"`
	Similarity float64 `json:"similarity"`
}

SimilarUser represents a user similar to the target user

type StatisticalTest ΒΆ

type StatisticalTest struct {
	TestType         string  `json:"test_type"` // "t_test", "chi_square", "mann_whitney"
	MetricID         string  `json:"metric_id"`
	ControlVariant   string  `json:"control_variant"`
	TreatmentVariant string  `json:"treatment_variant"`
	PValue           float64 `json:"p_value"`
	TestStatistic    float64 `json:"test_statistic"`
	DegreesOfFreedom int     `json:"degrees_of_freedom,omitempty"`
	EffectSize       float64 `json:"effect_size"`
	IsSignificant    bool    `json:"is_significant"`
	ConfidenceLevel  float64 `json:"confidence_level"`
}

StatisticalTest represents results of a statistical test

type StoppingRule ΒΆ

type StoppingRule struct {
	ID        string                 `json:"id"`
	Type      string                 `json:"type"`      // "significance", "sample_size", "time", "custom"
	Condition map[string]interface{} `json:"condition"` // Rule-specific parameters
	Action    string                 `json:"action"`    // "stop", "extend", "notify"
	Priority  int                    `json:"priority"`
}

StoppingRule defines when to stop an experiment

type TargetingRule ΒΆ

type TargetingRule struct {
	ID         string          `json:"id"`
	Name       string          `json:"name"`
	Conditions []RuleCondition `json:"conditions"`
	Include    bool            `json:"include"` // true = include, false = exclude
	Priority   int             `json:"priority"`
}

TargetingRule defines who should be included in an experiment

type TimeRange ΒΆ

type TimeRange struct {
	Start time.Time `json:"start"`
	End   time.Time `json:"end"`
}

TimeRange represents a time range for analysis

type TimeSeriesPoint ΒΆ

type TimeSeriesPoint struct {
	Timestamp time.Time              `json:"timestamp"`
	VariantID string                 `json:"variant_id"`
	MetricID  string                 `json:"metric_id"`
	Value     float64                `json:"value"`
	Count     int64                  `json:"count"`
	Metadata  map[string]interface{} `json:"metadata"`
}

TimeSeriesPoint represents a point in time series data

type User ΒΆ

type User struct {
	ID           string             `json:"id"`
	Preferences  map[string]float64 `json:"preferences"` // User preference vector
	Demographics map[string]string  `json:"demographics"`
	Segments     []string           `json:"segments"`
	CreatedAt    time.Time          `json:"created_at"`
}

User represents a user in the recommendation system

type Variant ΒΆ

type Variant struct {
	ID          string                 `json:"id"`
	Name        string                 `json:"name"`
	Weight      float64                `json:"weight"`      // 0.0 to 1.0
	Config      map[string]interface{} `json:"config"`      // Variant-specific configuration
	Conversions int64                  `json:"conversions"` // Number of conversions
	Impressions int64                  `json:"impressions"` // Number of impressions
}

Variant represents a single variant in an A/B test

type VariantResults ΒΆ

type VariantResults struct {
	VariantID          string             `json:"variant_id"`
	Impressions        int64              `json:"impressions"`
	Conversions        int64              `json:"conversions"`
	ConversionRate     float64            `json:"conversion_rate"`
	ConfidenceInterval ConfidenceInterval `json:"confidence_interval"`
	PValue             float64            `json:"p_value,omitempty"`
	IsSignificant      bool               `json:"is_significant"`
}

VariantResults contains results for a single variant

Directories ΒΆ

Path Synopsis
api

Jump to

Keyboard shortcuts

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