choices

package module
v0.0.0-...-f5f25a8 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2016 License: Apache-2.0 Imports: 8 Imported by: 0

README

GoDoc

choices

A way to choose things.

Documentation

Overview

Package choices provides a library for simple a/b and multivariate testing.

choices uses hashing to uniquely assign users to experiments and decide the values the user is assigned. This allows us to quickly assign a user to an experiment with out having to look up what they were assigned previously. Most of the ideas in this package are based off of Facebook's Planout.

In choices there are three main concepts. Namespaces, Experiments, and Params. Namespaces split traffic between the experiments they contain. Experiments are the element you are testing. Experiments are made up of one or more Params. Params are a key value pair. The value can be either a Uniform Choice value or a Weighted Choice value.

In most cases you will want to create one namespace per experiment. If you have experiments that might have interactions you can use namespaces to split the traffic between them. For example, if you are running a test on a banner and another test that takes over the whole page, you will want to split the traffic between these two tests. Another example, is if you want to run a test on a small percent of traffic. Namespaces contain a list of TeamID's. These TeamID's are used to deterime which Experiments to return to the caller.

Experiments contain the Params for a running experiment. When a caller queries Namespaces, Namespaces will hash the user into a segment, It will then check if the segment is contained in an Experiment. If the segment is contained in the experiment then the experiment will be evaluated. An experiment will in turn evaluate each of it's Params.

Params are key-value pairs. They Options for value are Uniform choice or Weighted choice. Uniform choices will be selected in a uniform fashion. Weighted choices will be selected based on the proportions supplied in the weights.

Index

Constants

This section is empty.

Variables

View Source
var SegmentsAll = segments{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}

Functions

func GlobalSalt

func GlobalSalt(salt string) func(*ElwinConfig) error

WithGlobalSalt sets the salt used in hashing users.

func UpdateInterval

func UpdateInterval(dur time.Duration) func(*ElwinConfig) error

UpdateInterval changes the update interval for Storage. Must call SetStorage after this or cancel context of the current Storage and call SetStorage again.

Types

type ElwinConfig

type ElwinConfig struct {
	Storage Storage

	ErrChan chan error
	// contains filtered or unexported fields
}

func NewElwin

func NewElwin(ctx context.Context, opts ...func(*ElwinConfig) error) (*ElwinConfig, error)

NewElwin sets the storage engine. It starts a ticker that will call s.Update() until the context is cancelled. To change the tick interval call SetUpdateInterval(d time.Duration). Must cancel the context before calling NewElwin again otherwise you will leak go routines.

func (*ElwinConfig) Namespaces

func (ec *ElwinConfig) Namespaces(teamID, userID string) ([]ExperimentResponse, error)

Namespaces determines the assignments for the a given users units based on the current set of namespaces and experiments. It returns a Response object if it is successful or an error if something went wrong.

type Experiment

type Experiment struct {
	Name     string
	Params   []Param
	Segments segments
}

Experiment is a structure that represents a single experiment in elwin. It can contain multiple parameters. Experiments are evaluated through the call to Namespaces.

type ExperimentResponse

type ExperimentResponse struct {
	Name   string
	Params []ParamValue
}

ExperimentResponse holds the data for an evaluated expeiment.

type Namespace

type Namespace struct {
	Name        string
	Segments    segments
	TeamID      []string
	Experiments []Experiment
}

Namespace is a container for experiments. Segments in the namespace divide traffic. Units are the keys that will hash experiments.

func NewNamespace

func NewNamespace(name, teamID string) *Namespace

NewNamespace creates a new namespace with all segments available. It returns an error if no units are given.

func TeamNamespaces

func TeamNamespaces(s Storage, teamID string) []Namespace

TeamNamespaces filters the namespaces from storage based on teamID.

func (*Namespace) AddExperiment

func (n *Namespace) AddExperiment(name string, params []Param, numSegments int) error

AddExperiment adds an experiment to the namespace. It takes the the given number of segments from the namespace. It returns an error if the number of segments is larger than the number of available segments in the namespace.

type Param

type Param struct {
	Name  string
	Value Value
}

Param is a struct that represents a single parameter in an experiment. Param is evaluated through the call to Namespaces.

type ParamValue

type ParamValue struct {
	Name  string
	Value string
}

ParamValue is a key value pair returned from an evalated experiment parameter.

type Storage

type Storage interface {
	Update() error
	Read() []Namespace
}

Storage is an interface for the storage of experiments. Storage has two functions. Update, which checks for new data from the data store, and Read which returns the current slice of Namespaces. Clients using the storage interface should never write data to the slice returned by Namespaces. Storage should be read only the values should never be overwritten.

type Uniform

type Uniform struct {
	Choices []string
}

Uniform is a way to select from a list of Choices with uniform probability.

func (*Uniform) Value

func (u *Uniform) Value(i uint64) (string, error)

type Value

type Value interface {
	Value(i uint64) (string, error)
}

Value is the interface Param Values must implement. They take a hash value and return the string that represents the value or an error.

type ValueType

type ValueType int

ValueType are the different types of Values a Param can have. This is used for parsing params in storage.

const (
	ValueTypeBad ValueType = iota
	ValueTypeUniform
	ValueTypeWeighted
)

type Weighted

type Weighted struct {
	Choices []string
	Weights []float64
}

Weighted is a way to select from a list of Choices with probability ratio supplied in Weights.

func (*Weighted) Value

func (w *Weighted) Value(i uint64) (string, error)

Directories

Path Synopsis
cmd
Package elwin is a generated protocol buffer package.
Package elwin is a generated protocol buffer package.
storage
mem

Jump to

Keyboard shortcuts

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