ethanfu / python-progressbar

Automatically exported from code.google.com/p/python-progressbar
Other
0 stars 0 forks source link

Display both the current file number and the transfer speed #8

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Set maxval to the total number of bytes being downloaded
2. Set up the FileTransferSpeed widget
3. Set up the SimpleProgress widget to display the number of the current file 
being downloaded

What is the expected output? What do you see instead?
I wanted to have this sort of output:
Downloading file 7 of 535 100% |||||||||||||| Time: 00:00:41  1.95 MB/s

But I can only get this sort of output:
Downloading file 7 of 10979307 100% ||||||||| Time: 00:00:41  1.95 MB/s

What version of the product are you using? On what operating system?
OS: Tested on both Windows 7 and Ubuntu Linux 10.04 LTS
ProgressBar Version: progressbar-2.3-dev

Please provide any additional information below.
N/A

Original issue reported on code.google.com by lpq...@gmail.com on 28 Dec 2010 at 11:36

GoogleCodeExporter commented 9 years ago
I don't know if this is technically a "defect". The problem you are detailing 
is to provide two different metrics:

1. File progress
2. Transfer progress

Right now the ProgressBar will show only one of the two metrics.

To solve you could do the following: Build a widget yourself which knew the 
lengths of each of the files. With this information the widget could determine 
which file was currently being downloaded.

On our end we could possibly build a composite ProgressBar which would be able 
to show multiple metrics. Since this is not really a priority at the time I 
would suggest my first alternative.

For people visiting this issue here is a quick example of how I might solve the 
problem:

class MultipartWidget(progressbar.widgets.Widget):
  format = '%d of %d'

  def __init__(self, bounds):
    self.bounds = bounds
    self.current = 0

  def update(self, pbar):
    if pbar.finished:
      self.current = len(self.bounds) - 1
    elif pbar.currval >= self.bounds[self.current]:
      self.current += 1

    return self.format % (self.current + 1, len(self.bounds))

# Usage:
#   file1.size() == 10 bytes
#   file2.size() == 10 bytes
#   file3.size() == 15 bytes
#   file4.size() == 65 bytes
#
# (you could have __init__ sum everything up for you,
#  but I'm just giving a very quick example)
>>> MultipartWidget([10, 20, 35, 100])

Original comment by Terence....@gmail.com on 16 May 2011 at 3:56