Codebase list golang-github-vbauerster-mpb / cebd2ca
PrependETA Vladimir Bauer 9 years ago
1 changed file(s) with 18 addition(s) and 11 deletion(s). Raw diff Collapse all Expand all
105105 b.currentIncrCh <- n
106106 }
107107
108 func (b *Bar) PrependFunc(f DecoratorFunc) *Bar {
109 b.decoratorCh <- &decorator{decoratorPrepend, f}
110 return b
111 }
112
108113 func (b *Bar) AppendFunc(f DecoratorFunc) *Bar {
109114 b.decoratorCh <- &decorator{decoratorAppend, f}
115 return b
116 }
117
118 func (b *Bar) PrependETA() *Bar {
119 b.PrependFunc(func(s *Statistics) string {
120 eta := time.Duration(s.Total-s.Completed) * s.TimePerItemEstimate
121 return fmt.Sprintf("ETA %-5v", time.Duration(eta.Seconds())*time.Second)
122 })
110123 return b
111124 }
112125
180193 }
181194
182195 // render prepend functions to the left of the bar
183 // for _, f := range b.prependFuncs {
184 // args := []byte(f(b))
185 // args = append(args, ' ')
186 // pb = append(args, pb...)
187 // }
196 for _, f := range prependFuncs {
197 args := []byte(f(s))
198 args = append(args, ' ')
199 buf = append(args, buf...)
200 }
188201 return buf
189202 }
190203
193206 lastItemEstimate := float64(lastBlockTime) / float64(items)
194207 b.timePerItemEstimate = time.Duration((b.Alpha * lastItemEstimate) + (1-b.Alpha)*float64(b.timePerItemEstimate))
195208 }
196
197 // func nextTimePerItemEstimate(d time.Duration, blockStartTime time.Time, alpha float64, items int) time.Duration {
198 // lastBlockTime := time.Since(blockStartTime)
199 // lastItemEstimate := float64(lastBlockTime) / float64(items)
200 // return time.Duration((alpha * lastItemEstimate) + (1-alpha)*float64(d))
201 // }