Use existing Mean and Variance functions

Available in github.com/montanaflynn/stats
This commit is contained in:
Akash Kothawale 2018-02-03 19:37:30 -05:00 committed by Pradyumna Kaushik
parent 46be28ef8d
commit 39d1cf980c
2 changed files with 5 additions and 21 deletions

View file

@ -10,6 +10,7 @@ import (
"os/exec"
"syscall"
"time"
"github.com/montanaflynn/stats"
)
func Start(quit chan struct{}, logging *bool, logMType chan elecLogDef.LogMessageType, logMsg chan string, s scheduler.Scheduler) {
@ -65,10 +66,10 @@ func Start(quit chan struct{}, logging *bool, logMType chan elecLogDef.LogMessag
}
}
cpuVariance := calcVariance(cpuUtils)
cpuTaskSharesVariance := calcVariance(cpuTaskShares)
memVariance := calcVariance(memUtils)
memTaskSharesVariance := calcVariance(memTaskShares)
cpuVariance, _ := stats.Variance(cpuUtils)
cpuTaskSharesVariance, _ := stats.Variance(cpuTaskShares)
memVariance, _ := stats.Variance(memUtils)
memTaskSharesVariance, _ := stats.Variance(memTaskShares)
logMType <- elecLogDef.DEG_COL
logMsg <- fmt.Sprintf("%f, %f, %f, %f", cpuVariance, cpuTaskSharesVariance, memVariance, memTaskSharesVariance)

View file

@ -59,23 +59,6 @@ func sumAndNormalize(tokenSlice []string, normalizer float64) float64 {
return sum / normalizer
}
func calcMean(a []float64) float64 {
total := 0.0
for _, v := range a {
total += v
}
return total / float64(len(a))
}
func calcVariance(a []float64) float64 {
mean := calcMean(a)
total := 0.0
for _, v := range a {
total += math.Pow(mean-v, 2)
}
return total / float64(len(a))
}
func utilization(used string, free string) float64 {
u, _ := strconv.ParseFloat(used, 64)
f, _ := strconv.ParseFloat(free, 64)