Codebase list golang-github-vbauerster-mpb / 8272499
a bit accurate ETA Vladimir Bauer 8 years ago
1 changed file(s) with 9 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
5656 etaAlpha float64
5757 total int64
5858 current int64
59 lastIncrement int64
5960 totalAutoIncrTrigger int64
6061 totalAutoIncrBy int64
6162 trimLeftSpace bool
249250 case b.operateState <- func(s *bState) {
250251 if s.current == 0 {
251252 s.startTime = now
252 s.blockStartTime = now
253253 } else {
254 s.updateETA(int64(n), now)
254 s.updateETA(now.Sub(s.blockStartTime))
255255 s.timeElapsed = now.Sub(s.startTime)
256256 }
257 s.current += int64(n)
257 s.blockStartTime = now
258 s.lastIncrement = int64(n)
259 s.current += s.lastIncrement
258260 if s.dynamic {
259261 curp := decor.CalcPercentage(s.total, s.current, 100)
260262 if 100-curp <= s.totalAutoIncrTrigger {
290292 s.toComplete = true
291293 cancel = nil
292294 case <-b.shutdown:
295 s.updateETA(time.Since(s.blockStartTime))
293296 b.cacheState = s
294297 close(b.done)
295298 return
425428 }
426429 }
427430
428 func (s *bState) updateETA(amount int64, now time.Time) {
429 lastBlockTime := now.Sub(s.blockStartTime)
430 lastItemEstimate := float64(lastBlockTime) / float64(amount)
431 func (s *bState) updateETA(lastBlockTime time.Duration) {
432 lastItemEstimate := float64(lastBlockTime) / float64(s.lastIncrement)
431433 s.timePerItemEstimate = time.Duration((s.etaAlpha * lastItemEstimate) + (1-s.etaAlpha)*float64(s.timePerItemEstimate))
432 s.timeRemaining = time.Duration(s.total-s.current+amount) * s.timePerItemEstimate
433 s.blockStartTime = now
434 s.timeRemaining = time.Duration(s.total-s.current) * s.timePerItemEstimate
434435 }
435436
436437 func newStatistics(s *bState) *decor.Statistics {