github.com/go-graphite/carbonapi@v0.17.0/expr/functions/exp/function.go (about) 1 package exp 2 3 import ( 4 "context" 5 "math" 6 7 "github.com/go-graphite/carbonapi/expr/helper" 8 "github.com/go-graphite/carbonapi/expr/interfaces" 9 "github.com/go-graphite/carbonapi/expr/types" 10 "github.com/go-graphite/carbonapi/pkg/parser" 11 ) 12 13 type exp struct{} 14 15 // offset(seriesList,factor) 16 func GetOrder() interfaces.Order { 17 return interfaces.Any 18 } 19 20 func New(configFile string) []interfaces.FunctionMetadata { 21 res := make([]interfaces.FunctionMetadata, 0) 22 f := &exp{} 23 for _, n := range []string{"exp"} { 24 res = append(res, interfaces.FunctionMetadata{Name: n, F: f}) 25 } 26 return res 27 } 28 29 func (f *exp) Do(ctx context.Context, eval interfaces.Evaluator, e parser.Expr, from, until int64, values map[parser.MetricRequest][]*types.MetricData) ([]*types.MetricData, error) { 30 args, err := helper.GetSeriesArg(ctx, eval, e.Arg(0), from, until, values) 31 if err != nil { 32 return nil, err 33 } 34 var results []*types.MetricData 35 36 for _, a := range args { 37 r := a.CopyLink() 38 r.Name = "exp(" + a.Name + ")" 39 r.Values = make([]float64, len(a.Values)) 40 r.Tags["exp"] = "e" 41 42 for i, v := range a.Values { 43 if math.IsNaN(v) { 44 r.Values[i] = math.NaN() 45 } else { 46 r.Values[i] = math.Exp(v) 47 } 48 } 49 results = append(results, r) 50 } 51 return results, nil 52 } 53 54 // Description is auto-generated description, based on output of https://github.com/graphite-project/graphite-web 55 func (f *exp) Description() map[string]types.FunctionDescription { 56 return map[string]types.FunctionDescription{ 57 "exp": { 58 Description: "Raise e to the power of the datapoint, where e = 2.718281… is the base of natural logarithms.\n\nExample:\n\n.. code-block:: none\n\n &target=exp(Server.instance01.threads.busy)", 59 Function: "exp(seriesList)", 60 Group: "Transform", 61 Module: "graphite.render.functions", 62 Name: "exp", 63 Params: []types.FunctionParam{ 64 { 65 Name: "seriesList", 66 Required: true, 67 Type: types.SeriesList, 68 }, 69 }, 70 }, 71 } 72 }