Coder Social home page Coder Social logo

sliding-window-counter's Introduction

Sliding Window Counter

PyPi PyPI - Status Python Versions License

sliding-window-counter provides time based sliding window counters. These are useful for tracking things like throughput metrics for long running applications.

Installation

Install via pip

pip3 install sliding-window-counter

Quick Start

## Creating Counters
## -----------------------------------------------------------------------------
import datetime as dt
from sliding_window_counter import SlidingWindowCounter

# Count across 1 minute with 5 second resolution
small_counter = SlidingWindowCounter(60, 5)

# Count across 1 hour with 1 minute resolution
long_counter = SlidingWindowCounter(dt.timedelta(hours=1), dt.timedelta(minutes=1))

# Count across 12 hours with 10 second resolution (not a good idea to be honest)
long_and_precise_counter = SlidingWindowCounter(dt.timdelta(hours=12), 10)

## Using Counters
## -----------------------------------------------------------------------------
import random
import time

mini_counter = SlidingWindowCounter(10, 1)

# fill it up and check it's state
for i in range(20):
    add = random.randint(1,20)
    mini_counter.increment(add)
    print(f"{i:>3}s Added: {add:<3} Window: {mini_counter.current_total:<6} Total: {mini_counter.grand_total:<6} Avg: {mini_counter.current_throughput:>5.2f}/s")
    time.sleep(1)

# Watch it drain
for i in range(12):
    time.sleep(1)
    print(f"Window: {mini_counter.current_total:<5} Total: {mini_counter.grand_total:<5} Avg: {mini_counter.current_throughput:>5.2f}/s")

Bugs, Feature Requests etc

TLDR: Please submit an issue on github.

In the case of bug reports, please help me help you by following best practices 1 2.

In the case of feature requests, please provide background to the problem you are trying to solve so to help find a solution that makes the most sense for the library as well as your usecase.

Development

The only development dependency is bash and docker. All actions are run within docker for ease of use. See ./dev.sh help for commands. Typical commands are format, lint, test, repl, build.

I am still working through open source licencing and contributing, so not taking PRs at this point in time. Instead raise and issue and I'll try get to it as soon a feasible.

Licence

This project is licenced under the MIT Licence - see LICENCE.

This project may include other open source licenced software - see NOTICE.

Authors

A project by Nicholas Hairs - www.nicholashairs.com.

sliding-window-counter's People

Contributors

nhairs avatar

Watchers

 avatar

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.