StdDev returns the standard deviation the message rates in the SampleGroup
()
| 227 | |
| 228 | // StdDev returns the standard deviation the message rates in the SampleGroup |
| 229 | func (sg *SampleGroup) StdDev() float64 { |
| 230 | if !sg.HasSamples() { |
| 231 | return 0 |
| 232 | } |
| 233 | avg := float64(sg.AvgRate()) |
| 234 | sum := float64(0) |
| 235 | for _, c := range sg.Samples { |
| 236 | sum += math.Pow(float64(c.Rate())-avg, 2) |
| 237 | } |
| 238 | variance := sum / float64(len(sg.Samples)) |
| 239 | return math.Sqrt(variance) |
| 240 | } |
| 241 | |
| 242 | // AddSample adds a Sample to the SampleGroup. After adding a Sample it shouldn't be modified. |
| 243 | func (sg *SampleGroup) AddSample(e *Sample) { |