-
Notifications
You must be signed in to change notification settings - Fork 4
/
histogram_sets_transform.go
67 lines (63 loc) · 1.51 KB
/
histogram_sets_transform.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
package histogram
var funcStringTransformNoop = func(s string) string { return s }
func (hsets *HistogramSets) FilterHsetNames(inFunc, exFunc func(name string) bool) *HistogramSets {
out := NewHistogramSets(hsets.Name)
for hsetName, hset := range hsets.HistogramSetMap {
if (exFunc != nil && exFunc(hsetName)) ||
inFunc == nil ||
!inFunc(hsetName) {
continue
}
for histName, hist := range hset.HistogramMap {
for binName, binSum := range hist.Bins {
out.Add(
hsetName,
histName,
binName,
binSum,
false,
)
}
}
}
return out
}
func (hsets *HistogramSets) TransformBinNamesMap(xfBinNames map[string]string) *HistogramSets {
return hsets.TransformNames(
nil,
nil,
func(name string) string {
if newName, ok := xfBinNames[name]; ok {
return newName
} else {
return name
}
},
)
}
func (hsets *HistogramSets) TransformNames(xfHsetName, xfFuncHistName, xfFuncBinName func(name string) string) *HistogramSets {
out := NewHistogramSets(hsets.Name)
if xfHsetName == nil {
xfHsetName = funcStringTransformNoop
}
if xfFuncHistName == nil {
xfFuncHistName = funcStringTransformNoop
}
if xfFuncBinName == nil {
xfFuncBinName = funcStringTransformNoop
}
for hsetName, hset := range hsets.HistogramSetMap {
for histName, hist := range hset.HistogramMap {
for binName, binSum := range hist.Bins {
out.Add(
xfHsetName(hsetName),
xfFuncHistName(histName),
xfFuncBinName(binName),
binSum,
false,
)
}
}
}
return out
}