From 22bbd2cf6718037523e46c9156465dfd45698aef Mon Sep 17 00:00:00 2001 From: Thomas Oettli Date: Sat, 30 Nov 2024 02:25:52 +0100 Subject: [PATCH] fix SummarizeValues average value --- pkg/expr/helper/helper.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/expr/helper/helper.go b/pkg/expr/helper/helper.go index 1bf12a44..d90c1ac1 100644 --- a/pkg/expr/helper/helper.go +++ b/pkg/expr/helper/helper.go @@ -201,12 +201,16 @@ func SummarizeValues(f string, values []float64, absent []bool) (float64, bool, rv += av } case "avg", "average": + total := 0 for i, av := range values { if !absent[i] { rv += av + total++ } } - rv /= float64(len(values)) + if total > 0 { + rv /= float64(total) + } case "max": rv = math.Inf(-1) for _, av := range values {