mathexp

package
v0.0.0-kmdagger1 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2023 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Avg

func Avg(fv *Float64Field) *float64

func Count

func Count(fv *Float64Field) *float64

func GetSupportedReduceFuncs

func GetSupportedReduceFuncs() []string

GetSupportedReduceFuncs returns collection of supported function names

func Last

func Last(fv *Float64Field) *float64

func Max

func Max(fv *Float64Field) *float64

func Min

func Min(fv *Float64Field) *float64

func Sum

func Sum(fv *Float64Field) *float64

Types

type DropNonNumber

type DropNonNumber struct {
}

func (DropNonNumber) MapInput

func (d DropNonNumber) MapInput(s *float64) *float64

MapInput returns nil if the input parameter is nil or point to either a NaN or a Inf

func (DropNonNumber) MapOutput

func (d DropNonNumber) MapOutput(s *float64) *float64

MapOutput returns nil if the input parameter is nil or point to either a NaN or a Inf

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, tracer tracing.Tracer) (r Results, err error)

Execute applies a parse expression to the context and executes it

type Float64Field

type Float64Field data.Field

FloatField is a *float64 or a float64 data.Field with methods to always get a *float64.

func (*Float64Field) GetValue

func (ff *Float64Field) GetValue(idx int) *float64

GetValue returns the value at idx as *float64.

func (*Float64Field) Len

func (ff *Float64Field) Len() int

Len returns the the length of the field.

type NoData

type NoData struct{ Frame *data.Frame }

NoData is an untyped no data response.

func NewNoData

func NewNoData() NoData

func (NoData) AddNotice

func (s NoData) AddNotice(notice data.Notice)

func (NoData) AsDataFrame

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

func (NoData) GetLabels

func (s NoData) GetLabels() data.Labels

func (NoData) GetMeta

func (s NoData) GetMeta() interface{}

func (NoData) New

func (s NoData) New() NoData

func (NoData) SetLabels

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

func (NoData) SetMeta

func (s NoData) SetMeta(v interface{})

func (NoData) Type

func (s NoData) Type() parse.ReturnType

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

func (NoData) Value

func (s NoData) Value() interface{}

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

type Number

type Number struct{ Frame *data.Frame }

Number hold a labelled single number values.

func GenerateNumber

func GenerateNumber(value *float64) Number

func NewNumber

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

NewNumber returns a data that holds a float64Vector

func NumberFromRef

func NumberFromRef(refID string, nr numeric.MetricRef) (Number, error)

NewNumber returns a data that holds a float64Vector

func (Number) AddNotice

func (n Number) AddNotice(notice data.Notice)

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) GetMeta

func (n Number) GetMeta() interface{}

func (Number) SetLabels

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

func (Number) SetMeta

func (n Number) SetMeta(v interface{})

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 ReduceMapper

type ReduceMapper interface {
	MapInput(s *float64) *float64
	MapOutput(v *float64) *float64
}

type ReducerFunc

type ReducerFunc = func(fv *Float64Field) *float64

func GetReduceFunc

func GetReduceFunc(rFunc string) (ReducerFunc, error)

type ReplaceNonNumberWithValue

type ReplaceNonNumberWithValue struct {
	Value float64
}

func (ReplaceNonNumberWithValue) MapInput

func (r ReplaceNonNumberWithValue) MapInput(v *float64) *float64

MapInput returns a pointer to ReplaceNonNumberWithValue.Value if input parameter is nil or points to either a NaN or an Inf. Otherwise, returns the input pointer as is.

func (ReplaceNonNumberWithValue) MapOutput

func (r ReplaceNonNumberWithValue) MapOutput(s *float64) *float64

MapOutput returns a pointer to ReplaceNonNumberWithValue.Value if input parameter is nil or points to either a NaN or an Inf. Otherwise, returns the input pointer as is.

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) AddNotice

func (s Scalar) AddNotice(notice data.Notice)

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) GetMeta

func (s Scalar) GetMeta() interface{}

func (Scalar) SetLabels

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

func (Scalar) SetMeta

func (s Scalar) SetMeta(v interface{})

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
}

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

func NewSeries

func NewSeries(refID string, labels data.Labels, size int) Series

NewSeries returns a dataframe of type Series.

func NewSeriesFromRef

func NewSeriesFromRef(refID string, s timeseries.MetricRef) (Series, error)

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 mutates the frame to be in the format that additional SSE operations expect.

func (Series) AddNotice

func (s Series) AddNotice(notice data.Notice)

func (Series) AppendPoint

func (s Series) AppendPoint(t time.Time, f *float64)

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) GetMeta

func (s Series) GetMeta() interface{}

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, mapper ReduceMapper) (Number, error)

Reduce turns the Series into a Number based on the given reduction function if ReduceMapper is defined it applies it to the provided series and performs reduction of the resulting series. Otherwise, the reduction operation is done against the original series.

func (Series) Resample

func (s Series) Resample(refID string, interval time.Duration, downsampler string, upsampler string, from, to time.Time) (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) SetMeta

func (s Series) SetMeta(v interface{})

func (Series) SetPoint

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

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
	// contains filtered or unexported fields
}

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)
	GetMeta() interface{}
	SetMeta(interface{})
	AsDataFrame() *data.Frame
	AddNotice(notice data.Notice)
}

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