Create keepLastValue() target function

Bug #379823 reported by chrismd
16
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Graphite
Fix Released
Undecided
kraig

Bug Description

The keepLastValue() target function should change the rendering behavior for each series passed to it such that missing values are converted to the last known value preceding them.

Revision history for this message
kraig (kamador) wrote :

This was a good idea. I found a lot of places to use this function.

diff --git a/composer_widgets.js b/composer_widgets.js
index f50997a..cba0c4c 100644
--- a/composer_widgets.js
+++ b/composer_widgets.js
@@ -404,6 +404,7 @@ var TargetsWindow = { //This widget has a lot of state, so an object is appropri
         {text: 'Most Deviant', handler: this.applyFuncToEachWithInput('mostDeviant', "Draw the ___ metrics with the highest standard deviation")},
         {text: 'Standard Deviation', handler: this.applyFuncToEachWithInput('stdev', "Draw the standard deviation for the last _ data points")},
         {text: 'Offset', handler: this.applyFuncToEachWithInput('offset', "Draw the graph with an offset of _")},
+ {text: 'Keep Last Value', handler: this.applyFuncToEach('keepLastValue')},
         {text: 'Remove Outer Call', handler: this.removeOuterCall.createDelegate(this)}
       ]
     });
diff --git a/functions.py b/functions.py
index d18315c..9c0da17 100644
--- a/functions.py
+++ b/functions.py
@@ -93,6 +93,15 @@ def averageSeries(*seriesLists):
   series.pathExpression = name
   return [series]

+def keepLastValue(seriesList):
+ for series in seriesList:
+ series.name = "keepLastValue(%s)" % (series.name)
+ for i,value in enumerate(series):
+ if value is None:
+ value = series[i-1]
+ series[i] = value
+ return seriesList
+
 def asPercent(seriesList1,seriesList2orNumber):
   assert len(seriesList1) == 1, "asPercent series arguments must reference *exactly* 1 series"
   series1 = seriesList1[0]
@@ -264,4 +273,5 @@ SeriesFunctions = {
   'mostDeviant' : mostDeviant,
   'stdev' : stdev,
   'offset' : offset,
+ 'keepLastValue' : keepLastValue,
 }

Revision history for this message
kraig (kamador) wrote :

commited in 121

Changed in graphite:
assignee: nobody → kraig (kamador)
status: New → Fix Committed
Revision history for this message
chrismd (chrismd) wrote :

Thanks for the patch kraig, this does look like a very useful function!

kraig (kamador)
Changed in graphite:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.