/
transform_functions.go
58 lines (51 loc) · 1.21 KB
/
transform_functions.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
package timeseries
import "time"
func TransformScale(factor float64) TransformFunc {
return func(point TimePoint) TimePoint {
if point.Value != nil {
newValue := *point.Value * factor
point.Value = &newValue
}
return point
}
}
func TransformOffset(offset float64) TransformFunc {
return func(point TimePoint) TimePoint {
if point.Value != nil {
newValue := *point.Value + offset
point.Value = &newValue
}
return point
}
}
func TransformNull(nullValue float64) TransformFunc {
return func(point TimePoint) TimePoint {
if point.Value == nil {
point.Value = &nullValue
}
return point
}
}
func TransformRemoveAboveValue(threshold float64) TransformFunc {
return func(point TimePoint) TimePoint {
if point.Value != nil && *point.Value > threshold {
point.Value = nil
}
return point
}
}
func TransformRemoveBelowValue(threshold float64) TransformFunc {
return func(point TimePoint) TimePoint {
if point.Value != nil && *point.Value < threshold {
point.Value = nil
}
return point
}
}
func TransformShiftTime(interval time.Duration) TransformFunc {
return func(point TimePoint) TimePoint {
shiftedTime := point.Time.Add(interval)
point.Time = shiftedTime
return point
}
}