Codebase list golang-github-vbauerster-mpb / 53b4398
Don't add bad values to MovingAverage Vladimir Bauer 7 years ago
2 changed file(s) with 9 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
5959 }
6060
6161 v := internal.Round(d.average.Value())
62 if math.IsInf(v, 0) || math.IsNaN(v) {
63 v = 0
64 }
6562 remaining := d.normalizer(time.Duration((st.Total - st.Current) * int64(v)))
6663 hours := int64((remaining / time.Hour) % 60)
6764 minutes := int64((remaining / time.Minute) % 60)
8885 workDuration = wd
8986 }
9087 lastItemEstimate := float64(workDuration) / float64(n)
88 if math.IsInf(lastItemEstimate, 0) || math.IsNaN(lastItemEstimate) {
89 return
90 }
9191 d.average.Add(lastItemEstimate)
9292 }
9393
159159 var normalized time.Duration
160160 var lastCall time.Time
161161 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 {
163163 normalized = remaining
164164 lastCall = time.Now()
165165 return remaining
22 import (
33 "fmt"
44 "io"
5 "math"
56 "strconv"
67 "strings"
78 "time"
194195 for _, wd := range wdd {
195196 workDuration = wd
196197 }
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 }
198202 s.average.Add(speed)
199203 }
200204