← Back to team overview

graphite-dev team mailing list archive

[Question #227751]: implementaion movingSum

 

New question #227751 on Graphite:
https://answers.launchpad.net/graphite/+question/227751

Hi, 

I track issue with your tool and I used function summarize in time interval, what is reseting values to zero at the begging of interval.


I wonder if you could implement something like movingSum what will be almost the same implementation like movingAvg but there will be no division.


def movingSum(requestContext, seriesList, windowSize):
  """
  Takes one metric or a wildcard seriesList followed by a number N of datapoints and graphs
  the Sum of N previous datapoints.  N-1 datapoints are set to None at the
  beginning of the graph.

  .. code-block:: none

    &target=movingSum(Server.instance01.threads.busy,10)

  """
  for seriesIndex, series in enumerate(seriesList):
    newName = "movingSum(%s,%d)" % (series.name, windowSize)
    newSeries = TimeSeries(newName, series.start, series.end, series.step, [])
    newSeries.pathExpression = newName

    windowIndex = int(windowSize) - 1

    for i in range( len(series) ):
      if i < windowIndex: # Pad the beginning with None's since we don't have enough data
        newSeries.append( None )

      else:
        window = series[i - windowIndex : i + 1]
        nonNull = [ v for v in window if v is not None ]
        if nonNull:
          newSeries.append( sum(nonNull) )
        else:
          newSeries.append(None)

    seriesList[ seriesIndex ] = newSeries

  return seriesList


what do you thing? 

Vena

-- 
You received this question notification because you are a member of
graphite-dev, which is an answer contact for Graphite.