rsalmei / alive-progress

A new kind of Progress Bar, with real-time throughput, ETA, and very cool animations!
MIT License
5.53k stars 206 forks source link

directly viz percentage to bar #14

Closed siddht4 closed 4 years ago

siddht4 commented 5 years ago

I liked your viz project for progress bar. But I am confused as your examples show int iteration to progress bar using a dummy data.

I would like to know that how i can directly provide percentage to progress bar as it generates the bar for me.

example

` a='0%'

percentage 0 to 100 %

a= '100%' now howashould be passed toalive_bar `

rsalmei commented 5 years ago

Hello @siddht4!

I'm not sure I got your doubt, but I assume you meant manual mode. That is the mode you can control the bar whatever you want.

To use it, just do:

from alive_progress import alive_bar
import time

with alive_bar(500, manual=1) as bar: 
    for i in range(500): 
        time.sleep(.01) # process 
        bar((i+1)/500.) 

Note the bar call. This is the place you send your percentage. The format is a float number between 0 and 1. For example to send 15%, you would send 0.15 which is 15 / 100. as I did in the example code. The general rule is position / total.

Was that your doubt?

siddht4 commented 5 years ago

@rsalmei Thank you for mentioning the above.

Can you add this to your readme/usage guide. (its partially explained,so can you also elaborate in your readme for the usage of manual mode there.

Was that your doubt?

I am obtaining the percentage through an api so I wanted to use that directly .

Looks like there is no direct usage . Can you add this mode i.e to directly provide percentage to bar

example : As how now i understand

perc_str='80.01%' #where perc_str is percentage in string format like 80.01% bar(perc_str)

rogerio-geru commented 4 years ago

No problem @siddht4

You're right, there isn't direct support the way you have. But I can't in the bar try to interpret any of infinite input formats. You should convert it to a float number before.

Using your example, you would do:

perc_str='80.01%' #where perc_str is percentage in string format like 80.01%

bar(float(perc_str[:-1]))
rsalmei commented 4 years ago

Hey @siddht4,

I've updated the documentation about the float argument, hope it is clearer now.