A clock-like periodic sequence generator
Project description
clockrange
A clock-like periodic sequence generator
Installation
pip install clockrange
Getting Started
ClockRange
provides clock-like sequences according to the given specification:
from clockrange import ClockRange
# A typical 24h microsecond-granular clock.
clock = ClockRange((24, 60, 60, 1000, 1000))
# How many microseconds until the clock completes a full cycle?
len(clock)
# How does the clock look like when 150000 microseconds have passed?
clock[150000]
See more examples below.
Examples
ClockRange
accepts different specification formats:
# These are equivalent:
ClockRange((3, 60))
ClockRange(([0, 1, 2], 60))
ClockRange((range(3), 60))
ClockRange((range(0, 3, 1), 60))
# These result in .counters being different from .rendered:
ClockRange((["A", "B", "Z"], 60))
ClockRange((range(4, 10, 2), 60))
ClockRange
instances support random item access with O(1) runtime performance:
clock = ClockRange((24, 60, 60))
clock[0] # ClockState(counters=(0, 0, 0), cycles=0, rendered=(0, 0, 0))
clock[1] # ClockState(counters=(0, 0, 1), cycles=0, rendered=(0, 0, 1))
clock[86400] # ClockState(counters=(0, 0, 0), cycles=1, rendered=(0, 0, 0))
ClockRange.__len__
provides the cycle length:
assert len(ClockRange((12,))) == 12
assert len(ClockRange((10, 10))) == 100
assert len(ClockRange((24, 60, 60))) == 86400
ClockRange
instances can be iterated on:
clock = ClockRange((24, 60, 60))
it = iter(clock)
next(it) # ClockState(counters=(0, 0, 0), cycles=0, rendered=(0, 0, 0))
next(it) # ClockState(counters=(0, 0, 1), cycles=0, rendered=(0, 0, 1))
ClockRange
iterators never get exhausted, so loop control needs to be performed manually:
for state in ClockRange((24, 60, 60):
if state.cycle == 1:
break
Contributing
To run the test suite locally, clone and setup the repository for local development:
pipenv install
pytest --cov-report=html
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file clockrange-0.0.1.tar.gz
.
File metadata
- Download URL: clockrange-0.0.1.tar.gz
- Upload date:
- Size: 2.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 04ebb0b4f23b5ca71570a4ca7e807c131d1b8001941f422ab6a49587589ebf89 |
|
MD5 | 1520fc4c06d6d6ac61ab758fae6449f0 |
|
BLAKE2b-256 | 0edf8adc4d061d166f51b0cd69270cf40366e38676076e00e535485338df0e9d |
File details
Details for the file clockrange-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: clockrange-0.0.1-py3-none-any.whl
- Upload date:
- Size: 2.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0151204e8f65129f8bcc5ab745d19ba79372d0c318bd7a1194d59eff9caf17fd |
|
MD5 | eb6caabdb1a64268fb1230579a31bc5d |
|
BLAKE2b-256 | 83933c95254af283d1431b3abcd38be0a202bb8c349b3b872bb06fdc8ae0d841 |