mirror of
https://github.com/Luzifer/mondash.git
synced 2024-12-23 04:21:18 +00:00
Fix a bug for a median of 1 value
This commit is contained in:
parent
525db95b08
commit
3f7e71c0c9
1 changed files with 7 additions and 0 deletions
|
@ -89,10 +89,17 @@ func newDashboardMetric() *dashboardMetric {
|
||||||
func median(values []float64) float64 {
|
func median(values []float64) float64 {
|
||||||
sort.Float64s(values)
|
sort.Float64s(values)
|
||||||
|
|
||||||
|
if len(values) == 1 {
|
||||||
|
return values[0]
|
||||||
|
}
|
||||||
|
|
||||||
// If even, take an average
|
// If even, take an average
|
||||||
if len(values)%2 == 0 {
|
if len(values)%2 == 0 {
|
||||||
return 0.5*values[len(values)/2] + 0.5*values[len(values)/2-1]
|
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]
|
return values[len(values)/2-1]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue