Skip to content

Commit

Permalink
2.1.1 - Add 'poll' method to rate tracker
Browse files Browse the repository at this point in the history
  • Loading branch information
vkottler committed Jun 27, 2023
1 parent aafdecf commit 107c7c2
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 14 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
=====================================
generator=datazen
version=3.1.2
hash=1cdc07131261518d6adc3cc3b858a4e5
hash=c8539167d87cd90bab3348640cfcc01d
=====================================
-->

# vcorelib ([2.1.0](https://pypi.org/project/vcorelib/))
# vcorelib ([2.1.1](https://pypi.org/project/vcorelib/))

[![python](https://img.shields.io/pypi/pyversions/vcorelib.svg)](https://pypi.org/project/vcorelib/)
![Build Status](https://github.com/vkottler/vcorelib/workflows/Python%20Package/badge.svg)
Expand Down
2 changes: 1 addition & 1 deletion local/variables/package.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
major: 2
minor: 1
patch: 0
patch: 1
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta:__legacy__"

[project]
name = "vcorelib"
version = "2.1.0"
version = "2.1.1"
description = "A collection of core Python utilities."
readme = "README.md"
requires-python = ">=3.8"
Expand Down
4 changes: 2 additions & 2 deletions vcorelib/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# =====================================
# generator=datazen
# version=3.1.2
# hash=f10b2b08bda3a1c912bec72ab1620fde
# hash=755514cb838cd49df3f095036c06cce4
# =====================================

"""
Expand All @@ -10,7 +10,7 @@

DESCRIPTION = "A collection of core Python utilities."
PKG_NAME = "vcorelib"
VERSION = "2.1.0"
VERSION = "2.1.1"

# vcorelib-specific content.
DEFAULT_INDENT = 2
Expand Down
21 changes: 13 additions & 8 deletions vcorelib/math/analysis/rate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,13 @@ def max(self) -> float:
"""An accessor for the underlying max."""
return self.average.max

def __call__(self, time_ns: int = None, value: float = 1.0) -> float:
"""
Submit new data to the rate tracker. If this function is called with
default arguments, the returned value will reflect the rate that this
method is being called in hertz.
"""
def poll(self, time_ns: int = None) -> float:
"""Siphon accumulated time and update rate tracking."""

# Use a default time if one wasn't provided.
if time_ns is None:
time_ns = _default_time_ns()

self.accumulated += value

# Only start tracking when a second data point is encountered.
if self.prev_time_ns != 0 and time_ns > self.prev_time_ns:
# Consider 'value' as the amount of change since the last data
Expand All @@ -66,8 +60,19 @@ def __call__(self, time_ns: int = None, value: float = 1.0) -> float:
self.accumulated = 0

self.prev_time_ns = time_ns

return self.average.value

def __call__(self, time_ns: int = None, value: float = 1.0) -> float:
"""
Submit new data to the rate tracker. If this function is called with
default arguments, the returned value will reflect the rate that this
method is being called in hertz.
"""

self.accumulated += value
return self.poll(time_ns=time_ns)

def with_dt(self, delta_s: float, value: float = 1.0) -> float:
"""Update this rate by directly providing the delta-time value."""
return self.average(value / delta_s)
Expand Down

0 comments on commit 107c7c2

Please sign in to comment.