<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Sebastian Raschka
Step1:  PyPrind demo
<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
Controlling the update frequency
<br>
<br>
Step2:  <a name='bar_basic'></a>
<br>
<br>
Basic Progress Bar
[back to section overview]
Using a for-loop
Step3:  In a while-loop
Step4:  <a name='percent_basic'></a>
<br>
<br>
Basic Percentage Indicator
[back to section overview]
Note
Step5:  <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.
Step6:  <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.
Step7:  <a name='percent_cpu'></a>
<br>
<br>
Progress Bar/Percentage Indicator - Reporting CPU and memory usage
[back to section overview]
monitor (bool)
Step8:  <a name='percent_cpu'></a>
Step9:  <a name='title'></a>
<br>
<br>
Progress Bar/Percentage Indicator - Setting a title
[back to section overview]
title (str)
Step10:  <a name='width'></a>
<br>
<br>
Progress Bar - Changing the default width
[back to section overview]
width (int)
Step11:  <a name='streams'></a>
<br>
<br>
Progress Bar/Percentage Indicator - Changing the output stream
[back to section overview]
stream (int)
Step12:  <br>
<br>
Stopping the Progress Bar/Percentage Indicator early
[back to section overview]
The tracking object can be stopped early via the .stop() method
Step13:  <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.
Step14:  <br>
<br>
Choosing your own progress bar style
[back to section overview]
Step15:  <br>
<br>
Controlling the update frequency
[back to section overview]
Update the progress in after iteration of the loop via the force_flush parameter.
Step16:  <br>
Update the progress every 4 seconds using the update_interval parameter.
<ASSISTANT_TASK:>
Python Code:
%load_ext watermark
%watermark -v -d -u -p pyprind
Explanation: Sebastian Raschka
End of explanation
import pyprind
Explanation: PyPrind demo
<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
Controlling the update frequency
<br>
<br>
End of explanation
import time
n = 100
timesleep = 0.05
bar = pyprind.ProgBar(n)
for i in range(n):
    time.sleep(timesleep) # your computation here
    bar.update()
Explanation: <a name='bar_basic'></a>
<br>
<br>
Basic Progress Bar
[back to section overview]
Using a for-loop
End of explanation
import random
random.seed(1)
collection = set()
n = 100
bar = pyprind.ProgBar(n, track_time=False, title='while example')
while len(collection) < n:
    r = random.randint(0, 10**5)
    if r % 7 and r not in collection:
        collection.add(r)
        bar.update()
        time.sleep(timesleep)
print(bar)
Explanation: In a while-loop
End of explanation
perc = pyprind.ProgPercent(n)
for i in range(n):
    time.sleep(timesleep) # your computation here
    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)):
    time.sleep(timesleep) # your computation here
for i in pyprind.prog_percent(range(n)):
    time.sleep(timesleep) # your computation here
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
bar = pyprind.ProgBar(n)
for i in range(n):
    time.sleep(timesleep) # your computation here
    bar.update()
print(bar)
bar = pyprind.ProgBar(n, monitor=True, title='Job_1')
for i in range(n):
    time.sleep(timesleep) # your computation here
    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
bar = pyprind.ProgBar(n, monitor=True)
for i in range(n):
    time.sleep(timesleep) # your computation here
    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
perc = pyprind.ProgPercent(n, monitor=True)
for i in range(n):
    time.sleep(timesleep) # your computation here
    perc.update()
print(perc)
Explanation: <a name='percent_cpu'></a>
End of explanation
bar = pyprind.ProgBar(n, title='My 1st Progress Bar')
for i in range(n):
    time.sleep(timesleep) # your computation here
    bar.update()
perc = pyprind.ProgPercent(n, title='My 1st Percent Tracker')
for i in range(n):
    time.sleep(timesleep) # your computation here
    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
bar = pyprind.ProgBar(n, width=10)
for i in range(n):
    time.sleep(timesleep) # your computation here
    bar.update()
bar = pyprind.ProgBar(n, width=70)
for i in range(n):
    time.sleep(timesleep) # your computation here
    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
bar = pyprind.ProgBar(n, stream=1)
for i in range(n):
    time.sleep(timesleep) # your computation here
    bar.update()
bar = pyprind.ProgBar(n, stream=2)
for i in range(n):
    time.sleep(timesleep) # your computation here
    bar.update()
import sys
bar = pyprind.ProgBar(n, stream=sys.stdout)
for i in range(n):
    time.sleep(timesleep) # your computation here
    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
bar = pyprind.ProgBar(n)
for i in range(n):
    time.sleep(timesleep) # your computation here
    if i == 5:
        bar.stop()
        break
    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
items = ['file_%s.csv' %i for i in range(1,21)]
bar = pyprind.ProgBar(len(items))
for i in items:
    time.sleep(timesleep) # your computation here
    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
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
n = 100
bar = pyprind.ProgBar(n, bar_char='█')
for i in range(n):
    time.sleep(0.5) # do some computation
    bar.update(force_flush=True)
Explanation: <br>
<br>
Controlling the update frequency
[back to section overview]
Update the progress in after iteration of the loop via the force_flush parameter.
End of explanation
n = 100
bar = pyprind.ProgBar(n, bar_char='█', update_interval=4)
for i in range(n):
    time.sleep(0.2) # do some computation
    bar.update()
n = 100
bar = pyprind.ProgPercent(n, update_interval=4)
for i in range(n):
    time.sleep(0.2) # do some computation
    bar.update()
Explanation: <br>
Update the progress every 4 seconds using the update_interval parameter.
End of explanation
<END_TASK>