Codebase list golang-github-vbauerster-mpb / 4e5a7b1
eta method on Statistics Vladimir Bauer 9 years ago
1 changed file(s) with 6 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
4848 type Statistics struct {
4949 Total, Completed int
5050 TimePerItemEstimate time.Duration
51 }
52
53 func (s *Statistics) eta() time.Duration {
54 return time.Duration(s.Total-s.Completed) * s.TimePerItemEstimate
5155 }
5256
5357 // type redrawRequest struct {
182186 func (b *Bar) PrependETA(padding int) *Bar {
183187 layout := "ETA%" + strconv.Itoa(padding) + "s"
184188 b.PrependFunc(func(s *Statistics) string {
185 eta := time.Duration(s.Total-s.Completed) * s.TimePerItemEstimate
186 return fmt.Sprintf(layout, time.Duration(eta.Seconds())*time.Second)
189 return fmt.Sprintf(layout, time.Duration(s.eta().Seconds())*time.Second)
187190 })
188191 return b
189192 }
190193
191194 func (b *Bar) AppendETA() *Bar {
192195 b.AppendFunc(func(s *Statistics) string {
193 eta := time.Duration(s.Total-s.Completed) * s.TimePerItemEstimate
194 return fmt.Sprintf("ETA %v", time.Duration(eta.Seconds())*time.Second)
196 return fmt.Sprintf("ETA %s", time.Duration(s.eta().Seconds())*time.Second)
195197 })
196198 return b
197199 }