Scale/offset
This commit is contained in:
@@ -74,78 +74,11 @@ func (ts TimeSeries) GroupBy(interval time.Duration, aggFunc AggFunc) TimeSeries
|
||||
return groupedSeries
|
||||
}
|
||||
|
||||
func AggAvg(points []TimePoint) *float64 {
|
||||
sum := AggSum(points)
|
||||
avg := *sum / float64(len(points))
|
||||
return &avg
|
||||
}
|
||||
|
||||
func AggSum(points []TimePoint) *float64 {
|
||||
var sum float64 = 0
|
||||
for _, p := range points {
|
||||
if p.Value != nil {
|
||||
sum += *p.Value
|
||||
}
|
||||
func (ts TimeSeries) Transform(transformFunc TransformFunc) TimeSeries {
|
||||
for i, p := range ts {
|
||||
ts[i] = transformFunc(p)
|
||||
}
|
||||
return &sum
|
||||
}
|
||||
|
||||
func AggMax(points []TimePoint) *float64 {
|
||||
var max *float64 = nil
|
||||
for _, p := range points {
|
||||
if p.Value != nil {
|
||||
if max == nil {
|
||||
max = p.Value
|
||||
} else if *p.Value > *max {
|
||||
max = p.Value
|
||||
}
|
||||
}
|
||||
}
|
||||
return max
|
||||
}
|
||||
|
||||
func AggMin(points []TimePoint) *float64 {
|
||||
var min *float64 = nil
|
||||
for _, p := range points {
|
||||
if p.Value != nil {
|
||||
if min == nil {
|
||||
min = p.Value
|
||||
} else if *p.Value < *min {
|
||||
min = p.Value
|
||||
}
|
||||
}
|
||||
}
|
||||
return min
|
||||
}
|
||||
|
||||
func AggCount(points []TimePoint) *float64 {
|
||||
count := float64(len(points))
|
||||
return &count
|
||||
}
|
||||
|
||||
func AggFirst(points []TimePoint) *float64 {
|
||||
return points[0].Value
|
||||
}
|
||||
|
||||
func AggLast(points []TimePoint) *float64 {
|
||||
return points[len(points)-1].Value
|
||||
}
|
||||
|
||||
func AggMedian(points []TimePoint) *float64 {
|
||||
values := make([]float64, 0)
|
||||
for _, p := range points {
|
||||
if p.Value != nil {
|
||||
values = append(values, *p.Value)
|
||||
}
|
||||
}
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
values = sort.Float64Slice(values)
|
||||
medianIndex := int(math.Floor(float64(len(values)) / 2))
|
||||
median := values[medianIndex]
|
||||
return &median
|
||||
return ts
|
||||
}
|
||||
|
||||
// Aligns point's time stamps according to provided interval.
|
||||
|
||||
Reference in New Issue
Block a user