Codebase list golang-github-vbauerster-mpb / a3e885c
default etaAlpha = 0.12 Vladimir Bauer 8 years ago
3 changed file(s) with 8 addition(s) and 11 deletion(s). Raw diff Collapse all Expand all
2121
2222 const (
2323 formatLen = 5
24 etaAlpha = 0.25
24 etaAlpha = 0.12
2525 )
2626
2727 type barRunes [formatLen]rune
255255 now := time.Now()
256256 select {
257257 case b.operateState <- func(s *bState) {
258 if s.current == 0 {
259 s.startTime = now
260 } else {
261 s.timeElapsed = now.Sub(s.startTime)
262 }
263258 s.current += int64(n)
264 s.updateETA(n, now.Sub(s.blockStartTime))
259 s.timeElapsed = now.Sub(s.startTime)
260 s.timeRemaining = s.calcETA(n, now.Sub(s.blockStartTime))
265261 if s.dynamic {
266262 curp := decor.CalcPercentage(s.total, s.current, 100)
267263 if 100-curp <= s.totalAutoIncrTrigger {
289285
290286 func (b *Bar) serve(wg *sync.WaitGroup, s *bState, cancel <-chan struct{}) {
291287 defer wg.Done()
288 s.startTime = time.Now()
289 s.blockStartTime = s.startTime
292290 for {
293291 select {
294292 case op := <-b.operateState:
432430 }
433431 }
434432
435 func (s *bState) updateETA(n int, lastBlockTime time.Duration) {
433 func (s *bState) calcETA(n int, lastBlockTime time.Duration) time.Duration {
436434 lastItemEstimate := float64(lastBlockTime) / float64(n)
437435 s.timePerItemEstimate = time.Duration((s.etaAlpha * lastItemEstimate) + (1-s.etaAlpha)*float64(s.timePerItemEstimate))
438 s.timeRemaining = time.Duration(s.total-s.current) * s.timePerItemEstimate
436 return time.Duration(s.total-s.current) * s.timePerItemEstimate
439437 }
440438
441439 func newStatistics(s *bState) *decor.Statistics {
5252
5353 // BarEtaAlpha option is a way to adjust ETA behavior.
5454 // You can play with it, if you're not satisfied with default behavior.
55 // Default value is 0.25.
55 // Default value is 0.12
5656 func BarEtaAlpha(a float64) BarOption {
5757 return func(s *bState) {
5858 s.etaAlpha = a
1414 }
1515
1616 func main() {
17
1817 var wg sync.WaitGroup
1918 p := mpb.New(mpb.WithWaitGroup(&wg))
2019 total := 100