pax_global_header 0000666 0000000 0000000 00000000064 13221734077 0014520 g ustar 00root root 0000000 0000000 52 comment=afbf10af519e50d73b212e304f9b14cd4a55a732
pyprind-2.11.1/ 0000775 0000000 0000000 00000000000 13221734077 0013267 5 ustar 00root root 0000000 0000000 pyprind-2.11.1/CHANGELOG.md 0000664 0000000 0000000 00000012752 13221734077 0015107 0 ustar 00root root 0000000 0000000
Version 2.11.1
================
- Flushes both `stdout` and `stderr` prior to `ProgressBar` initialization to avoid cluttering environments with previously cached print statements.
Version 2.11.0
================
- Use only 1 line to print the progress bar (instead of the previous too lines)
Version 2.10.0
================
- Fixes an issue with Jupyter Notebook 4.3.1 when the `ETA` got printed on new lines
Version 2.9.9
================
- added PyCharm support
Version 2.9.8
================
- raise `ValueError` if `monitor` is set to `True` and `psutils` is not installed
Version 2.9.7
================
- requirements.txt for `psutil`, now supports `pip install pyprind -r requirements.txt`
Version 2.9.5
================
- new `update_interval` parameter to control the update frequency in seconds
- new `force_flush` parameter to print the progress after every iteration
Version 2.9.4
================
- new time formatting in hh:mm:ss format (by Divyanshu Sharma, https://github.com/Div44)
- permissive new BSD license
VERSION 2.9.3
================
- some PEP8 adjustments and code cleanup
- new `bar` argument for ProgressBar to use
your favorite bar style (by Konstantin Tolstikhin)
VERSION 2.9.2
================
- support for psutil >= 2.0 and < 2.0.
- removed psutil from the setup requirements and made it's installation
optional via "pip install pyprind -r requirements.txt"
VERSION 2.9.1
================
- Minor reorganization of the generator interface.
- Minor changes to the code documentation.
- Added new test files.
VERSION 2.9.0
================
- New generator functions for progress bar and percentage indicators via:
for i in pyprind.prog_bar(range(n)):
# do something
pass
for i in pyprind.prog_percent(range(n)):
# do something
pass
(by Olaf Gladis, https://github.com/hwmrocker)
VERSION 2.8.0
================
- A new `.stop()` method to stop the progress bar / percentage indicator early.
- `.update()` method accepts an `item_id` argument now in order to display
which item is currently processed next to the progress bar / percentage indicator.
E.g.,
Job1
0% 100%
[####################] | ETA[sec]: 0.000 | Item ID: file_xyz.csv
VERSION 2.7.0
================
- Version intentionally skipped to not cause confusion that
this is a tool exclusively for Python 2.7.
VERSION 2.6.2
================
- Fixed bug that the report was squeezed after the bar and before the "time elapsed" string if printed immediately after the progress bar has reached 100%.
VERSION 2.6.1
================
- Small bugfix on some system a warning was printed although
a valid output string was provided.
VERSION 2.6.0
================
- Added IPython Notebook support
- Fixed to work with most recent psutil v. 0.6 for monitoring CPU and memory usage
VERSION 2.5.0
================
- New default argument `monitor=False` was added to `ProgBar()` and `ProgPercent()` objects to monitor memory and CPU usage (via `psutil`) if `monitor` is set to True.
VERSION 2.4.0
================
- Default argument for `.update(iterations=1)` methods to increment the count by more than 1 per
iteration.
VERSION 2.3.1
================
- Minor fix of the output formatting.
VERSION 2.3.0
================
- Added native print() support
prints title and elapsed time of an tracked object after loop completed.
- Data member self.end stores elapsed time when loop completed.
- Data member self.title saves title of the tracking objects.
VERSION 2.2.0
================
- added ETA (estimated time until arrival) tracking to progress bar
(by Taylan Aydinli).
- better support for Python 2.x.
VERSION 2.1.1
================
- Changed visuals of the printed progress for percentage indicators.
VERSION 2.1.0
================
- added ETA (estimated time until arrival) tracking to percentage indicator
(by Taylan Aydinli, https://github.com/taylan)
VERSION 2.0.3
================
- Accepts a given outputstream for the `stream` parameter.
VERSION 2.0.2
================
- Fixed bug that occurred for some Python 3.3.3 users
specifically on Linux Red Hat 4.4.7-1, GCC v. 4.4.7
that self.max_iter was cast to a float when `ProgBar()`
object was seeded with n=48.
VERSION 2.0.1
================
- Fixed packaging of example files.
VERSION 2.0.0
==============
- ProgBar and ProgPerc inherit data members from parent class Prog
- Added ProgBar and ProgPerc default argument `stream=2` to write to stderr by
default. Set `stream=1` to write to stdout.
my_prbar = pyprind.ProgBar(n, stream=1) # writes to stdout
my_prbar = pyprind.ProgBar(n, stream=2) # writes to stderr, default
- Does not redirect data to the standard output or error stream if program is not
outputting to a terminal.
VERSION 1.1.1
==============
- Fixed problem with packaging of example scripts.
VERSION 1.1.0
===============
- Added live time tracking to percentage indicator
- progress bar and percentage indicator complete automatically,
.finish() was removed
VERSION 1.0.4
===============
- Added boundary that .update() can't print over the
right progress bar limit.
- Prints warning when ProgBar seed exits the number of iterations
in the loop.
VERSION 1.0.3
===============
- Reformatting of README files.
- Minor updates in setup.py file.
VERSION 1.0.2
===============
- Corrected errors in the README files.
- Added docstring to the __init__.py
VERSION 1.0.1
===============
- Added more README formats.
- Added class descriptions.
- Added example scripts to the distribution.
pyprind-2.11.1/CONTRIBUTING.md 0000664 0000000 0000000 00000002626 13221734077 0015526 0 ustar 00root root 0000000 0000000 # How to Contribute
I would be very happy about any kind of contributions that help to improve and extend the functionality of pyprind.
## Getting Started
- If you don't have a [GitHub](https://github.com) account yet, please create one to contribute to this project.
- Please submit a ticket for your issue to discuss the fix or new feature before too much time and effort is spent for the implementation.

- Fork the `pyprind` repository from the GitHub web interface.

- Clone the `pyprind` repository to your local machine
- `git clone https://github.com/your_username/pyprind.git`
## Making Changes
- Please avoid working directly on the master branch but create a new feature branch:
- `git branch new_feature`
- `git checkout new_feature`
- When you make changes, please provide meaningful `commit` messages:
- `git add edited_file`
- `git commit -m 'my note'`
- If it is a new feature, it would be nice (but not necessary) if you could update the documentation.
- Make an entry in the `CHANGELOG.md` file.
- Add tests to the `pyprind/tests` directory.
- Run all tests (e.g., via `nosetests` or `pytest`).
- Push your changes to a topic branch:
- `git push -u origin my_feature`
- Submit a `pull request` from your forked repository via the GitHub web interface.

pyprind-2.11.1/LICENSE 0000664 0000000 0000000 00000002722 13221734077 0014277 0 ustar 00root root 0000000 0000000 Copyright (c) 2014-2016, Sebastian Raschka
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of biopandas nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
pyprind-2.11.1/MANIFEST.in 0000664 0000000 0000000 00000000170 13221734077 0015023 0 ustar 00root root 0000000 0000000 include LICENSE
include README.md
include CONTRIBUTING.md
include CHANGELOG.md
include requirements.txt
include tests/*
pyprind-2.11.1/PKG-INFO 0000664 0000000 0000000 00000002432 13221734077 0014365 0 ustar 00root root 0000000 0000000 Metadata-Version: 1.1
Name: PyPrind
Version: 2.11.1
Summary: Python Progress Bar and Percent Indicator Utility
Home-page: https://github.com/rasbt/pyprind
Author: Sebastian Raschka
Author-email: mail@sebastianraschka.com
License: BSD 3-Clause
Description:
The PyPrind (Python Progress Indicator) module provides a progress
bar and a percentage indicator
object that let you track the progress of a loop structure or
other iterative computation.
Typical applications include the processing of
large data sets to provide an intuitive estimate
at runtime about the progress of the computation.
For more details and examples please see the package documentation
https://github.com/rasbt/pyprind/blob/master/README.md.
Contact
=============
If you have any questions or comments about PyPrind,
please feel free to contact me via
email: mail@sebastianraschka.com
or Twitter: https://twitter.com/rasbt
Platform: any
Classifier: License :: OSI Approved :: BSD License
Classifier: Development Status :: 5 - Production/Stable
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3
Classifier: Environment :: Console
pyprind-2.11.1/PyPrind.egg-info/ 0000775 0000000 0000000 00000000000 13221734077 0016346 5 ustar 00root root 0000000 0000000 pyprind-2.11.1/PyPrind.egg-info/PKG-INFO 0000664 0000000 0000000 00000002432 13221734077 0017444 0 ustar 00root root 0000000 0000000 Metadata-Version: 1.1
Name: PyPrind
Version: 2.11.1
Summary: Python Progress Bar and Percent Indicator Utility
Home-page: https://github.com/rasbt/pyprind
Author: Sebastian Raschka
Author-email: mail@sebastianraschka.com
License: BSD 3-Clause
Description:
The PyPrind (Python Progress Indicator) module provides a progress
bar and a percentage indicator
object that let you track the progress of a loop structure or
other iterative computation.
Typical applications include the processing of
large data sets to provide an intuitive estimate
at runtime about the progress of the computation.
For more details and examples please see the package documentation
https://github.com/rasbt/pyprind/blob/master/README.md.
Contact
=============
If you have any questions or comments about PyPrind,
please feel free to contact me via
email: mail@sebastianraschka.com
or Twitter: https://twitter.com/rasbt
Platform: any
Classifier: License :: OSI Approved :: BSD License
Classifier: Development Status :: 5 - Production/Stable
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3
Classifier: Environment :: Console
pyprind-2.11.1/PyPrind.egg-info/SOURCES.txt 0000664 0000000 0000000 00000000577 13221734077 0020243 0 ustar 00root root 0000000 0000000 CHANGELOG.md
CONTRIBUTING.md
LICENSE
MANIFEST.in
README.md
requirements.txt
setup.py
PyPrind.egg-info/PKG-INFO
PyPrind.egg-info/SOURCES.txt
PyPrind.egg-info/dependency_links.txt
PyPrind.egg-info/top_level.txt
pyprind/__init__.py
pyprind/generator_factory.py
pyprind/prog_class.py
pyprind/progbar.py
pyprind/progpercent.py
tests/test_percentage_indicator.py
tests/test_progress_bar.py pyprind-2.11.1/PyPrind.egg-info/dependency_links.txt 0000664 0000000 0000000 00000000001 13221734077 0022414 0 ustar 00root root 0000000 0000000
pyprind-2.11.1/PyPrind.egg-info/top_level.txt 0000664 0000000 0000000 00000000010 13221734077 0021067 0 ustar 00root root 0000000 0000000 pyprind
pyprind-2.11.1/README.md 0000664 0000000 0000000 00000020712 13221734077 0014550 0 ustar 00root root 0000000 0000000 [](https://travis-ci.org/rasbt/pyprind)
[](https://landscape.io/github/rasbt/pyprind/master)
[](https://coveralls.io/github/rasbt/pyprind?branch=master)


[](http://badge.fury.io/py/pyprind)
[](https://github.com/rasbt/pyprind/blob/master/LICENSE.txt)
# PyPrind (Python Progress Indicator)
The `PyPrind` (Python Progress Indicator) module provides a **progress bar** and a
**percentage indicator** object that let you track the progress of a loop structure or other iterative computation.
Typical applications include the processing of large data sets to provide an intuitive estimate
at runtime about the progress of the computation.

#### Progress Bars and Percentage Generators
```python
import pyprind
for i in pyprind.prog_bar(range(n)):
time.sleep(timesleep) # your computation here
```
```
0% 100%
[##############################] | ETA: 00:00:00
Total time elapsed: 00:00:05
```
```python
for i in pyprind.prog_percent(range(n)):
time.sleep(timesleep) # your computation here
```
```
[10 %] Time elapsed: 00:00:01 | ETA: 00:00:04
```
#### While-loops
The `ProgBar` and `ProgPercent` classes also support while loops if desired.
The objects are updated inside the loop using the `update` method as shown below:
```python
import random
import pyprind
import time
timesleep = 0.05
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)
```
```
while example
0% 100%
[##############################]
Title: while example
Started: 09/07/2016 13:06:58
Finished: 09/07/2016 13:07:03
Total time elapsed: 00:00:05
```
#### Advanced Tracking
If you have the `psutil` package installed, you can set the `monitor=True` to track CPU and memory usage:
```python
bar = pyprind.ProgBar(n, monitor=True)
for i in range(n):
time.sleep(timesleep) # your computation here
bar.update()
print(bar)
```
```
0% 100%
[##############################] | ETA: 00:00:00
Total time elapsed: 00:00:05
Title:
Started: 09/07/2016 13:14:09
Finished: 09/07/2016 13:14:14
Total time elapsed: 00:00:05
CPU %: 1.90
Memory %: 0.48
```
#### Choose Your Favorite Bar Style
```python
bar = pyprind.ProgBar(n, bar_char='█')
for i in range(n):
time.sleep(0.1) # do some computation
bar.update()
```
```
0% 100%
[██████████████████████████████] | ETA: 00:00:00
Total time elapsed: 00:00:10
```
#### Note to PyCharm users
If you are using the PyCharm IDE, you need to pass the `sys.stdout` or `sys.err`
as a `stream` argument to display the progress indicators correctly in the IDE. For example,
```python
import sys
bar = pyprind.ProgBar(n, stream=sys.stdout)
for i in range(n):
time.sleep(0.1) # do some computation
bar.update()
```
###[View more examples in an IPython Demo Notebook](http://nbviewer.ipython.org/github/rasbt/pyprind/blob/master/examples/pyprind_demo.ipynb)
# Sections
- [Installation](#installation)
- [Documentation](#documentation)
- [Examples](#examples)
- [Contact](#contact)
- [Changelog](https://raw.githubusercontent.com/rasbt/pyprind/master/CHANGELOG.txt)
# Installation
[[back to top](#sections)]
The most convenient way to install PyPrind is via tools like `pip` or `easy_install`:
- `pip install pyprind`
- `easy_install pyprind`
PyPrind comes without any dependencies except for the optional [psutil](https://pypi.python.org/pypi/psutil) to [monitor CPU and memory usages](#advanced_tracking). You can install `psutil` via `pip install psutil` or install it automatically with PyPrind:
`pip install pyprind -r requirements.txt`
Alternatively, you can install PyPrind the classic way: Download the package from the Python Package Index [https://pypi.python.org/pypi/PyPrind](https://pypi.python.org/pypi/PyPrind), unzip it,
navigate into the unzipped directory, and use the command
`python setup.py install`
# Documentation
[[back to top](#sections)]
PyPrind consists of two class objects that can visualize the progress of a computation on the output screen.
Progress bars are available via `ProgBar`, and percentage indicators can be used via a `ProgPercent`.
```python
n = 10000000
bar = pyprind.ProgBar(n) # 1) initialization with number of iterations
for i in range(n):
# do some computation
bar.update() # 2) update the progress visualization
```
Alternatively, the progress can be tracked via the equivalent generator functions `prog_bar` and `prog_percent`:
```python
for i in pyprind.prog_bar(range(n)):
# do something
pass
```
#### Complete Parameter of Parameters and Options
##### ProgBar
*`ProgBar(iterations, track_time=True, width=30, bar_char='#',
stream=2, title='', monitor=False, update_interval=None))`*
- iterations : `int`
Number of iterations for the iterative computation.
- track_time : `bool` (default: `True`)
Prints elapsed time when loop has finished.
- width : `int` (default: 30)
Sets the progress bar width in characters.
- stream : `int` (default: 2).
Setting the output stream.
Takes `1` for stdout, `2` for stderr, or a custom stream object
- title : `str` (default: `''`)
Setting a title for the progress bar.
- monitor : `bool` (default: `False`)
Monitors CPU and memory usage if `True` (requires `psutil` package).
- update_interval : float or int (default: `None`)
The update_interval in seconds controls how often the progress
is flushed to the screen.
Automatic mode if `update_interval=None`.
##### ProgPercent
*`ProgPercent(iterations, track_time=True,
stream=2, title='', monitor=False, update_interval=None)`*
- iterations : `int`
Number of iterations for the iterative computation.
- track_time : `bool` (default: `True`)
Prints elapsed time when loop has finished.
- stream : `int` (default: 2).
Setting the output stream.
Takes `1` for stdout, `2` for stderr, or a custom stream object
- title : `str` (default : `''`).
Setting a title for the percentage indicator.
- monitor : `bool` (default: `False`)
Monitors CPU and memory usage if `True` (requires `psutil` package).
- update_interval : float or int (default: `None`)
The update_interval in seconds controls how often the progress
is flushed to the screen.
Automatic mode if `update_interval=None`.
##### update method
*`update(iterations=1, item_id=None, force_flush=False)`*
- iterations : int (default: `1`)
default argument can be changed to integer values
`>=1` in order to update the progress indicators more than once
per iteration.
- item_id : str (default: `None`)
Print an item_id sring behind the progress bar
- force_flush : bool (default: `False`)
If True, flushes the progress indicator to the output screen
in each iteration.
# Examples
[[back to top](#sections)]
Examples for using the progress bar and percentage indicator objects can be found in the [IPython Demo Notebook](https://github.com/rasbt/pyprind/blob/master/examples/pyprind_demo.ipynb).
# Contact
[[back to top](#sections)]
If you have any questions or comments about `PyPrind`, please feel free to contact me via
eMail: [mail@sebastianraschka.com](mailto:mail@sebastianraschka.com)
or Twitter: [@rasbt](https://twitter.com/rasbt)
The `pyprind` module is available on GitHub at [https://github.com/rasbt/pyprind](https://github.com/rasbt/pyprind).
pyprind-2.11.1/pyprind/ 0000775 0000000 0000000 00000000000 13221734077 0014754 5 ustar 00root root 0000000 0000000 pyprind-2.11.1/pyprind/__init__.py 0000664 0000000 0000000 00000000740 13221734077 0017066 0 ustar 00root root 0000000 0000000 """
Sebastian Raschka 2014-2017
Python Progress Indicator Utility
Author: Sebastian Raschka
License: BSD 3 clause
Contributors: https://github.com/rasbt/pyprind/graphs/contributors
Code Repository: https://github.com/rasbt/pyprind
PyPI: https://pypi.python.org/pypi/PyPrind
"""
from .progbar import ProgBar
from .progpercent import ProgPercent
from .generator_factory import prog_percent
from .generator_factory import prog_bar
__version__ = '2.11.1'
pyprind-2.11.1/pyprind/generator_factory.py 0000775 0000000 0000000 00000001405 13221734077 0021046 0 ustar 00root root 0000000 0000000 # PyPrind
# Author: Sebastian Raschka
# Contributors: https://github.com/rasbt/pyprind/graphs/contributors
# License: BSD 3 clause
# Code Repository: https://github.com/rasbt/pyprind
# PyPI: https://pypi.python.org/pypi/PyPrind
from .progbar import ProgBar
from .progpercent import ProgPercent
def generator_factory(mother_class):
def generator_progress(iteritem, iterations=None, *args, **kw):
if iterations is None:
iterations = len(iteritem)
assert iterations
mbar = mother_class(iterations, *args, **kw)
for item in iteritem:
yield item
mbar.update()
return generator_progress
prog_percent = generator_factory(ProgPercent)
prog_bar = generator_factory(ProgBar)
pyprind-2.11.1/pyprind/prog_class.py 0000664 0000000 0000000 00000015722 13221734077 0017471 0 ustar 00root root 0000000 0000000 """
Sebastian Raschka 2014-2017
Python Progress Indicator Utility
Author: Sebastian Raschka
License: BSD 3 clause
Contributors: https://github.com/rasbt/pyprind/graphs/contributors
Code Repository: https://github.com/rasbt/pyprind
PyPI: https://pypi.python.org/pypi/PyPrind
"""
import time
import sys
import os
from io import UnsupportedOperation
try:
import psutil
psutil_import = True
except ImportError:
psutil_import = False
class Prog():
def __init__(self, iterations, track_time, stream, title,
monitor, update_interval=None):
""" Initializes tracking object. """
self.cnt = 0
self.title = title
self.max_iter = float(iterations) # to support Python 2.x
self.track = track_time
self.start = time.time()
self.end = None
self.item_id = None
self.eta = None
self.total_time = 0.0
self.last_time = self.start
self.monitor = monitor
self.stream = stream
self.active = True
self._stream_out = self._no_stream
self._stream_flush = self._no_stream
self._check_stream()
self._print_title()
self.update_interval = update_interval
self._cached_output = ''
sys.stdout.flush()
sys.stderr.flush()
if monitor:
if not psutil_import:
raise ValueError('psutil package is required when using'
' the `monitor` option.')
else:
self.process = psutil.Process()
if self.track:
self.eta = 1
def update(self, iterations=1, item_id=None, force_flush=False):
"""
Updates the progress bar / percentage indicator.
Parameters
----------
iterations : int (default: 1)
default argument can be changed to integer values
>=1 in order to update the progress indicators more than once
per iteration.
item_id : str (default: None)
Print an item_id sring behind the progress bar
force_flush : bool (default: False)
If True, flushes the progress indicator to the output screen
in each iteration.
"""
self.item_id = item_id
self.cnt += iterations
self._print(force_flush=force_flush)
self._finish()
def stop(self):
"""Stops the progress bar / percentage indicator if necessary."""
self.cnt = self.max_iter
self._finish()
def _check_stream(self):
"""Determines which output stream (stdout, stderr, or custom) to use"""
if self.stream:
try:
supported = ('PYCHARM_HOSTED' in os.environ or
os.isatty(sys.stdout.fileno()))
# a fix for IPython notebook "IOStream has no fileno."
except(UnsupportedOperation):
supported = True
else:
if self.stream is not None and hasattr(self.stream, 'write'):
self._stream_out = self.stream.write
self._stream_flush = self.stream.flush
if supported:
if self.stream == 1:
self._stream_out = sys.stdout.write
self._stream_flush = sys.stdout.flush
elif self.stream == 2:
self._stream_out = sys.stderr.write
self._stream_flush = sys.stderr.flush
else:
if self.stream is not None and hasattr(self.stream, 'write'):
self._stream_out = self.stream.write
self._stream_flush = self.stream.flush
else:
print('Warning: No valid output stream.')
def _elapsed(self):
""" Returns elapsed time at update. """
self.last_time = time.time()
return self.last_time - self.start
def _calc_eta(self):
""" Calculates estimated time left until completion. """
elapsed = self._elapsed()
if self.cnt == 0 or elapsed < 0.001:
return None
rate = float(self.cnt) / elapsed
self.eta = (float(self.max_iter) - float(self.cnt)) / rate
def _calc_percent(self):
"""Calculates the rel. progress in percent with 2 decimal points."""
return round(self.cnt / self.max_iter * 100, 2)
def _no_stream(self, text=None):
""" Called when no valid output stream is available. """
pass
def _get_time(self, _time):
if (_time < 86400):
return time.strftime("%H:%M:%S", time.gmtime(_time))
else:
s = (str(int(_time // 3600)) + ':' +
time.strftime("%M:%S", time.gmtime(_time)))
return s
def _finish(self):
""" Determines if maximum number of iterations (seed) is reached. """
if self.cnt >= self.max_iter:
self.total_time = self._elapsed()
self.end = time.time()
self.last_progress -= 1 # to force a refreshed _print()
self._print()
if self.track:
self._stream_out('\nTotal time elapsed: ' +
self._get_time(self.total_time))
self._stream_out('\n')
self.active = False
def _print_title(self):
""" Prints tracking title at initialization. """
if self.title:
self._stream_out('{}\n'.format(self.title))
self._stream_flush()
def _cache_eta(self):
""" Prints the estimated time left."""
self._calc_eta()
self._cached_output += ' | ETA: ' + self._get_time(self.eta)
def _cache_item_id(self):
""" Prints an item id behind the tracking object."""
self._cached_output += ' | Item ID: %s' % self.item_id
def __repr__(self):
str_start = time.strftime('%m/%d/%Y %H:%M:%S',
time.localtime(self.start))
str_end = time.strftime('%m/%d/%Y %H:%M:%S',
time.localtime(self.end))
self._stream_flush()
time_info = 'Title: {}\n'\
' Started: {}\n'\
' Finished: {}\n'\
' Total time elapsed: '.format(self.title,
str_start,
str_end)\
+ self._get_time(self.total_time)
if self.monitor:
try:
cpu_total = self.process.cpu_percent()
mem_total = self.process.memory_percent()
except AttributeError: # old version of psutil
cpu_total = self.process.get_cpu_percent()
mem_total = self.process.get_memory_percent()
cpu_mem_info = ' CPU %: {:.2f}\n'\
' Memory %: {:.2f}'.format(cpu_total, mem_total)
return time_info + '\n' + cpu_mem_info
else:
return time_info
def __str__(self):
return self.__repr__()
pyprind-2.11.1/pyprind/progbar.py 0000775 0000000 0000000 00000006702 13221734077 0016772 0 ustar 00root root 0000000 0000000 """
Sebastian Raschka 2014-2017
Python Progress Indicator Utility
Author: Sebastian Raschka
License: BSD 3 clause
Contributors: https://github.com/rasbt/pyprind/graphs/contributors
Code Repository: https://github.com/rasbt/pyprind
PyPI: https://pypi.python.org/pypi/PyPrind
"""
from math import floor
from pyprind.prog_class import Prog
import time
class ProgBar(Prog):
"""
Initializes a progress bar object that allows visuzalization
of an iterational computation in the standard output screen.
Parameters
----------
iterations : `int`
Number of iterations for the iterative computation.
track_time : `bool` (default: `True`)
Prints elapsed time when loop has finished.
width : `int` (default: 30)
Sets the progress bar width in characters.
stream : `int` (default: 2).
Setting the output stream.
Takes `1` for stdout, `2` for stderr, or a custom stream object
title : `str` (default: `''`)
Setting a title for the progress bar.
monitor : `bool` (default: False)
Monitors CPU and memory usage if `True` (requires `psutil` package).
update_interval : float or int (default: None)
The update_interval in seconds controls how often the progress
is flushed to the screen.
Automatic mode if update_interval=None.
"""
def __init__(self, iterations, track_time=True, width=30, bar_char='#',
stream=2, title='', monitor=False, update_interval=None):
Prog.__init__(self, iterations, track_time,
stream, title, monitor, update_interval)
self.bar_width = width
self._adjust_width()
self.bar_char = bar_char
self.last_progress = 0
if monitor:
try:
self.process.cpu_percent()
self.process.memory_percent()
except AttributeError: # old version of psutil
self.process.get_cpu_percent()
self.process.get_memory_percent()
if self.item_id:
self._cache_item_id()
def _adjust_width(self):
"""Shrinks bar if number of iterations is less than the bar width"""
if self.bar_width > self.max_iter:
self.bar_width = int(self.max_iter)
# some Python 3.3.3 users specifically
# on Linux Red Hat 4.4.7-1, GCC v. 4.4.7
# reported that self.max_iter was converted to
# float. Thus this fix to prevent float multiplication of chars.
def _cache_progress_bar(self, progress):
remaining = self.bar_width - progress
self._cached_output += '0% [{}{}] 100%'.format(self.bar_char * int(progress),
' ' * int(remaining))
def _print(self, force_flush=False):
progress = floor(self._calc_percent() / 100 * self.bar_width)
if self.update_interval:
do_update = time.time() - self.last_time >= self.update_interval
elif force_flush:
do_update = True
else:
do_update = progress > self.last_progress
if do_update and self.active:
self._cache_progress_bar(progress)
if self.track:
self._cache_eta()
if self.item_id:
self._cache_item_id()
self._stream_out('\r%s' % self._cached_output)
self._stream_flush()
self._cached_output = ''
self.last_progress = progress
pyprind-2.11.1/pyprind/progpercent.py 0000775 0000000 0000000 00000005570 13221734077 0017670 0 ustar 00root root 0000000 0000000 """
Sebastian Raschka 2014-2017
Python Progress Indicator Utility
Author: Sebastian Raschka
License: BSD 3 clause
Contributors: https://github.com/rasbt/pyprind/graphs/contributors
Code Repository: https://github.com/rasbt/pyprind
PyPI: https://pypi.python.org/pypi/PyPrind
"""
from pyprind.prog_class import Prog
import time
class ProgPercent(Prog):
"""
Initializes a progress bar object that allows visuzalization
of an iterational computation in the standard output screen.
Parameters
----------
iterations : `int`
Number of iterations for the iterative computation.
track_time : `bool` (default: `True`)
Prints elapsed time when loop has finished.
stream : `int` (default: 2).
Setting the output stream.
Takes `1` for stdout, `2` for stderr, or a custom stream object
title : `str` (default: `''`).
Setting a title for the percentage indicator.
monitor : `bool` (default: `False`)
Monitors CPU and memory usage if `True` (requires `psutil` package).
update_interval : float or int (default: `None`)
The update_interval in seconds controls how often the progress
is flushed to the screen.
Automatic mode if `update_interval=None`.
"""
def __init__(self, iterations, track_time=True,
stream=2, title='', monitor=False, update_interval=None):
Prog.__init__(self, iterations, track_time, stream,
title, monitor, update_interval)
self.last_progress = 0
self._print()
if monitor:
try:
self.process.cpu_percent()
self.process.memory_percent()
except AttributeError: # old version of psutil
self.process.get_cpu_percent()
self.process.get_memory_percent()
def _cache_percent_indicator(self, last_progress):
self._cached_output += '[%3d %%]' % (last_progress)
def _print(self, force_flush=False):
""" Prints formatted percentage and tracked time to the screen."""
self._stream_flush()
next_perc = self._calc_percent()
if self.update_interval:
do_update = time.time() - self.last_time >= self.update_interval
elif force_flush:
do_update = True
else:
do_update = next_perc > self.last_progress
if do_update and self.active:
self.last_progress = next_perc
self._cache_percent_indicator(self.last_progress)
if self.track:
self._cached_output += ' Time elapsed: ' + \
self._get_time(self._elapsed())
self._cache_eta()
if self.item_id:
self._cache_item_id()
self._stream_out('\r%s' % self._cached_output)
self._stream_flush()
self._cached_output = ''
pyprind-2.11.1/requirements.txt 0000664 0000000 0000000 00000000015 13221734077 0016547 0 ustar 00root root 0000000 0000000 psutil>=3.2.0 pyprind-2.11.1/setup.cfg 0000664 0000000 0000000 00000000073 13221734077 0015110 0 ustar 00root root 0000000 0000000 [egg_info]
tag_build =
tag_date = 0
tag_svn_revision = 0
pyprind-2.11.1/setup.py 0000664 0000000 0000000 00000003762 13221734077 0015011 0 ustar 00root root 0000000 0000000 """
Sebastian Raschka 2014-2016
Python Progress Indicator Utility
Author: Sebastian Raschka
License: BSD 3 clause
Contributors: https://github.com/rasbt/pyprind/graphs/contributors
Code Repository: https://github.com/rasbt/pyprind
PyPI: https://pypi.python.org/pypi/PyPrind
"""
from setuptools import setup, find_packages
import pyprind
VERSION = pyprind.__version__
setup(name='PyPrind',
version=VERSION,
description='Python Progress Bar and Percent Indicator Utility',
author='Sebastian Raschka',
author_email='mail@sebastianraschka.com',
url='https://github.com/rasbt/pyprind',
packages=find_packages(),
package_data={'': ['LICENSE',
'README.md',
'requirements.txt',
'CHANGELOG.md',
'CONTRIBUTING.md'],
'tests': ['tests/test_percentage_indicator.py',
'tests/test_progress_bar.py']},
include_package_data=True,
license='BSD 3-Clause',
platforms='any',
classifiers=[
'License :: OSI Approved :: BSD License',
'Development Status :: 5 - Production/Stable',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Environment :: Console'],
long_description="""
The PyPrind (Python Progress Indicator) module provides a progress
bar and a percentage indicator
object that let you track the progress of a loop structure or
other iterative computation.
Typical applications include the processing of
large data sets to provide an intuitive estimate
at runtime about the progress of the computation.
For more details and examples please see the package documentation
https://github.com/rasbt/pyprind/blob/master/README.md.
Contact
=============
If you have any questions or comments about PyPrind,
please feel free to contact me via
email: mail@sebastianraschka.com
or Twitter: https://twitter.com/rasbt""",)
pyprind-2.11.1/tests/ 0000775 0000000 0000000 00000000000 13221734077 0014431 5 ustar 00root root 0000000 0000000 pyprind-2.11.1/tests/test_percentage_indicator.py 0000664 0000000 0000000 00000004504 13221734077 0022216 0 ustar 00root root 0000000 0000000 """
Sebastian Raschka 2014-2016
Python Progress Indicator Utility
Author: Sebastian Raschka
License: BSD 3 clause
Contributors: https://github.com/rasbt/pyprind/graphs/contributors
Code Repository: https://github.com/rasbt/pyprind
PyPI: https://pypi.python.org/pypi/PyPrind
"""
import sys
import time
import pyprind
n = 100
sleeptime = 0.02
def test_basic_percent():
perc = pyprind.ProgPercent(n)
for i in range(n):
time.sleep(sleeptime)
perc.update()
def test_stdout():
perc = pyprind.ProgPercent(n, stream=sys.stdout)
for i in range(n):
time.sleep(sleeptime)
perc.update()
def test_generator():
for i in pyprind.prog_percent(range(n), stream=sys.stdout):
time.sleep(sleeptime)
def test_monitoring():
perc = pyprind.ProgPercent(n, monitor=True)
for i in range(n):
time.sleep(sleeptime)
perc.update()
print(perc)
def test_item_tracking():
items = ['file_%s.csv' % i for i in range(0, n)]
perc = pyprind.ProgPercent(len(items))
for i in items:
time.sleep(sleeptime)
perc.update(item_id=i)
def test_force_flush():
perc = pyprind.ProgPercent(n)
for i in range(n):
time.sleep(sleeptime)
perc.update(force_flush=True)
def test_update_interval():
perc = pyprind.ProgPercent(n, update_interval=4)
for i in range(n):
time.sleep(sleeptime)
perc.update()
if __name__ == "__main__":
print('\n%s' % (80 * '='))
print('%s\n' % (80 * '='))
print('Testing Basic Percentage Indicator\n')
test_basic_percent()
print('\n%s' % (80 * '='))
print('%s\n' % (80 * '='))
print('Testing stdout Stream\n')
test_stdout()
print('\n%s' % (80 * '='))
print('%s\n' % (80 * '='))
print('Testing Percentage Indicator Generator\n')
test_generator()
print('\n%s' % (80 * '='))
print('%s\n' % (80 * '='))
print('Testing monitor function\n')
test_monitoring()
print('\n%s' % (80 * '='))
print('%s\n' % (80 * '='))
print('Testing Item Tracking\n')
test_item_tracking()
print('\n%s' % (80 * '='))
print('%s\n' % (80 * '='))
print('Testing Force Flush\n')
test_force_flush()
print('\n%s' % (80 * '='))
print('%s\n' % (80 * '='))
print('Testing Update Interval\n')
test_update_interval()
pyprind-2.11.1/tests/test_progress_bar.py 0000664 0000000 0000000 00000004752 13221734077 0020542 0 ustar 00root root 0000000 0000000 import sys
import time
import pyprind
n = 100
sleeptime = 0.02
def test_bar():
bar = pyprind.ProgBar(n)
for i in range(n):
time.sleep(sleeptime)
bar.update()
def test_stdout():
bar = pyprind.ProgBar(n, stream=sys.stdout)
for i in range(n):
time.sleep(sleeptime)
bar.update()
def test_generator():
for i in pyprind.prog_bar(range(n), stream=sys.stdout):
time.sleep(sleeptime)
def test_monitoring():
bar = pyprind.ProgBar(n, monitor=True)
for i in range(n):
time.sleep(sleeptime)
bar.update()
print(bar)
def test_width():
bar = pyprind.ProgBar(n, width=10)
for i in range(n):
time.sleep(sleeptime)
bar.update()
def test_item_tracking():
items = ['file_%s.csv' % i for i in range(0, n)]
bar = pyprind.ProgBar(len(items))
for i in items:
time.sleep(sleeptime)
bar.update(item_id=i)
def test_character():
bar = pyprind.ProgBar(n, bar_char='>')
for i in range(n):
time.sleep(sleeptime)
bar.update()
def test_force_flush():
bar = pyprind.ProgBar(n)
for i in range(n):
time.sleep(sleeptime)
bar.update(force_flush=True)
def test_update_interval():
bar = pyprind.ProgBar(n, update_interval=0.1)
for i in range(n):
time.sleep(sleeptime)
bar.update()
if __name__ == '__main__':
print('\n%s' % (80 * '='))
print('%s\n' % (80 * '='))
print('Testing Basic Progress Bar\n')
test_bar()
print('\n%s' % (80 * '='))
print('%s\n' % (80 * '='))
print('Testing stdout Stream\n')
test_stdout()
print('\n%s' % (80 * '='))
print('%s\n' % (80 * '='))
print('Testing Progress Bar Generator\n')
test_generator()
print('\n%s' % (80 * '='))
print('%s\n' % (80 * '='))
print('Testing monitor function\n')
test_monitoring()
print('\n%s' % (80 * '='))
print('%s\n' % (80 * '='))
print('Testing Width Parameter\n')
test_width()
print('\n%s' % (80 * '='))
print('%s\n' % (80 * '='))
print('Testing Item Tracking\n')
test_item_tracking()
print('\n%s' % (80 * '='))
print('%s\n' % (80 * '='))
print("Testing Progress Bar Character ('>', default: '#')\n")
test_character()
print('\n%s' % (80 * '='))
print('%s\n' % (80 * '='))
print('Testing Force Flush\n')
test_force_flush()
print('\n%s' % (80 * '='))
print('%s\n' % (80 * '='))
print('Testing Update Interval\n')
test_update_interval()