This repository has been archived by the owner on Aug 23, 2023. It is now read-only.
/
func_removeabovebelowvalue.go
71 lines (58 loc) · 1.41 KB
/
func_removeabovebelowvalue.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package expr
import (
"fmt"
"math"
"github.com/grafana/metrictank/schema"
"github.com/grafana/metrictank/api/models"
)
type FuncRemoveAboveBelowValue struct {
in GraphiteFunc
n float64
above bool
}
func NewRemoveAboveBelowValueConstructor(above bool) func() GraphiteFunc {
return func() GraphiteFunc {
return &FuncRemoveAboveBelowValue{above: above}
}
}
func (s *FuncRemoveAboveBelowValue) Signature() ([]Arg, []Arg) {
return []Arg{
ArgSeriesList{val: &s.in},
ArgFloat{key: "n", val: &s.n},
}, []Arg{ArgSeriesList{}}
}
func (s *FuncRemoveAboveBelowValue) Context(context Context) Context {
return context
}
func (s *FuncRemoveAboveBelowValue) Exec(dataMap DataMap) ([]models.Series, error) {
series, err := s.in.Exec(dataMap)
if err != nil {
return nil, err
}
var output []models.Series
for _, serie := range series {
if s.above {
serie.Target = fmt.Sprintf("removeAboveValue(%s, %g)", serie.Target, s.n)
} else {
serie.Target = fmt.Sprintf("removeBelowValue(%s, %g)", serie.Target, s.n)
}
serie.QueryPatt = serie.Target
out := pointSlicePool.Get().([]schema.Point)
for _, p := range serie.Datapoints {
if s.above {
if p.Val > s.n {
p.Val = math.NaN()
}
} else {
if p.Val < s.n {
p.Val = math.NaN()
}
}
out = append(out, p)
}
serie.Datapoints = out
output = append(output, serie)
}
dataMap.Add(Req{}, output...)
return output, nil
}