eta update
Vladimir Bauer
8 years ago
| 64 | 64 |
dynamic bool
|
| 65 | 65 |
noBarOnComplete bool
|
| 66 | 66 |
startTime time.Time
|
|
67 |
blockStartTime time.Time
|
| 67 | 68 |
timeElapsed time.Duration
|
| 68 | |
blockStartTime time.Time
|
| 69 | |
timePerItem time.Duration
|
|
69 |
timePerItemEstimate time.Duration
|
|
70 |
timeRemaining time.Duration
|
| 70 | 71 |
aDecorators []decor.DecoratorFunc
|
| 71 | 72 |
pDecorators []decor.DecoratorFunc
|
| 72 | 73 |
refill *refill
|
|
| 248 | 249 |
s.startTime = now
|
| 249 | 250 |
s.blockStartTime = now
|
| 250 | 251 |
} else {
|
| 251 | |
s.updateTimePerItemEstimate(n, now)
|
|
252 |
s.updateETA(int64(n), now)
|
| 252 | 253 |
s.timeElapsed = now.Sub(s.startTime)
|
| 253 | 254 |
}
|
| 254 | 255 |
s.current += int64(n)
|
|
| 422 | 423 |
}
|
| 423 | 424 |
}
|
| 424 | 425 |
|
| 425 | |
func (s *bState) updateTimePerItemEstimate(amount int, now time.Time) {
|
|
426 |
func (s *bState) updateETA(amount int64, now time.Time) {
|
| 426 | 427 |
lastBlockTime := now.Sub(s.blockStartTime)
|
| 427 | 428 |
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
|
| 429 | 431 |
s.blockStartTime = now
|
| 430 | 432 |
}
|
| 431 | 433 |
|
|
| 437 | 439 |
Current: s.current,
|
| 438 | 440 |
StartTime: s.startTime,
|
| 439 | 441 |
TimeElapsed: s.timeElapsed,
|
| 440 | |
TimePerItemEstimate: s.timePerItem,
|
|
442 |
TimeRemaining: s.timeRemaining,
|
|
443 |
TimePerItemEstimate: s.timePerItemEstimate,
|
| 441 | 444 |
}
|
| 442 | 445 |
}
|
| 443 | 446 |
|
| 37 | 37 |
Current int64
|
| 38 | 38 |
StartTime time.Time
|
| 39 | 39 |
TimeElapsed time.Duration
|
|
40 |
TimeRemaining time.Duration
|
| 40 | 41 |
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
|
| 46 | 42 |
}
|
| 47 | 43 |
|
| 48 | 44 |
// DecoratorFunc is a function that can be prepended and appended to the progress bar
|
|
| 188 | 184 |
}
|
| 189 | 185 |
format += "%ds"
|
| 190 | 186 |
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)
|
| 192 | 188 |
if (conf & DwidthSync) != 0 {
|
| 193 | 189 |
widthAccumulator <- utf8.RuneCountInString(str)
|
| 194 | 190 |
max := <-widthDistributor
|