Giter VIP home page Giter VIP logo

etaprogress's Introduction

etaprogress

Draw progress bars with room for colors and display rates and ETAs in your console applications. ETA library is its own class so it may be used in other non-console applications. ETAs calculated with simple linear regression.

This library supports both defined and undefined progress bars. Undefined progress bars are those that do not have a "total size". Similar to when wget downloads a file with an unknown file size. Due to this, undefined progress bars have no percent and no ETA. Defined progress bars are the usual progress bars with percentages and ETAs.

  • Python 2.6, 2.7, PyPy, PyPy3, 3.3, and 3.4 supported on Linux and OS X.
  • Python 2.7, 3.3, and 3.4 supported on Windows (both 32 and 64 bit versions of Python).

Tested on Windows XP and Windows 10 technical preview.

Build Status Windows

Build Status

Coverage Status

Latest Version

Downloads

Quickstart

Install:

pip install etaprogress

Example Implementations

Example Scripts Screenshot

Source code for examples: example.py, example_colors.py, and example_wget.py

Usage

If all you need is a progress bar with an ETA, you only have to import a class in the etaprogress.progress module. To get the progress bar itself just cast to string or print the instance.

Simple Usage

import time
from etaprogress.progress import ProgressBar
total = 5
bar = ProgressBar(total, max_width=40)
for i in range(total + 1):
    bar.numerator = i
    print bar
    time.sleep(1)
0% (0/5) [               ] eta --:-- -

20% (1/5) [### ] eta 00:05 40% (2/5) [###### ] eta 00:04 | 60% (3/5) [######### ] eta 00:03 / 80% (4/5) [############ ] eta 00:02 -

100% (5/5) [###############] eta 00:00

Of course that's not a very good progress bar animation. Here's a better one with print_function:

from __future__ import print_function
import sys
import time
from etaprogress.progress import ProgressBar
total = 5
bar = ProgressBar(total, max_width=40)
for i in range(total + 1):
    bar.numerator = i
    print(bar, end='\r')
    sys.stdout.flush()
    time.sleep(1)
print()
100% (5/5) [###############] eta 00:00 \

Terminal Colors Support

Colors are supported using colorclass. Take a look at example_colors.py on how to implement colorful progress bars. You may have to subclass one of the ProgressBar classes (or even BaseProgressBar) to add colors to every nook and cranny of a progress bar.

Class Attributes

There are five different progress bar classes with visual differences:

  • ProgressBar -- a simple progress bar.
  • ProgressBarBits -- similar to ProgressBar but converts numbers to bits, kilobits, etc.
  • ProgressBarBytes -- similar to ProgressBar but converts numbers to bytes, kibibytes (kilobytes), etc.
  • ProgressBarWget -- a progress bar that looks like the one in the GNU wget application.
  • ProgressBarYum -- a progress bar that looks like the one in CentOS/RHEL 7 yum utility.
Name Description/Notes
max_width Limit number of characters shown (by default the full progress bar takes up the entire terminal width).
eta_every Calculate and cache the ETA string after this many numerator setting iteration. Default is every iter.
force_done For undefined progress bars this indicates that the progress has completed.
filename 'ProgressBarYum' only. The string to display before the progress bar. Limited to whatever space is available in the terminal.

Class Properties

Name Description/Notes
denominator Returns the denominator of the progress bars. The same value provided when instantiating.
done Returns True if the progress has completed.
numerator Read/write. Returns the numerator as an integer or sets a new numerator. When setting a numerator it must be equal to or greater than the previous one.
percent Returns the percent as a float.
rate Returns the rate of the progress as a float.
undefined Return True if the progress bar is undefined.

Changelog

This project adheres to Semantic Versioning.

1.1.1 - 2015-03-18

Fixed
  • Broken setup.py file.

1.1.0 - 2014-11-25

Added
  • Windows support.

1.0.0 - 2014-10-20

  • Initial release.

etaprogress's People

Contributors

robpol86 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

etaprogress's Issues

simple usage example misleading

The simple usage example assumes that the total number of items to process is 5 and iterates over range(5 + 1) (= 6) items in order to draw a full 100%. Obviously you cannot iterate six times in a loop over a list of five items.

The following shows a "real life" usage example:

progress_set = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)

total = len(progress_set)
bar   = ProgressBar(total)

for index, item in enumerate(progress_set):
    bar.numerator = index
    print(bar, end = '\r')

    # do stuff with item of progress_set
    time.sleep(0.25)

bar.numerator += 1
print(bar)

example.py shows in progress_bar() print(bar) # Always print one last time. This is probably an - incomplete - remainder of the correct usage. The author just forgot to increment the numerator.

Installing on windows

Line 137 of setup.py
**get_metadata(os.path.join(NAME_FILE + ('/init.py' if PACKAGE else '.py')))

Should this be \ \ for windows?

Installing on windows gives me this error: FileNotFoundError: [Errno 2] No such file or directory: 'c:\users\sean\appdata\local\temp\pip_build_Sean\etaprogress\etaprogress/init.py'

locale.format is deprecated since Python 3.7

I get the following deprecation warnings:

.../lib/python3.7/site-packages/etaprogress/progress.py:79: DeprecationWarning: This method will be removed in a future version of Python. Use 'locale.format_string()' instead.
    denominator = locale.format('%d', self.denominator, grouping=True)
.../lib/python3.7/site-packages/etaprogress/progress.py:86: DeprecationWarning: This method will be removed in a future version of Python. Use 'locale.format_string()' instead.
    return locale.format('%d', self.numerator, grouping=True)

division by 0 in eta.py

Hello,

I am using the progress bar to report progress on some long running task. Sometime I get a division by 0 exception in eta.py at line 155:

pearson_r = sum_xy / sqrt(sum_sq_v_x * sum_sq_v_y)

This does not happen all the time, but it does happen quite frequently. Sometimes the numerator is incremented by 0, sometime by some thousands.

Is this a known bug?

Thanks,
Iulian

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.