datasets

package
v0.0.0-...-5e0ed37 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2021 License: Apache-2.0 Imports: 9 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	InterpolatorRegistry = map[string]*Interpolator{}

	RegistryLock = &sync.RWMutex{}
)

InterpolatorRegsitry is a map of the registered interpolators. Only use this structure when displaying documentation, do not manually add interpolators. Instead, use the Interpolator.Register() method.

View Source
var TransformInterpolator = &Interpolator{
	Name:        "transform",
	Description: "Allows using pipescript transforms to interpolate between values",
	Options: map[string]interface{}{
		"transform": map[string]interface{}{
			"type": "string",
		},
		"run_on": map[string]interface{}{
			"type":    "string",
			"enum":    []interface{}{"t", "dt"},
			"default": "t",
		},
		"required": []interface{}{"transform", "run_on"},
	},
	Constructor: func(name string, options map[string]interface{}, reference *pipescript.BufferIterator, stream pipescript.Iterator) (pipescript.Iterator, error) {
		var opt TIOptions
		err := mapstructure.Decode(options, &opt)
		if err != nil {
			return nil, err
		}
		if opt.Transform == "" {
			return nil, errors.New("Empty transform")
		}
		p, err := pipescript.Parse(opt.Transform)
		if err != nil {
			return nil, err
		}
		tsi := timestampIterator{
			Until:    -9999999999,
			Iterator: stream,
		}
		switch opt.RunOn {
		case "t":
			return &tTransformInterpolator{
				ref:  reference,
				pipe: p,
				tsi:  tsi,
				opt:  opt,
			}, nil
		case "dt":
			return &dtTransformInterpolator{
				ref:  reference,
				pipe: p,
				tsi:  tsi,
				opt:  opt,
			}, nil
		default:
			return nil, errors.New("Unrecognized transform run_on value")
		}
	},
}

Functions

func GetInterpolator

func GetInterpolator(interpolator string, options map[string]interface{}, reference *pipescript.BufferIterator, stream pipescript.Iterator) (pipescript.Iterator, error)

GetInterpolator parses the interpolator given and returns everything initialized. If the given string cannot be parsed as an interpolator, it is assumed to be PipeScript, and a ScriptInterpolator is returned based upon the pipescript. If both these methods fail, returns an error.

func Merge

Merge takes multiple Iterators and merges them into one Iterator based upon increasing timestamp. Remember that everywhere in PipeScript, it is assumed that datapoints have increasing timestamp, that is, they are ordered by time.

func Unregister

func Unregister(name string)

Unregister removes the given named interpolator from the registry

Types

type Dataset

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

Dataset allows to create a tabular structure

func NewDataset

func NewDataset(stream pipescript.Iterator) *Dataset

func NewTDataset

func NewTDataset(t1, t2, dt float64) *Dataset

func (*Dataset) Add

func (d *Dataset) Add(key string, it pipescript.Iterator)

func (*Dataset) Next

func (*Dataset) Reference

func (d *Dataset) Reference() *pipescript.BufferIterator

type Interpolator

type Interpolator struct {
	Name          string                 `json:"name"`          // The name of the interpolator
	Description   string                 `json:"description"`   // The docstring of the interpolator
	Documentation string                 `json:"documentation"` // The full documentation for the interpolator in markdown
	Options       map[string]interface{} `json:"options"`       // The options available to the interpolator

	Constructor InterpolatorConstructor `json:"-"` // The generator function of the interpolator
	// contains filtered or unexported fields
}

Interpolator is the struct which holds documentation and generator for an Interpolation method.

func (*Interpolator) Register

func (i *Interpolator) Register() error

Regsiter registers the interpolator with the system. See documentation for pipescript.Transform.Regsiter() as the two are implemented in the same way.

type InterpolatorConstructor

type InterpolatorConstructor func(name string, options map[string]interface{}, reference *pipescript.BufferIterator, stream pipescript.Iterator) (pipescript.Iterator, error)

InterpolatorConstructor creates a new Iterator, which will return a datapoint for each element of reference.

type JSONSchema

type JSONSchema struct {
	Schema map[string]interface{}
	// contains filtered or unexported fields
}

func NewSchema

func NewSchema(schema map[string]interface{}) (*JSONSchema, error)

func (*JSONSchema) Validate

func (s *JSONSchema) Validate(data map[string]interface{}) error

Validate ensures that the passed data conforms to the given schema

func (*JSONSchema) ValidateUpdate

func (s *JSONSchema) ValidateUpdate(data map[string]interface{}) (err error)

ValidateUpdate checks an update struct for validity

func (*JSONSchema) ValidateWithDefaults

func (s *JSONSchema) ValidateWithDefaults(data map[string]interface{}) (err error)

ValidateWithDefaults both validates the given data, and inserts defaults for any missing values in the root object

type TIOptions

type TIOptions struct {
	Transform string `mapstructure:"transform"`
	RunOn     string `mapstructure:"run_on"`
}

type TestCase

type TestCase struct {
	Interpolator string // The interpolator to run
	Options      map[string]interface{}
	Reference    []pipescript.Datapoint
	Stream       []pipescript.Datapoint // The input datapoints
	GetError     bool                   // Whether there is to be a parsing error
	OutputError  bool                   // Whether there is to be an error during output
	Output       []pipescript.Datapoint // The output associated with the interpolator
}

TestCase is a simplified test case generator for use in testing Interpolators. Use this to make sure interpolators are doing the right thing.

func (TestCase) Run

func (tc TestCase) Run(t *testing.T)

Run the test case

type TestOutput

type TestOutput struct {
	Timestamp float64 // The timestamp to use while interpolating
	Duration  float64 // Duration to use

	Output *pipescript.Datapoint // The expected output datapoint. nil if error expected (and last)
}

TestOutput is an output of the interpolator

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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