cc-metric-store/pkg/resampler/util.go

36 lines
656 B
Go
Raw Normal View History

2024-08-21 09:47:16 +02:00
package resampler
import (
"math"
"github.com/ClusterCockpit/cc-metric-store/internal/util"
)
func calculateTriangleArea(paX, paY, pbX, pbY, pcX, pcY util.Float) float64 {
area := ((paX-pcX)*(pbY-paY) - (paX-pbX)*(pcY-paY)) * 0.5
return math.Abs(float64(area))
}
func calculateAverageDataPoint(points []util.Float, xStart int64) (avgX util.Float, avgY util.Float) {
2024-08-25 16:12:43 +02:00
flag := 0
2024-08-21 09:47:16 +02:00
for _, point := range points {
avgX += util.Float(xStart)
avgY += point
xStart++
2024-08-25 16:12:43 +02:00
if math.IsNaN(float64(point)) {
flag = 1
}
2024-08-21 09:47:16 +02:00
}
2024-08-25 16:12:43 +02:00
2024-08-21 09:47:16 +02:00
l := util.Float(len(points))
2024-08-25 16:12:43 +02:00
2024-08-21 09:47:16 +02:00
avgX /= l
avgY /= l
2024-08-25 16:12:43 +02:00
if flag == 1 {
return avgX, util.NaN
} else {
return avgX, avgY
}
2024-08-21 09:47:16 +02:00
}