segmenters

package
v0.0.0-...-6cc63a5 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MinS2CellLevel is the permissible minimum value for S2 Cell level
	MinS2CellLevel = 0
	// MaxS2CellLevel is the permissible maximum value for S2 Cell level
	MaxS2CellLevel = 30
)
View Source
const TypeCastingErrorTmpl = "invalid type of variable (%s) was provided for %s segmenter; expected %s"

Variables

View Source
var Runners = make(map[string]Factory)

Runners contain all the registered segmenter runners by name.

Functions

func Register

func Register(name string, factory Factory) error

Register a segmenter runner with the provided name and factory function.

For registration to be properly recorded, Register function should be called in the init phase of the Go execution. The init function is usually defined in the package where the segmenter runner is implemented. The name of the segmenter runners should be unique across all implementations. Registering multiple segmenter runners with the same name will return an error.

Types

type BaseRunner

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

func NewBaseRunner

func NewBaseRunner(s *SegmenterConfig) *BaseRunner

func (*BaseRunner) GetName

func (r *BaseRunner) GetName() string

func (*BaseRunner) Transform

func (r *BaseRunner) Transform(
	segmenter string,
	requestValues map[string]interface{},
	experimentVariables []string,
) ([]*_segmenters.SegmenterValue, error)

type Factory

type Factory func(config json.RawMessage) (Runner, error)

Factory creates a segmenter runner from the provided config.

Config is a raw encoded JSON value. The segmenter runner implementation for each segmenter should provide a schema and example of the JSON value to explain the usage.

type Runner

type Runner interface {
	GetName() string
	Transform(name string, requestValues map[string]interface{}, experimentVariables []string) ([]*_segmenters.SegmenterValue, error)
}

func Get

func Get(name string, config json.RawMessage) (Runner, error)

Get a segmenter runner that has been registered.

The segmenter runner will be initialized using the registered factory function with the provided config. Retrieving a segmenter runner that is not yet registered will return an error.

func NewDaysOfWeekSegmenter

func NewDaysOfWeekSegmenter(_ json.RawMessage) (Runner, error)

func NewHoursOfDaySegmenter

func NewHoursOfDaySegmenter(_ json.RawMessage) (Runner, error)

func NewS2IDRunner

func NewS2IDRunner(configData json.RawMessage) (Runner, error)

type S2IDSegmenterConfig

type S2IDSegmenterConfig struct {
	MinS2CellLevel int `json:"mins2celllevel"`
	MaxS2CellLevel int `json:"maxs2celllevel"`
}

type SegmenterConfig

type SegmenterConfig struct {
	Name string
	Type *_segmenters.SegmenterValueType
}

Jump to

Keyboard shortcuts

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