send min/median connection score along with avg (#1720)

* send min/median connection score along with avg
* guard against divide by zero for avg score calculation
* update median calculation

Signed-off-by: shishir gowda <shishir@livekit.io>
This commit is contained in:
shishirng
2023-05-18 13:50:54 -04:00
committed by GitHub
parent 1d3faefc5e
commit 2e93d386fe
4 changed files with 72 additions and 31 deletions
+22
View File
@@ -0,0 +1,22 @@
package utils
import "sort"
// MedianFloat32 gets median value for an array of float32
func MedianFloat32(input []float32) float32 {
num := len(input)
if num == 0 {
return 0
} else if num == 1 {
return input[0]
}
sort.Slice(input, func(i, j int) bool {
return input[i] < input[j]
})
if num%2 != 0 {
return input[num/2]
}
left := input[num/2-1]
right := input[num/2]
return (left + right) / 2
}