Compute standard deviation for ranges
This commit is contained in:
parent
249228c566
commit
2c645076c4
17
server.go
17
server.go
@ -32,6 +32,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/GaryBoone/GoStats/stats"
|
||||||
_ "github.com/go-sql-driver/mysql"
|
_ "github.com/go-sql-driver/mysql"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -90,13 +91,25 @@ func executeQuery(rw http.ResponseWriter, req *http.Request) {
|
|||||||
column.Hints = append(column.Hints, jsonHint)
|
column.Hints = append(column.Hints, jsonHint)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var d stats.Stats
|
||||||
for _, record := range foundEntries {
|
for _, record := range foundEntries {
|
||||||
if feature, ok := record.features[name]; ok {
|
if feature, ok := record.features[name]; ok {
|
||||||
column.Bracket.Max = math.Max(column.Bracket.Max, feature)
|
d.Update(feature)
|
||||||
column.Bracket.Min = math.Min(column.Bracket.Min, feature)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if d.Count() > 0 {
|
||||||
|
var dev float64
|
||||||
|
if d.Count() > 1 {
|
||||||
|
dev = d.SampleStandardDeviation() * 3
|
||||||
|
}
|
||||||
|
|
||||||
|
mean := d.Mean()
|
||||||
|
|
||||||
|
column.Bracket.Max = math.Min(mean+dev, d.Max())
|
||||||
|
column.Bracket.Min = math.Max(mean-dev, d.Min())
|
||||||
|
}
|
||||||
|
|
||||||
response.Columns[name] = column
|
response.Columns[name] = column
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user