dgryski/carbonapi — pull request #32 by cashlo (2014-10-30 17:43:52+00:00)
Title: Adding absolute(), averageAbove(), averageBelow(), and maxValue support for nonNegativeDerivative

Implemented a few functions, and modified nonNegativeDerivative base on the logic from
http://nullege.com/codes/search/graphite_api.functions.nonNegativeDerivative
```
def nonNegativeDerivative(requestContext, seriesList, maxValue=None):
"""
Same as the derivative function above, but ignores datapoints that trend
down. Useful for counters that increase for a long time, then wrap or
reset. (Such as if a network interface is destroyed and recreated by
unloading and re-loading a kernel module, common with USB / WiFi cards.

Example::

&target=nonNegativederivative(
company.server.application01.ifconfig.TXPackets)

"""
results = []

for series in seriesList:
newValues = []
prev = None

for val in series:
if None in (prev, val):
newValues.append(None)
prev = val
continue

diff = val - prev
if diff >= 0:
newValues.append(diff)
elif maxValue is not None and maxValue >= val:
newValues.append((maxValue - prev) + val + 1)
else:
newValues.append(None)

prev = val

newName = "nonNegativeDerivative(%s)" % series.name
newSeries = TimeSeries(newName, series.start, series.end, series.step,
newValues)
newSeries.pathExpression = newName
results.append(newSeries)

return results
```