mathexp

package
v0.0.0-...-900be4e Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Avg

func Avg(v *data.Field) *float64

func Count

func Count(fv *data.Field) *float64

func Max

func Max(fv *data.Field) *float64

func Min

func Min(fv *data.Field) *float64

func Sum

func Sum(v *data.Field) *float64

Types

type Expr

type Expr struct {
	*parse.Tree
}

Expr holds a parsed math command expression.

func New

func New(expr string, funcs ...map[string]parse.Func) (*Expr, error)

New creates a new expression tree

func (*Expr) Execute

func (e *Expr) Execute(refID string, vars Vars) (r Results, err error)

Execute applies a parse expression to the context and executes it

type Number

type Number struct{ Frame *data.Frame }

Number hold a labelled single number values.

func NewNumber

func NewNumber(name string, labels data.Labels) Number

NewNumber returns a data that holds a float64Vector

func (Number) AsDataFrame

func (n Number) AsDataFrame() *data.Frame

AsDataFrame returns the underlying *data.Frame.

func (Number) GetFloat64Value

func (n Number) GetFloat64Value() *float64

GetFloat64Value retrieves the single scalar value from the data

func (Number) GetLabels

func (n Number) GetLabels() data.Labels

func (Number) SetLabels

func (n Number) SetLabels(ls data.Labels)

func (Number) SetValue

func (n Number) SetValue(f *float64)

SetValue sets the value of the Number to float64 pointer f

func (Number) Type

func (n Number) Type() parse.ReturnType

Type returns the Value type and allows it to fulfill the Value interface.

func (Number) Value

func (n Number) Value() interface{}

Value returns the actual value allows it to fulfill the Value interface.

type Results

type Results struct {
	Values Values
}

Results is a container for Value interfaces.

func NewScalarResults

func NewScalarResults(name string, f *float64) Results

NewScalarResults creates a Results holding a single Scalar

type Scalar

type Scalar struct{ Frame *data.Frame }

Scalar is the type that holds a single number constant. Before returning from an expression it will be wrapped in a data frame.

func NewScalar

func NewScalar(name string, f *float64) Scalar

NewScalar creates a Scalar holding value f.

func (Scalar) AsDataFrame

func (s Scalar) AsDataFrame() *data.Frame

AsDataFrame returns the underlying *data.Frame.

func (Scalar) GetFloat64Value

func (s Scalar) GetFloat64Value() *float64

GetFloat64Value retrieves the single scalar value from the data

func (Scalar) GetLabels

func (s Scalar) GetLabels() data.Labels

func (Scalar) SetLabels

func (s Scalar) SetLabels(ls data.Labels)

func (Scalar) Type

func (s Scalar) Type() parse.ReturnType

Type returns the Value type and allows it to fulfill the Value interface.

func (Scalar) Value

func (s Scalar) Value() interface{}

Value returns the actual value allows it to fulfill the Value interface.

type Series

type Series struct {
	Frame           *data.Frame
	TimeIsNullable  bool
	TimeIdx         int
	ValueIsNullable bool
	ValueIdx        int
}

Series has time.Time and ...? *float64 fields.

func NewSeries

func NewSeries(refID string, labels data.Labels, timeIdx int, nullableTime bool, valueIdx int, nullableValue bool, size int) Series

NewSeries returns a dataframe of type Series.

func SeriesFromFrame

func SeriesFromFrame(frame *data.Frame) (s Series, err error)

SeriesFromFrame validates that the dataframe can be considered a Series type and populate meta information on Series about the frame.

func (Series) AppendPoint

func (s Series) AppendPoint(pointIdx int, t *time.Time, f *float64) (err error)

AppendPoint appends a point (time/value).

func (Series) AsDataFrame

func (s Series) AsDataFrame() *data.Frame

AsDataFrame returns the underlying *data.Frame.

func (Series) GetLabels

func (s Series) GetLabels() data.Labels

func (Series) GetName

func (s Series) GetName() string

func (Series) GetPoint

func (s Series) GetPoint(pointIdx int) (*time.Time, *float64)

GetPoint returns the time and value at the specified index.

func (Series) GetTime

func (s Series) GetTime(pointIdx int) *time.Time

GetTime returns the time at the specified index.

func (Series) GetValue

func (s Series) GetValue(pointIdx int) *float64

GetValue returns the float value at the specified index.

func (Series) Len

func (s Series) Len() int

Len returns the length of the series.

func (Series) Reduce

func (s Series) Reduce(refID, rFunc string) (Number, error)

Reduce turns the Series into a Number based on the given reduction function

func (Series) Resample

func (s Series) Resample(refID string, interval time.Duration, downsampler string, upsampler string, tr backend.TimeRange) (Series, error)

Resample turns the Series into a Number based on the given reduction function

func (Series) SetLabels

func (s Series) SetLabels(ls data.Labels)

func (Series) SetPoint

func (s Series) SetPoint(pointIdx int, t *time.Time, f *float64) (err error)

SetPoint sets the time and value on the corresponding vectors at the specified index.

func (Series) SortByTime

func (s Series) SortByTime(desc bool)

SortByTime sorts the series by the time from oldest to newest. If desc is true, it will sort from newest to oldest. If any time values are nil, it will panic.

func (Series) Type

func (s Series) Type() parse.ReturnType

Type returns the Value type and allows it to fulfill the Value interface.

func (Series) Value

func (s Series) Value() interface{}

Value returns the actual value allows it to fulfill the Value interface.

type SortSeriesByTime

type SortSeriesByTime Series

SortSeriesByTime allows a Series to be sorted by time the sort interface will panic if any timestamps are null

func (SortSeriesByTime) Len

func (ss SortSeriesByTime) Len() int

func (SortSeriesByTime) Less

func (ss SortSeriesByTime) Less(i, j int) bool

func (SortSeriesByTime) Swap

func (ss SortSeriesByTime) Swap(i, j int)

type State

type State struct {
	*Expr
	Vars Vars
	// Could hold more properties that change behavior around:
	//  - Unions (How many result A and many Result B in case A + B are joined)
	//  - NaN/Null behavior
	RefID string
}

State embeds a parsed Expr with variables and their results so the expression can act on them.

type Union

type Union struct {
	Labels data.Labels
	A, B   Value
}

Union holds to Values from Two sets where their labels are compatible (TODO: define compatible). This is a intermediate container for Binary operations such (e.g. A + B).

type Value

type Value interface {
	Type() parse.ReturnType
	Value() interface{}
	GetLabels() data.Labels
	SetLabels(data.Labels)
	AsDataFrame() *data.Frame
}

Value is the interface that holds different types such as a Scalar, Series, or Number. all Value implementations should be a *data.Frame

type Values

type Values []Value

Values is a slice of Value interfaces

func (Values) AsDataFrames

func (vals Values) AsDataFrames(refID string) []*data.Frame

AsDataFrames returns each value as a slice of frames.

type Vars

type Vars map[string]Results

Vars holds the results of datasource queries or other expression commands.

Directories

Path Synopsis
Package parse builds parse trees for expressions as defined by expr.
Package parse builds parse trees for expressions as defined by expr.

Jump to

Keyboard shortcuts

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