Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AdaptiveTransferSpeed is not adaptive #122

Closed
tobiasmaier opened this issue Jun 2, 2017 · 9 comments
Closed

AdaptiveTransferSpeed is not adaptive #122

tobiasmaier opened this issue Jun 2, 2017 · 9 comments

Comments

@tobiasmaier
Copy link

Description

AdaptiveTransferSpeed shows the same values as TransferSpeed, it does not calculate the values over the last X samples.

The example code below shows when finished:

100% ETA: Time: 0:00:15 Adaptive ETA: Time: 0:00:15 Absolute ETA: Finished at: 0:00:15 Transfer Speed: 33.3 B/s Adaptive Transfer Speed: 33.3 B/s ||

the expected Adaptive Transfer Speed with sleep(0.1) for the last 100 iterations would be 10.0 B/s

The reason is FileTransferSpeed is used to print Adaptive Transfer Speed but calculated and passed parameters value and total_seconds_elapsed are ignored because the keys exist in data.

value = data['value'] or value
elapsed = data['total_seconds_elapsed'] or total_seconds_elapsed

Proposed Fix

Change the code in FileTransferSpeed.__call__ to

value = value or data['value']
elapsed = total_seconds_elapsed or data['total_seconds_elapsed']

or to be have the same code as in ETA.__call__ to:

if value is None:
    value = data['value']
if elapsed is None:
    elapsed = data['total_seconds_elapsed']

Code

Copied from examples and added FileTransferSpeed widget

import progressbar
from time import sleep

widgets = [
    progressbar.Percentage(),
    ' ETA: ', progressbar.ETA(),
    ' Adaptive ETA: ', progressbar.AdaptiveETA(),
    ' Absolute ETA: ', progressbar.AbsoluteETA(),
    ' Transfer Speed: ', progressbar.FileTransferSpeed(),
    ' Adaptive Transfer Speed: ', progressbar.AdaptiveTransferSpeed(),
    ' ', progressbar.Bar(),
]
bar = progressbar.ProgressBar(widgets=widgets, max_value=500)
bar.start()
for i in range(500):
    if i < 100:
        sleep(0.02)
    elif i > 400:
        sleep(0.1)
    else:
        sleep(0.01)
    bar.update(i + 1)
bar.finish()

Versions

  • Python version: 3.5.2 (default, Nov 17 2016, 17:05:23) [GCC 5.4.0 20160609]
  • Python distribution/environment: CPython
  • Operating System: Ubuntu Linux
  • Package version: 3.20.0 / git
@wolph wolph closed this as completed in 815eb20 Jun 2, 2017
@wolph
Copy link
Owner

wolph commented Jun 2, 2017

Thanks for the extensive bug report and the fix! It seems to work great, I'll try to get a new release out within a few days

@wolph
Copy link
Owner

wolph commented Jun 2, 2017

And the new release is online :)

You can try 3.30.2

@tobiasmaier
Copy link
Author

Something seems to have gone wrong with the pull request (#123) that fixes this issue. The change is not visible in master or develop.

wolph added a commit that referenced this issue Jul 22, 2017
wolph added a commit that referenced this issue Jul 22, 2017
@martinprikryl
Copy link

I also came to report the same bug and the same fix.
I'm happy to see it fixed already.
But unfortunately I still do not see the fix in master nor develop.
https://github.com/WoLpH/python-progressbar/blob/develop/progressbar/widgets.py#L479
https://github.com/WoLpH/python-progressbar/blob/master/progressbar/widgets.py#L471

@wolph wolph reopened this Sep 17, 2019
@wolph
Copy link
Owner

wolph commented Sep 17, 2019

This issue has been fixed before but apparently it's broken again somehow. For some reason the previously added tests didn't cover this so I'll add more tests to make sure it won't happen again.

It seems like #207 is a duplicate of this. I'll get it working again as soon as possible :)

@wolph
Copy link
Owner

wolph commented Sep 17, 2019

@martinprikryl did you run into the issue of #207 as well or is it broken for you in a different case?

When I run python examples.py eta_types_demonstration it appears to be running correctly but I might be missing something :)

@martinprikryl
Copy link

martinprikryl commented Sep 17, 2019

No, I do not get that problem. For me all widgets work. It's just that AdaptiveTransferSpeed displays the same value as FileTransferSpeed due to the bug described above by @tobiasmaier.

If I apply his fix to the module, everything works as I need.

@wolph
Copy link
Owner

wolph commented Sep 17, 2019

I could swear I've re-added this code before... either way, it's back again :)

Now the hard part... creating a test for this case ;)

@wolph wolph closed this as completed in fa5206c Sep 17, 2019
@wolph
Copy link
Owner

wolph commented Sep 18, 2019

I've finally been able to write a test that consistently works across all testing platforms so I'll create a new release now :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants