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
)

Variables

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

segmenters contain all the registered experiment segmenters by name.

Functions

func ProtobufSegmenterConfigToOpenAPISegmenterConfig

func ProtobufSegmenterConfigToOpenAPISegmenterConfig(segmenterConfiguration *_segmenters.SegmenterConfiguration) (*schema.Segmenter, error)

func Register

func Register(name string, factory Factory) error

Register an experiment segmenter 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 is implemented. The name of the experiment segmenters should be unique across all implementations. Registering multiple experiment segmenters with the same name will return an error.

func ToProtoValues

func ToProtoValues(
	segments map[string]interface{},
	segmentersType map[string]schema.SegmenterType,
) (map[string]*_segmenters.ListSegmenterValue, error)

Types

type BaseSegmenter

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

func (*BaseSegmenter) GetConfiguration

func (s *BaseSegmenter) GetConfiguration() (*_segmenters.SegmenterConfiguration, error)

func (*BaseSegmenter) GetExperimentVariables

func (s *BaseSegmenter) GetExperimentVariables() *_segmenters.ListExperimentVariables

func (*BaseSegmenter) GetName

func (s *BaseSegmenter) GetName() string

func (*BaseSegmenter) GetType

func (*BaseSegmenter) IsValidType

func (s *BaseSegmenter) IsValidType(inputValues []*_segmenters.SegmenterValue) bool

IsValidType checks that the input values for the segmenter are of the configured type

func (*BaseSegmenter) ValidateSegmenterAndConstraints

func (s *BaseSegmenter) ValidateSegmenterAndConstraints(segment map[string]*_segmenters.ListSegmenterValue) error

ValidateSegmenterAndConstraints validates the current segmenter's values, taking into account the configuration of the whole segment.

type Factory

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

Factory creates a segmenter manager from the provided config.

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

type S2IDSegmenterConfig

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

type Segmenter

type Segmenter interface {
	GetName() string
	GetType() _segmenters.SegmenterValueType
	GetConfiguration() (*_segmenters.SegmenterConfiguration, error)
	GetExperimentVariables() *_segmenters.ListExperimentVariables
	IsValidType(inputValues []*_segmenters.SegmenterValue) bool
	ValidateSegmenterAndConstraints(segment map[string]*_segmenters.ListSegmenterValue) error
}

func Get

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

Get an experiment segmenter that has been registered.

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

func NewDaysOfWeekSegmenter

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

func NewHoursOfDaySegmenter

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

func NewS2IDSegmenter

func NewS2IDSegmenter(configData json.RawMessage) (Segmenter, error)

Jump to

Keyboard shortcuts

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