Added functions
Signed-off-by: Levi Harrison <git@leviharrison.dev>
This commit is contained in:
parent
bd217c58a7
commit
309e020c0a
|
@ -570,6 +570,70 @@ func funcLog10(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper
|
||||||
return simpleFunc(vals, enh, math.Log10)
|
return simpleFunc(vals, enh, math.Log10)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// === sin(Vector parser.ValueTypeVector) Vector ===
|
||||||
|
func funcSin(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper) Vector {
|
||||||
|
return simpleFunc(vals, enh, math.Sin)
|
||||||
|
}
|
||||||
|
|
||||||
|
// === cos(Vector parser.ValueTypeVector) Vector ===
|
||||||
|
func funcCos(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper) Vector {
|
||||||
|
return simpleFunc(vals, enh, math.Cos)
|
||||||
|
}
|
||||||
|
|
||||||
|
// === tan(Vector parser.ValueTypeVector) Vector ===
|
||||||
|
func funcTan(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper) Vector {
|
||||||
|
return simpleFunc(vals, enh, math.Tan)
|
||||||
|
}
|
||||||
|
|
||||||
|
// == asin(Vector parser.ValueTypeVector) Vector ===
|
||||||
|
func funcAsin(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper) Vector {
|
||||||
|
return simpleFunc(vals, enh, math.Asin)
|
||||||
|
}
|
||||||
|
|
||||||
|
// == acos(Vector parser.ValueTypeVector) Vector ===
|
||||||
|
func funcAcos(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper) Vector {
|
||||||
|
return simpleFunc(vals, enh, math.Acos)
|
||||||
|
}
|
||||||
|
|
||||||
|
// == atan(Vector parser.ValueTypeVector) Vector ===
|
||||||
|
func funcAtan(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper) Vector {
|
||||||
|
return simpleFunc(vals, enh, math.Atan)
|
||||||
|
}
|
||||||
|
|
||||||
|
// === atan2(Vector1, Vector2 parser.ValueTypeVector) Vector ===
|
||||||
|
func funcAtan2(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper) Vector {
|
||||||
|
y := vals[0].(Vector)
|
||||||
|
x := vals[1].(Vector)
|
||||||
|
|
||||||
|
for i := 0; i < len(y); i++ {
|
||||||
|
enh.Out = append(enh.Out, Sample{
|
||||||
|
Point: Point{V: math.Atan2(y[i].V, x[i].V)},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return enh.Out
|
||||||
|
}
|
||||||
|
|
||||||
|
// === rad(Vector parser.ValueTypeVector) Vector ===
|
||||||
|
func funcRad(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper) Vector {
|
||||||
|
return simpleFunc(vals, enh, func(v float64) float64 {
|
||||||
|
return v * (math.Pi / 180)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// === deg(Vector parser.ValueTypeVector) Vector ===
|
||||||
|
func funcDeg(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper) Vector {
|
||||||
|
return simpleFunc(vals, enh, func(v float64) float64 {
|
||||||
|
return v * 180 / math.Pi
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// === pi(Vector parser.ValueTypeVector) Vector ===
|
||||||
|
func funcPi(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper) Vector {
|
||||||
|
return Vector{Sample{Point: Point{
|
||||||
|
V: math.Pi,
|
||||||
|
}}}
|
||||||
|
}
|
||||||
|
|
||||||
// === sgn(Vector parser.ValueTypeVector) Vector ===
|
// === sgn(Vector parser.ValueTypeVector) Vector ===
|
||||||
func funcSgn(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper) Vector {
|
func funcSgn(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper) Vector {
|
||||||
return simpleFunc(vals, enh, func(v float64) float64 {
|
return simpleFunc(vals, enh, func(v float64) float64 {
|
||||||
|
@ -935,16 +999,22 @@ var FunctionCalls = map[string]FunctionCall{
|
||||||
"abs": funcAbs,
|
"abs": funcAbs,
|
||||||
"absent": funcAbsent,
|
"absent": funcAbsent,
|
||||||
"absent_over_time": funcAbsentOverTime,
|
"absent_over_time": funcAbsentOverTime,
|
||||||
|
"acos": funcAcos,
|
||||||
|
"asin": funcAsin,
|
||||||
|
"atan": funcAtan,
|
||||||
|
"atan2": funcAtan2,
|
||||||
"avg_over_time": funcAvgOverTime,
|
"avg_over_time": funcAvgOverTime,
|
||||||
"ceil": funcCeil,
|
"ceil": funcCeil,
|
||||||
"changes": funcChanges,
|
"changes": funcChanges,
|
||||||
"clamp": funcClamp,
|
"clamp": funcClamp,
|
||||||
"clamp_max": funcClampMax,
|
"clamp_max": funcClampMax,
|
||||||
"clamp_min": funcClampMin,
|
"clamp_min": funcClampMin,
|
||||||
|
"cos": funcCos,
|
||||||
"count_over_time": funcCountOverTime,
|
"count_over_time": funcCountOverTime,
|
||||||
"days_in_month": funcDaysInMonth,
|
"days_in_month": funcDaysInMonth,
|
||||||
"day_of_month": funcDayOfMonth,
|
"day_of_month": funcDayOfMonth,
|
||||||
"day_of_week": funcDayOfWeek,
|
"day_of_week": funcDayOfWeek,
|
||||||
|
"deg": funcDeg,
|
||||||
"delta": funcDelta,
|
"delta": funcDelta,
|
||||||
"deriv": funcDeriv,
|
"deriv": funcDeriv,
|
||||||
"exp": funcExp,
|
"exp": funcExp,
|
||||||
|
@ -965,20 +1035,24 @@ var FunctionCalls = map[string]FunctionCall{
|
||||||
"min_over_time": funcMinOverTime,
|
"min_over_time": funcMinOverTime,
|
||||||
"minute": funcMinute,
|
"minute": funcMinute,
|
||||||
"month": funcMonth,
|
"month": funcMonth,
|
||||||
|
"pi": funcPi,
|
||||||
"predict_linear": funcPredictLinear,
|
"predict_linear": funcPredictLinear,
|
||||||
"present_over_time": funcPresentOverTime,
|
"present_over_time": funcPresentOverTime,
|
||||||
"quantile_over_time": funcQuantileOverTime,
|
"quantile_over_time": funcQuantileOverTime,
|
||||||
|
"rad": funcRad,
|
||||||
"rate": funcRate,
|
"rate": funcRate,
|
||||||
"resets": funcResets,
|
"resets": funcResets,
|
||||||
"round": funcRound,
|
"round": funcRound,
|
||||||
"scalar": funcScalar,
|
"scalar": funcScalar,
|
||||||
"sgn": funcSgn,
|
"sgn": funcSgn,
|
||||||
|
"sin": funcSin,
|
||||||
"sort": funcSort,
|
"sort": funcSort,
|
||||||
"sort_desc": funcSortDesc,
|
"sort_desc": funcSortDesc,
|
||||||
"sqrt": funcSqrt,
|
"sqrt": funcSqrt,
|
||||||
"stddev_over_time": funcStddevOverTime,
|
"stddev_over_time": funcStddevOverTime,
|
||||||
"stdvar_over_time": funcStdvarOverTime,
|
"stdvar_over_time": funcStdvarOverTime,
|
||||||
"sum_over_time": funcSumOverTime,
|
"sum_over_time": funcSumOverTime,
|
||||||
|
"tan": funcTan,
|
||||||
"time": funcTime,
|
"time": funcTime,
|
||||||
"timestamp": funcTimestamp,
|
"timestamp": funcTimestamp,
|
||||||
"vector": funcVector,
|
"vector": funcVector,
|
||||||
|
|
|
@ -39,9 +39,24 @@ var Functions = map[string]*Function{
|
||||||
ArgTypes: []ValueType{ValueTypeMatrix},
|
ArgTypes: []ValueType{ValueTypeMatrix},
|
||||||
ReturnType: ValueTypeVector,
|
ReturnType: ValueTypeVector,
|
||||||
},
|
},
|
||||||
"present_over_time": {
|
"acos": {
|
||||||
Name: "present_over_time",
|
Name: "acos",
|
||||||
ArgTypes: []ValueType{ValueTypeMatrix},
|
ArgTypes: []ValueType{ValueTypeVector},
|
||||||
|
ReturnType: ValueTypeVector,
|
||||||
|
},
|
||||||
|
"asin": {
|
||||||
|
Name: "asin",
|
||||||
|
ArgTypes: []ValueType{ValueTypeVector},
|
||||||
|
ReturnType: ValueTypeVector,
|
||||||
|
},
|
||||||
|
"atan": {
|
||||||
|
Name: "atan",
|
||||||
|
ArgTypes: []ValueType{ValueTypeVector},
|
||||||
|
ReturnType: ValueTypeVector,
|
||||||
|
},
|
||||||
|
"atan2": {
|
||||||
|
Name: "atan2",
|
||||||
|
ArgTypes: []ValueType{ValueTypeVector, ValueTypeVector},
|
||||||
ReturnType: ValueTypeVector,
|
ReturnType: ValueTypeVector,
|
||||||
},
|
},
|
||||||
"avg_over_time": {
|
"avg_over_time": {
|
||||||
|
@ -74,6 +89,11 @@ var Functions = map[string]*Function{
|
||||||
ArgTypes: []ValueType{ValueTypeVector, ValueTypeScalar},
|
ArgTypes: []ValueType{ValueTypeVector, ValueTypeScalar},
|
||||||
ReturnType: ValueTypeVector,
|
ReturnType: ValueTypeVector,
|
||||||
},
|
},
|
||||||
|
"cos": {
|
||||||
|
Name: "cos",
|
||||||
|
ArgTypes: []ValueType{ValueTypeVector},
|
||||||
|
ReturnType: ValueTypeVector,
|
||||||
|
},
|
||||||
"count_over_time": {
|
"count_over_time": {
|
||||||
Name: "count_over_time",
|
Name: "count_over_time",
|
||||||
ArgTypes: []ValueType{ValueTypeMatrix},
|
ArgTypes: []ValueType{ValueTypeMatrix},
|
||||||
|
@ -97,6 +117,11 @@ var Functions = map[string]*Function{
|
||||||
Variadic: 1,
|
Variadic: 1,
|
||||||
ReturnType: ValueTypeVector,
|
ReturnType: ValueTypeVector,
|
||||||
},
|
},
|
||||||
|
"deg": {
|
||||||
|
Name: "deg",
|
||||||
|
ArgTypes: []ValueType{ValueTypeVector},
|
||||||
|
ReturnType: ValueTypeVector,
|
||||||
|
},
|
||||||
"delta": {
|
"delta": {
|
||||||
Name: "delta",
|
Name: "delta",
|
||||||
ArgTypes: []ValueType{ValueTypeMatrix},
|
ArgTypes: []ValueType{ValueTypeMatrix},
|
||||||
|
@ -201,16 +226,32 @@ var Functions = map[string]*Function{
|
||||||
Variadic: 1,
|
Variadic: 1,
|
||||||
ReturnType: ValueTypeVector,
|
ReturnType: ValueTypeVector,
|
||||||
},
|
},
|
||||||
|
"pi": {
|
||||||
|
Name: "pi",
|
||||||
|
ArgTypes: []ValueType{},
|
||||||
|
Variadic: 1,
|
||||||
|
ReturnType: ValueTypeVector,
|
||||||
|
},
|
||||||
"predict_linear": {
|
"predict_linear": {
|
||||||
Name: "predict_linear",
|
Name: "predict_linear",
|
||||||
ArgTypes: []ValueType{ValueTypeMatrix, ValueTypeScalar},
|
ArgTypes: []ValueType{ValueTypeMatrix, ValueTypeScalar},
|
||||||
ReturnType: ValueTypeVector,
|
ReturnType: ValueTypeVector,
|
||||||
},
|
},
|
||||||
|
"present_over_time": {
|
||||||
|
Name: "present_over_time",
|
||||||
|
ArgTypes: []ValueType{ValueTypeMatrix},
|
||||||
|
ReturnType: ValueTypeVector,
|
||||||
|
},
|
||||||
"quantile_over_time": {
|
"quantile_over_time": {
|
||||||
Name: "quantile_over_time",
|
Name: "quantile_over_time",
|
||||||
ArgTypes: []ValueType{ValueTypeScalar, ValueTypeMatrix},
|
ArgTypes: []ValueType{ValueTypeScalar, ValueTypeMatrix},
|
||||||
ReturnType: ValueTypeVector,
|
ReturnType: ValueTypeVector,
|
||||||
},
|
},
|
||||||
|
"rad": {
|
||||||
|
Name: "rad",
|
||||||
|
ArgTypes: []ValueType{ValueTypeVector},
|
||||||
|
ReturnType: ValueTypeVector,
|
||||||
|
},
|
||||||
"rate": {
|
"rate": {
|
||||||
Name: "rate",
|
Name: "rate",
|
||||||
ArgTypes: []ValueType{ValueTypeMatrix},
|
ArgTypes: []ValueType{ValueTypeMatrix},
|
||||||
|
@ -237,6 +278,11 @@ var Functions = map[string]*Function{
|
||||||
ArgTypes: []ValueType{ValueTypeVector},
|
ArgTypes: []ValueType{ValueTypeVector},
|
||||||
ReturnType: ValueTypeVector,
|
ReturnType: ValueTypeVector,
|
||||||
},
|
},
|
||||||
|
"sin": {
|
||||||
|
Name: "sin",
|
||||||
|
ArgTypes: []ValueType{ValueTypeVector},
|
||||||
|
ReturnType: ValueTypeVector,
|
||||||
|
},
|
||||||
"sort": {
|
"sort": {
|
||||||
Name: "sort",
|
Name: "sort",
|
||||||
ArgTypes: []ValueType{ValueTypeVector},
|
ArgTypes: []ValueType{ValueTypeVector},
|
||||||
|
@ -267,6 +313,11 @@ var Functions = map[string]*Function{
|
||||||
ArgTypes: []ValueType{ValueTypeMatrix},
|
ArgTypes: []ValueType{ValueTypeMatrix},
|
||||||
ReturnType: ValueTypeVector,
|
ReturnType: ValueTypeVector,
|
||||||
},
|
},
|
||||||
|
"tan": {
|
||||||
|
Name: "tan",
|
||||||
|
ArgTypes: []ValueType{ValueTypeVector},
|
||||||
|
ReturnType: ValueTypeVector,
|
||||||
|
},
|
||||||
"time": {
|
"time": {
|
||||||
Name: "time",
|
Name: "time",
|
||||||
ArgTypes: []ValueType{},
|
ArgTypes: []ValueType{},
|
||||||
|
|
Loading…
Reference in New Issue