Added functions

Signed-off-by: Levi Harrison <git@leviharrison.dev>
This commit is contained in:
Levi Harrison 2021-08-23 20:04:00 -04:00
parent bd217c58a7
commit 309e020c0a
2 changed files with 128 additions and 3 deletions

View File

@ -570,6 +570,70 @@ func funcLog10(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper
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 ===
func funcSgn(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper) Vector {
return simpleFunc(vals, enh, func(v float64) float64 {
@ -935,16 +999,22 @@ var FunctionCalls = map[string]FunctionCall{
"abs": funcAbs,
"absent": funcAbsent,
"absent_over_time": funcAbsentOverTime,
"acos": funcAcos,
"asin": funcAsin,
"atan": funcAtan,
"atan2": funcAtan2,
"avg_over_time": funcAvgOverTime,
"ceil": funcCeil,
"changes": funcChanges,
"clamp": funcClamp,
"clamp_max": funcClampMax,
"clamp_min": funcClampMin,
"cos": funcCos,
"count_over_time": funcCountOverTime,
"days_in_month": funcDaysInMonth,
"day_of_month": funcDayOfMonth,
"day_of_week": funcDayOfWeek,
"deg": funcDeg,
"delta": funcDelta,
"deriv": funcDeriv,
"exp": funcExp,
@ -965,20 +1035,24 @@ var FunctionCalls = map[string]FunctionCall{
"min_over_time": funcMinOverTime,
"minute": funcMinute,
"month": funcMonth,
"pi": funcPi,
"predict_linear": funcPredictLinear,
"present_over_time": funcPresentOverTime,
"quantile_over_time": funcQuantileOverTime,
"rad": funcRad,
"rate": funcRate,
"resets": funcResets,
"round": funcRound,
"scalar": funcScalar,
"sgn": funcSgn,
"sin": funcSin,
"sort": funcSort,
"sort_desc": funcSortDesc,
"sqrt": funcSqrt,
"stddev_over_time": funcStddevOverTime,
"stdvar_over_time": funcStdvarOverTime,
"sum_over_time": funcSumOverTime,
"tan": funcTan,
"time": funcTime,
"timestamp": funcTimestamp,
"vector": funcVector,

View File

@ -39,9 +39,24 @@ var Functions = map[string]*Function{
ArgTypes: []ValueType{ValueTypeMatrix},
ReturnType: ValueTypeVector,
},
"present_over_time": {
Name: "present_over_time",
ArgTypes: []ValueType{ValueTypeMatrix},
"acos": {
Name: "acos",
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,
},
"avg_over_time": {
@ -74,6 +89,11 @@ var Functions = map[string]*Function{
ArgTypes: []ValueType{ValueTypeVector, ValueTypeScalar},
ReturnType: ValueTypeVector,
},
"cos": {
Name: "cos",
ArgTypes: []ValueType{ValueTypeVector},
ReturnType: ValueTypeVector,
},
"count_over_time": {
Name: "count_over_time",
ArgTypes: []ValueType{ValueTypeMatrix},
@ -97,6 +117,11 @@ var Functions = map[string]*Function{
Variadic: 1,
ReturnType: ValueTypeVector,
},
"deg": {
Name: "deg",
ArgTypes: []ValueType{ValueTypeVector},
ReturnType: ValueTypeVector,
},
"delta": {
Name: "delta",
ArgTypes: []ValueType{ValueTypeMatrix},
@ -201,16 +226,32 @@ var Functions = map[string]*Function{
Variadic: 1,
ReturnType: ValueTypeVector,
},
"pi": {
Name: "pi",
ArgTypes: []ValueType{},
Variadic: 1,
ReturnType: ValueTypeVector,
},
"predict_linear": {
Name: "predict_linear",
ArgTypes: []ValueType{ValueTypeMatrix, ValueTypeScalar},
ReturnType: ValueTypeVector,
},
"present_over_time": {
Name: "present_over_time",
ArgTypes: []ValueType{ValueTypeMatrix},
ReturnType: ValueTypeVector,
},
"quantile_over_time": {
Name: "quantile_over_time",
ArgTypes: []ValueType{ValueTypeScalar, ValueTypeMatrix},
ReturnType: ValueTypeVector,
},
"rad": {
Name: "rad",
ArgTypes: []ValueType{ValueTypeVector},
ReturnType: ValueTypeVector,
},
"rate": {
Name: "rate",
ArgTypes: []ValueType{ValueTypeMatrix},
@ -237,6 +278,11 @@ var Functions = map[string]*Function{
ArgTypes: []ValueType{ValueTypeVector},
ReturnType: ValueTypeVector,
},
"sin": {
Name: "sin",
ArgTypes: []ValueType{ValueTypeVector},
ReturnType: ValueTypeVector,
},
"sort": {
Name: "sort",
ArgTypes: []ValueType{ValueTypeVector},
@ -267,6 +313,11 @@ var Functions = map[string]*Function{
ArgTypes: []ValueType{ValueTypeMatrix},
ReturnType: ValueTypeVector,
},
"tan": {
Name: "tan",
ArgTypes: []ValueType{ValueTypeVector},
ReturnType: ValueTypeVector,
},
"time": {
Name: "time",
ArgTypes: []ValueType{},