breadcrumbtrail

Create simple timestamps as you code in Python


License
MIT
Install
pip install breadcrumbtrail==1.0

Documentation

breadcrumbtrail

Create simple timestamps as you code in Python

Installation

pip install breadcrumbtrail

Usage

Currently the package is only one class.

import time
from breadcrumbtrail import track

Make checkpoints and calculate the time from checkpoint or the total time elapsed:

t = track(); time.sleep(1)
t.make_checkpoint('checkpoint_name'); time.sleep(1)

# measure time from checkpoint with key 'checkpoint_name'
timedelta = t.timedelta_to_checkpoint(timestamp=t.timestamp(), checkpoint_key='checkpoint_name')

# format the time measured according to user-defined format
print(t.format_time(timedelta, fmt = '{days} days, {hours} hours, {seconds} seconds', zero_padding=0))

# print the total time since 
print(t.time_elapsed())

Yields the following output:

>>> 0 days, 0 hours, 1 seconds
>>> 00:00:02

Set the number of checkpoints expected until completion to get an ETA on when the process will be done:

t = track(10) # 10 checkpoints expected until completion
for _ in range(10):
    time.sleep(0.25); t.make_checkpoint()
    print('complete: %s' % t.complete)
    print(t.eta(fmt='ETA: {seconds} seconds'))

Yields the following output:

>>> complete: False
>>> None
>>> complete: False
>>> ETA: 2 seconds
>>> complete: False
>>> ETA: 2 seconds
>>> complete: False
>>> ETA: 1 seconds
>>> complete: False
>>> ETA: 1 seconds
>>> complete: False
>>> ETA: 1 seconds
>>> complete: False
>>> ETA: 1 seconds
>>> complete: False
>>> ETA: 0 seconds
>>> complete: False
>>> ETA: 0 seconds
>>> complete: True
>>> ETA: 0 seconds