%load_ext watermark
%watermark -v -d -u

"""
Explanation: Sebastian Raschka
End of explanation
"""


import pyprind

"""
Explanation: PyPrind demo
<hr>
I would be happy to hear your comments and suggestions.
Please feel free to drop me a note via
twitter, email, or google+.
<hr>

<a name='sections'></a>
Sections

Basic Progress Bar  
Basic Percentage Indicator 
Progress Bar and Percentage Indicator generators
Progress Bar/Percentage Indicator - Reporting tracking information
Progress Bar/Percentage Indicator - Reporting CPU and memory usage  
Progress Bar/Percentage Indicator - Setting a title
Progress Bar - Changing the default width
Progress Bar/Percentage Indicator - Changing the output stream
Stopping the Progress Bar/Percentage Indicator early
Choosing your own progress bar style

<br>
<br>
End of explanation
"""


n = 150000

bar = pyprind.ProgBar(n)
for i in range(n):
    # do some computation
    bar.update()

"""
Explanation: <a name='bar_basic'></a>
<br>
<br>
Basic Progress Bar
[back to section overview]
End of explanation
"""


n = 1500

perc = pyprind.ProgPercent(n)
for i in range(n):
    # do some computation
    perc.update()

"""
Explanation: <a name='percent_basic'></a>
<br>
<br>
Basic Percentage Indicator
[back to section overview]
Note: the Percentage indicator is significantly slower due to background computation.
Thus, it is recommended for tasks with less iterations but longer computational time per iteration.
End of explanation
"""


for i in pyprind.prog_bar(range(n)):
    # do something
    pass

for i in pyprind.prog_percent(range(n)):
    # do something
    pass

"""
Explanation: <a name='percent_basic'></a>
<br>
<br>
Progress Bar and Percentage Indicator generators
[back to section overview]
Alternatively, you can use the progress bar and percentage indicators as generators.
End of explanation
"""


n = 150000

bar = pyprind.ProgBar(n)
for i in range(n):
    # do some computation
    bar.update()
print(bar)

n = 150000

bar = pyprind.ProgBar(n, monitor=True, title='Job_1')
for i in range(n):
    # do some computation
    bar.update()
    
# print report for future reference
print(bar)

"""
Explanation: <a name='info'></a>
<br>
<br>
Progress Bar/Percentage Indicator - Reporting tracking information
[back to section overview]
Simply print() the tracking object after the tracking has completed.
End of explanation
"""


n = 150000

bar = pyprind.ProgBar(n, monitor=True)
for i in range(n):
    # do some computation
    bar.update()
print(bar)

"""
Explanation: <a name='percent_cpu'></a>
<br>
<br>
Progress Bar/Percentage Indicator - Reporting CPU and memory usage
[back to section overview]
monitor (bool): default False. Monitors CPU and memory usage if True 
            (requires the psutil package).
End of explanation
"""


n = 1500

perc = pyprind.ProgPercent(n, monitor=True)
for i in range(n):
    # do some computation
    perc.update()
print(perc)

"""
Explanation: <a name='percent_cpu'></a>
End of explanation
"""


n = 150000

bar = pyprind.ProgBar(n, title='My 1st Progress Bar')
for i in range(n):
    # do some computation
    bar.update()

n = 1500

perc = pyprind.ProgPercent(n, title='My 1st Percent Tracker')
for i in range(n):
    # do some computation
    perc.update()

"""
Explanation: <a name='title'></a>
<br>
<br>
Progress Bar/Percentage Indicator - Setting a title
[back to section overview]
title (str): default ''. A title for the progress bar
End of explanation
"""


n = 150000

bar = pyprind.ProgBar(n, width=10)
for i in range(n):
    # do some computation
    bar.update()

bar = pyprind.ProgBar(n, width=70)
for i in range(n):
    # do some computation
    bar.update()

"""
Explanation: <a name='width'></a>
<br>
<br>
Progress Bar - Changing the default width
[back to section overview]
width (int): default 30. Sets the progress bar width in characters.
End of explanation
"""


n = 150000

bar = pyprind.ProgBar(n, stream=1)
for i in range(n):
    # do some computation
    bar.update()

bar = pyprind.ProgBar(n, stream=2)
for i in range(n):
    # do some computation
    bar.update()

import sys

bar = pyprind.ProgBar(n, stream=sys.stdout)
for i in range(n):
    # do some computation
    bar.update()

"""
Explanation: <a name='streams'></a>
<br>
<br>
Progress Bar/Percentage Indicator - Changing the output stream
[back to section overview]
stream (int): default 2. Takes 1 for stdout, 2 for stderr, or given stream object
End of explanation
"""


n = 150000

bar = pyprind.ProgBar(n)
for i in range(n):
    # do some computation
    if i == 10000:
        bar.stop()
    bar.update()

"""
Explanation: <br>
<br>
Stopping the Progress Bar/Percentage Indicator early
[back to section overview]
The tracking object can be stopped early via the .stop() method:
End of explanation
"""


import time

items = ['file_%s.csv' %i for i in range(1,21)]

bar = pyprind.ProgBar(len(items))
for i in items:
    time.sleep(0.5) # do some computation
    bar.update(item_id = i)

"""
Explanation: <br>
<br>
Progress Bar/Percentage Indicator - Printing currently processed items
[back to section overview]
Sometimes it is useful to print out the name of currently processed items, e.g., files are being processed. This can be done by providing a custom string for the optional item_id parameter of the .update() method.
End of explanation
"""


import sys
sys.path = ['/Users/sebastian/github/pyprind/'] + sys.path
import pyprind
import time

n = 100
bar = pyprind.ProgBar(n, bar_char='█')
for i in range(n):
    time.sleep(0.1) # do some computation
    bar.update()

"""
Explanation: <br>
<br>
Choosing your own progress bar style
[back to section overview]
End of explanation
"""


