Rockhopper-Technologies / enlighten

Enlighten Progress Bar for Python Console Apps
https://python-enlighten.readthedocs.io
Mozilla Public License 2.0
421 stars 25 forks source link

Is there a way to print the inverted rate on the counter? #34

Closed triwahyuu closed 3 years ago

triwahyuu commented 4 years ago

I have a long lived process that never run 1s each iteration, so I wanted to display it as {1/rate} s/iteration, is there a way to get the inverted value of rate (1/rate)?

avylove commented 4 years ago

rate is calculated during formating, so there's no way to access it independently. I can look at adding a field for inverted rate. For now, you can calculate it and pass it as an argument.

import enlighten
import time

bar_format = u'{desc}{desc_pad} {percentage:3.0f}%|{bar}| ' + \
             u'{count:{len_total}d}/{total:d} ' + \
             u'[{elapsed}<{eta}, {seconds_per_file:.2f}{unit_pad}s/{unit}]'
manager = enlighten.get_manager(bar_format=bar_format)

bar = manager.counter(total=100, desc='Loading', unit='files', seconds_per_file=0)
bar.refresh()

for num in range(100):
    time.sleep(2.3)  # Simulate work
    seconds_per_file = bar.elapsed / (bar.count + 1)
    bar.update(seconds_per_file=seconds_per_file)
triwahyuu commented 4 years ago

will it be possible to add this feature by default? I find it quite useful

triwahyuu commented 4 years ago

anyway, thank you for the answer.

avylove commented 4 years ago

It seems useful enough and has a relatively low cost that I think we can add it as a built-in field. I'm leaning towards calling it "interval". There are some other changes I'm working on now, but I'll try to add it once those are done.

triwahyuu commented 4 years ago

thanks, really appreciate it.

avylove commented 3 years ago

Added in 1.7.0. Let me know if you have any issues.