ETA Time
A library for tracking, computing, and formatting time estimates.
Basic Usage
import time, random
from etatime.eta import eta_calculator
# Just a placeholder function that takes a random amount of time
def process_item(item):
time.sleep(random.random() * 20)
for item, eta in eta_calculator(range(10)): # Creates a new Eta object for each item
print(eta) # Print the current progress stats
process_item(item) # Do your processing here
If you want to access the eta stats outside the loop, you can use this pattern to do so:
eta = None # Initialize the eta variable here, so we can use it outside the loop
for item, eta in eta_calculator(range(10)):
print(eta)
process_item(item)
eta.complete() # Update the last Eta object to completed, using now as the end time
print(f"Done processing {eta.total_items} items in {eta.string(eta.StringField.TIME_TAKEN)}!\n")
Here is an example of the sort of output this produces:
0.00%
10.00% | R: 0:01:33 | E: 12:25:16 AM
20.00% | R: 0:01:56 | E: 12:25:57 AM
30.00% | R: 0:01:13 | E: 12:25:16 AM
40.00% | R: 0:00:55 | E: 12:25:03 AM
50.00% | R: 0:00:55 | E: 12:25:22 AM
60.00% | R: 0:00:43 | E: 12:25:18 AM
70.00% | R: 0:00:32 | E: 12:25:19 AM
80.00% | R: 0:00:19 | E: 12:25:09 AM
90.00% | R: 0:00:09 | E: 12:25:00 AM
Done processing 10 items in 0:01:33!
You can get more verbose information by replacing the for loop with this:
for item, eta in eta_calculator(range(10), verbose=True):
Here is an example of the verbose output:
0.00% (0/10)
10.00% (1/10) | Time remaining: 1 minute and 54 seconds | ETA: 12:27:33 AM US Mountain Standard Time
20.00% (2/10) | Time remaining: 1 minute and 33 seconds | ETA: 12:27:22 AM US Mountain Standard Time
30.00% (3/10) | Time remaining: 1 minute and 7 seconds | ETA: 12:27:02 AM US Mountain Standard Time
40.00% (4/10) | Time remaining: 50 seconds | ETA: 12:26:49 AM US Mountain Standard Time
50.00% (5/10) | Time remaining: 51 seconds | ETA: 12:27:08 AM US Mountain Standard Time
60.00% (6/10) | Time remaining: 41 seconds | ETA: 12:27:09 AM US Mountain Standard Time
70.00% (7/10) | Time remaining: 28 seconds | ETA: 12:27:01 AM US Mountain Standard Time
80.00% (8/10) | Time remaining: 20 seconds | ETA: 12:27:05 AM US Mountain Standard Time
90.00% (9/10) | Time remaining: 10 seconds | ETA: 12:27:07 AM US Mountain Standard Time
Done processing 10 items in 1 minute and 51 seconds!
You can also build a custom message piece-by-piece, like so:
print(f"Processing item: '{item}'")
print(f" Completed: {eta.string(eta.Value.COMPLETION)}")
print(f" Time taken: {eta.string(eta.Value.TIME_TAKEN)}")
print(f" Time remaining: {eta.string(eta.Value.TIME_REMAINING)}")
print(f" ETA: {eta.string(eta.Value.ETA)}")
This produces the following output:
Processing item: '0'
Completed: 0.00% (0/10)
Time taken: 0 seconds
Time remaining: not enough data
ETA: not enough data
Processing item: '1'
Completed: 10.00% (1/10)
Time taken: 11 seconds
Time remaining: 1 minute and 38 seconds
ETA: 12:29:31 AM US Mountain Standard Time
Processing item: '2'
Completed: 20.00% (2/10)
Time taken: 29 seconds
Time remaining: 1 minute and 55 seconds
ETA: 12:30:05 AM US Mountain Standard Time
Processing item: '3'
Completed: 30.00% (3/10)
Time taken: 47 seconds
Time remaining: 1 minute and 50 seconds
ETA: 12:30:18 AM US Mountain Standard Time
Processing item: '4'
Completed: 40.00% (4/10)
Time taken: 54 seconds
Time remaining: 1 minute and 21 seconds
ETA: 12:29:57 AM US Mountain Standard Time
Processing item: '5'
Completed: 50.00% (5/10)
Time taken: 56 seconds
Time remaining: 56 seconds
ETA: 12:29:33 AM US Mountain Standard Time
Processing item: '6'
Completed: 60.00% (6/10)
Time taken: 1 minute and 3 seconds
Time remaining: 42 seconds
ETA: 12:29:27 AM US Mountain Standard Time
Processing item: '7'
Completed: 70.00% (7/10)
Time taken: 1 minute and 22 seconds
Time remaining: 35 seconds
ETA: 12:29:38 AM US Mountain Standard Time
Processing item: '8'
Completed: 80.00% (8/10)
Time taken: 1 minute and 28 seconds
Time remaining: 22 seconds
ETA: 12:29:32 AM US Mountain Standard Time
Processing item: '9'
Completed: 90.00% (9/10)
Time taken: 1 minute and 48 seconds
Time remaining: 12 seconds
ETA: 12:29:41 AM US Mountain Standard Time
Done processing 10 items in 1 minute and 57 seconds!
Full Documentation
Metadata
Release files for etatime 2.7.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| etatime-2.7.1.tar.gz | 20.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| etatime-2.7.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 40.8 kB
Release files / etatime-2.7.1.tar.gz
| Download URL | etatime-2.7.1.tar.gz |
|---|---|
| Size | 20.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a49f3334e88e7f064579c2a7fa06c4621e92184af30c86f9dd6d4c4aa60d0912
|
|
BLAKE2b-256 checksum How to use checksums |
515ce8e374ba17c18fe451c46f1226b8ddbfcb307d11f961037bbea8f6f2eb55
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/4.0.2 CPython/3.11.7
|
Release files / etatime-2.7.1-py3-none-any.whl
| Download URL | etatime-2.7.1-py3-none-any.whl |
|---|---|
| Size | 20.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1fa2ce04d6555fc611a5728a7504fef85ae7d999c85634c241e5918ee61fc512
|
|
BLAKE2b-256 checksum How to use checksums |
d14ff95bd964a1fe8ca88bf578115a3fd5c6340320a66dd5843146beff034e0a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/4.0.2 CPython/3.11.7
|