for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
# -*- coding: utf-8 -*-
"""
.. moduleauthor:: Kenny Freeman <[email protected]>
__author__ = 'Kenny Freeman'
__email__ = '[email protected]'
__version__ = '0.3.3'
__license__ = "ISCL"
__docformat__ = 'reStructuredText'
import time
class Differential(object):
"""Computes the rate of change of a set of metrics."""
def __init__(self):
self.metrics = {}
def per_second(self, name, val, ts):
"""Records and returns the rate of change of a metric in units/second.
:param name: The name of a metric
:type name: str
:param val: The value of a metric
:type val: int or float
:rtype: int or float
ret = type(val)(0)
if name not in self.metrics:
self.metrics[name] = (val, ts)
else:
pval, ptime = self.metrics[name]
dval = val - pval
dtime = ts - ptime
if dtime > 0:
ret = dval / dtime
ret = 0
return ret