chausies
chausies

Reputation: 854

python-progressbar library - inverse FileTransferSpeed

I submitted an issue about this, but wanted to ask here for any workarounds/solutions.

For many slow-moving loops, the transfer speed would be something like .01 B/s or .00 B/s, which is highly uninformative. Is there a way you could show s/B for these cases? 175 s/B is much more descriptive and helpful. Do you have a workaround I could use for now? Because seeing .00 B/s doesn't tell me much about how fast I'm looping.

https://github.com/WoLpH/python-progressbar/issues/25

Upvotes: 1

Views: 111

Answers (1)

chausies
chausies

Reputation: 854

After searching through the code for progressbar and emulating the FileTransferSpeed class, here's a solution I came up with that you can plop in your code instead of FileTransferSpeed()

class InvFileTransferSpeed(Widget):
  'Widget for showing the transfer speed (useful for file transfers).'

  format = '%6.2f %ss/%s'
  prefixes = ' kMGTPEZY'
  __slots__ = ('unit', 'format')

  def __init__(self, unit='loop'):
    self.unit = unit

  def update(self, pbar):
    'Updates the widget with the current SI prefixed speed.'

    if pbar.seconds_elapsed < 2e-10 or pbar.currval < 2e-10: # =~ 0
      scaled = power = 0
    else:
      speed = pbar.seconds_elapsed / pbar.currval 
      power = int(math.log(speed, 1000))
      scaled = speed / 1000.**power

    return self.format % (scaled, self.prefixes[power], self.unit)

Note that this will use the units kiloseconds, megaseconds, etc. instead of minutes and days >.<.

Upvotes: 2

Related Questions