Codebase list golang-github-vbauerster-mpb / beaaf66
eta update Vladimir Bauer 8 years ago
2 changed file(s) with 11 addition(s) and 12 deletion(s). Raw diff Collapse all Expand all
6464 dynamic bool
6565 noBarOnComplete bool
6666 startTime time.Time
67 blockStartTime time.Time
6768 timeElapsed time.Duration
68 blockStartTime time.Time
69 timePerItem time.Duration
69 timePerItemEstimate time.Duration
70 timeRemaining time.Duration
7071 aDecorators []decor.DecoratorFunc
7172 pDecorators []decor.DecoratorFunc
7273 refill *refill
248249 s.startTime = now
249250 s.blockStartTime = now
250251 } else {
251 s.updateTimePerItemEstimate(n, now)
252 s.updateETA(int64(n), now)
252253 s.timeElapsed = now.Sub(s.startTime)
253254 }
254255 s.current += int64(n)
422423 }
423424 }
424425
425 func (s *bState) updateTimePerItemEstimate(amount int, now time.Time) {
426 func (s *bState) updateETA(amount int64, now time.Time) {
426427 lastBlockTime := now.Sub(s.blockStartTime)
427428 lastItemEstimate := float64(lastBlockTime) / float64(amount)
428 s.timePerItem = time.Duration((s.etaAlpha * lastItemEstimate) + (1-s.etaAlpha)*float64(s.timePerItem))
429 s.timePerItemEstimate = time.Duration((s.etaAlpha * lastItemEstimate) + (1-s.etaAlpha)*float64(s.timePerItemEstimate))
430 s.timeRemaining = time.Duration(s.total-s.current+amount) * s.timePerItemEstimate
429431 s.blockStartTime = now
430432 }
431433
437439 Current: s.current,
438440 StartTime: s.startTime,
439441 TimeElapsed: s.timeElapsed,
440 TimePerItemEstimate: s.timePerItem,
442 TimeRemaining: s.timeRemaining,
443 TimePerItemEstimate: s.timePerItemEstimate,
441444 }
442445 }
443446
3737 Current int64
3838 StartTime time.Time
3939 TimeElapsed time.Duration
40 TimeRemaining time.Duration
4041 TimePerItemEstimate time.Duration
41 }
42
43 // Eta returns exponential-weighted-moving-average ETA estimator
44 func (s *Statistics) Eta() time.Duration {
45 return time.Duration(s.Total-s.Current) * s.TimePerItemEstimate
4642 }
4743
4844 // DecoratorFunc is a function that can be prepended and appended to the progress bar
188184 }
189185 format += "%ds"
190186 return func(s *Statistics, widthAccumulator chan<- int, widthDistributor <-chan int) string {
191 str := fmt.Sprint(time.Duration(s.Eta().Seconds()) * time.Second)
187 str := fmt.Sprint(time.Duration(s.TimeRemaining.Seconds()) * time.Second)
192188 if (conf & DwidthSync) != 0 {
193189 widthAccumulator <- utf8.RuneCountInString(str)
194190 max := <-widthDistributor