mirror of
https://github.com/Luzifer/mondash.git
synced 2024-11-09 16:10:01 +00:00
Knut Ahlers
f3c31476b4
* Update dependencies * Improve code quality * Apply linter advices * Add gzip compression to all requests * Rework frontend * Apply bootswatch theme * Hide historic details when not requested * Remove debugging header * Apply auto-migration of meta fields * Fix broken "last update" time * Pre-sort metrics for frontend / API * Add tooltip with absolute time * Some design fixes * Add tooltip with absolute date to last ok * Implement filters * Apply eslint --fix * Remove unused var * Remove remains of old template engine * Update baked in assets * Update Dockerfile for new version Signed-off-by: Knut Ahlers <knut@ahlers.me>
33 lines
539 B
Go
33 lines
539 B
Go
package main
|
|
|
|
import (
|
|
"math"
|
|
"sort"
|
|
)
|
|
|
|
func absoluteDeviation(values []float64) []float64 {
|
|
medianValue := median(values)
|
|
|
|
deviation := make([]float64, len(values))
|
|
|
|
for i := range values {
|
|
deviation[i] = math.Abs(values[i] - medianValue)
|
|
}
|
|
|
|
return deviation
|
|
}
|
|
|
|
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]
|
|
}
|
|
|
|
return values[len(values)/2-1]
|
|
}
|