pycharmers.utils.monitor_utils module¶
-
pycharmers.utils.monitor_utils.
progress_reporthook_create
(filename='', bar_width=20, verbose=True)[source]¶ Create Progress reporthook for
urllib.request.urlretrieve
- Returns
The
reporthook
which is a callable that accepts ablock number
, aread size
, and thetotal file size
of the URL target.- Parameters
filename (str) – Downloading filename.
bar_width (int) – The width of progress bar.
Examples
>>> import urllib >>> from pycharmers.utils import progress_reporthook_create >>> urllib.request.urlretrieve(url="hoge.zip", filename="hoge.zip", reporthook=progress_reporthook_create(filename="hoge.zip")) hoge.zip 1.5%[--------------------] 21.5[s] 8.0[GB/s] eta 1415.1[s]
-
class
pycharmers.utils.monitor_utils.
ProgressMonitor
(max_iter, verbose=1, barname='', **kwargs)[source]¶ Bases:
object
Monitor the loop progress.
-
max_iter
¶ Maximum number of iterations.
- Type
int
-
digit
¶ The number of digit of
max_iter
(=len(str(max_iter))
)- Type
int
-
verbose
¶ Determine the output method.
0
is silent,1
is progress bar and metrics, and2
is only progress bar.- Type
int
-
barname
¶ Barname.
- Type
str
-
histories
¶ The histories.
- Type
dict
-
iter
¶ The current number of iterations.
- Type
int
-
prev_length
¶ The number of characters in the previous output.
- Type
int
-
prev_nrows
¶ The number of rows in the previous output.
- Type
int
-
start_time
¶ current time in seconds since the Epoch. (
time.time()
)- Type
int
verbose
report
0
1
2
else
Examples
>>> from pycharmers.utils import ProgressMonitor >>> max_iter = 100 >>> monitor = ProgressMonitor(max_iter=max_iter, verbose=1, barname="NAME") >>> for it in range(max_iter): >>> monitor.report(it, loop=it+1) >>> monitor.remove() NAME 100/100[####################]100.00% - 0.010[s] loop: 100
-
write
(string)[source]¶ Use ASCI to output progress beautifully.
\033[0J
: Delete all strings after the cursor (including the following lines).\033[nF
: Moves the cursor upn
lines and then moves to the beginning of that line.
- Parameters
string – String to output.
Todo
Determine
nrows
according to the previous output result.
-