1
0
Fork 0
mirror of https://github.com/Luzifer/mondash.git synced 2024-11-09 16:10:01 +00:00

Fix a bug for a median of 1 value

This commit is contained in:
zainhoda 2015-02-22 21:20:14 -05:00
parent 525db95b08
commit 3f7e71c0c9

View file

@ -89,10 +89,17 @@ func newDashboardMetric() *dashboardMetric {
func median(values []float64) float64 {
sort.Float64s(values)
if len(values) == 1 {
return values[0]
}
// If even, take an average
if len(values)%2 == 0 {
return 0.5*values[len(values)/2] + 0.5*values[len(values)/2-1]
}
log.Printf("len(values)=%v, len(values)/2=%v\n", len(values), len(values)/2)
return values[len(values)/2-1]
}