Don't add bad values to MovingAverage
Vladimir Bauer
7 years ago
| 59 | 59 |
}
|
| 60 | 60 |
|
| 61 | 61 |
v := internal.Round(d.average.Value())
|
| 62 | |
if math.IsInf(v, 0) || math.IsNaN(v) {
|
| 63 | |
v = 0
|
| 64 | |
}
|
| 65 | 62 |
remaining := d.normalizer(time.Duration((st.Total - st.Current) * int64(v)))
|
| 66 | 63 |
hours := int64((remaining / time.Hour) % 60)
|
| 67 | 64 |
minutes := int64((remaining / time.Minute) % 60)
|
|
| 88 | 85 |
workDuration = wd
|
| 89 | 86 |
}
|
| 90 | 87 |
lastItemEstimate := float64(workDuration) / float64(n)
|
|
88 |
if math.IsInf(lastItemEstimate, 0) || math.IsNaN(lastItemEstimate) {
|
|
89 |
return
|
|
90 |
}
|
| 91 | 91 |
d.average.Add(lastItemEstimate)
|
| 92 | 92 |
}
|
| 93 | 93 |
|
|
| 159 | 159 |
var normalized time.Duration
|
| 160 | 160 |
var lastCall time.Time
|
| 161 | 161 |
return func(remaining time.Duration) time.Duration {
|
| 162 | |
if diff := normalized - remaining; diff <= 0 || diff >= maxTolerate || remaining <= maxTolerate {
|
|
162 |
if diff := normalized - remaining; diff <= 0 || diff > maxTolerate || remaining < maxTolerate/2 {
|
| 163 | 163 |
normalized = remaining
|
| 164 | 164 |
lastCall = time.Now()
|
| 165 | 165 |
return remaining
|
| 2 | 2 |
import (
|
| 3 | 3 |
"fmt"
|
| 4 | 4 |
"io"
|
|
5 |
"math"
|
| 5 | 6 |
"strconv"
|
| 6 | 7 |
"strings"
|
| 7 | 8 |
"time"
|
|
| 194 | 195 |
for _, wd := range wdd {
|
| 195 | 196 |
workDuration = wd
|
| 196 | 197 |
}
|
| 197 | |
speed := float64(n) / workDuration.Seconds()
|
|
198 |
speed := float64(n) / workDuration.Seconds() / 1000
|
|
199 |
if math.IsInf(speed, 0) || math.IsNaN(speed) {
|
|
200 |
return
|
|
201 |
}
|
| 198 | 202 |
s.average.Add(speed)
|
| 199 | 203 |
}
|
| 200 | 204 |
|