diff --git a/progress.go b/progress.go index cf1c25a..077323b 100644 --- a/progress.go +++ b/progress.go @@ -200,41 +200,43 @@ func (p *Progress) Reset() { } func (p *Progress) speedStatus(s *Status) { - if p.IncrementalSpeed { - lc := s.LinesCompleted - p.prevStatus.LinesCompleted - bc := s.BytesCompleted - p.prevStatus.BytesCompleted - dc := s.DonePercent - p.prevStatus.DonePercent - ela := s.Elapsed - p.prevStatus.Elapsed - - if lc > 0 { - s.SpeedLPS = float64(lc) / ela.Seconds() - } - - if bc > 0 { - s.SpeedMBPS = (float64(bc) / ela.Seconds()) / (1024 * 1024) - } + if !p.IncrementalSpeed { + s.SpeedMBPS = (float64(s.BytesCompleted) / s.Elapsed.Seconds()) / (1024 * 1024) + s.SpeedLPS = float64(s.LinesCompleted) / s.Elapsed.Seconds() if s.DonePercent > 0 { - s.Remaining = time.Duration((100.0 - s.DonePercent) * float64(ela) / dc) + s.Remaining = time.Duration(float64(100*s.Elapsed)/s.DonePercent) - s.Elapsed s.Remaining = s.Remaining.Truncate(time.Second) } else { s.Remaining = 0 } - p.prevStatus = *s - return } - s.SpeedMBPS = (float64(s.BytesCompleted) / s.Elapsed.Seconds()) / (1024 * 1024) - s.SpeedLPS = float64(s.LinesCompleted) / s.Elapsed.Seconds() + lc := s.LinesCompleted - p.prevStatus.LinesCompleted + bc := s.BytesCompleted - p.prevStatus.BytesCompleted + dc := s.DonePercent - p.prevStatus.DonePercent + ela := s.Elapsed - p.prevStatus.Elapsed - if s.DonePercent > 0 { - s.Remaining = time.Duration(float64(100*s.Elapsed)/s.DonePercent) - s.Elapsed + if ela != 0 { + if lc > 0 { + s.SpeedLPS = float64(lc) / ela.Seconds() + } + + if bc > 0 { + s.SpeedMBPS = (float64(bc) / ela.Seconds()) / (1024 * 1024) + } + } + + if dc > 0 { + s.Remaining = time.Duration((100.0 - s.DonePercent) * float64(ela) / dc) s.Remaining = s.Remaining.Truncate(time.Second) } else { s.Remaining = 0 } + + p.prevStatus = *s } func (p *Progress) printStatus(last bool) {