← Back to team overview

graphite-dev team mailing list archive

[Question #79928]: Continuous lines when no data for teh period

 

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

Hi,

this is to continue discussion from https://answers.launchpad.net/graphite/+question/72090
I'm just re-posting my suggestion from that ticket as that one is solved already. Here it is:

I just faced the same problem and found this ticket. From the attached bug I found out that changes are done and merged, so I tried the trunk code. So the function works, but I think in a rather weird way. Meaning, it does what it's designed for, keeping last value till the new value found, but it makes plot staircased which is I believe not the desired behavior. Would be nice if Graphite could draw a direct line from previous point to the current one, pretending a set of averaged values between those points.

Actually, I've added following diff to the functions to do what I need. Sorry if it looks ugly - this is my first Python code.

=== modified file 'webapp/web/render/functions.py'
--- webapp/web/render/functions.py 2009-08-07 18:05:06 +0000
+++ webapp/web/render/functions.py 2009-08-13 14:25:55 +0000
@@ -22,6 +22,12 @@
   if not safeValues: return None
   return sum(safeValues)

+def safeSub(a,b):
+ if a is None and b is None: return None
+ if a is None: return None
+ if b is None: return a
+ return a - b
+
 def safeDiff(values):
   safeValues = [v for v in values if v is not None]
   if not safeValues: return None
@@ -106,6 +112,27 @@
       series[i] = value
   return seriesList

+def averageLastValue(seriesList):
+ for series in seriesList:
+ series.name = "averageLastValue(%s)" % (series.name)
+ i = 0
+ addition = None
+ series_length = len(series)
+ while i < series_length:
+ value = series[i]
+ if (value is None) and (addition is None) and (i > 0) and (series[i-1] is not None):
+ j = i + 1
+ while (j < series_length) and (addition is None):
+ if series[j] is not None:
+ addition = safeDiv(safeSub(series[j], series[i-1]), j - i)
+ j += 1
+ if (value is None):
+ series[i] = safeSum([series[i-1], addition])
+ else:
+ addition = None
+ i += 1
+ return seriesList
+
 def asPercent(seriesList1,seriesList2orNumber):
   assert len(seriesList1) == 1, "asPercent series arguments must reference *exactly* 1 series"
   series1 = seriesList1[0]
@@ -318,4 +345,5 @@
   'lastAbove' : lastAbove,
   'highestMean' : highestMean,
   'highestLast' : highestLast,
+ 'averageLastValue' : averageLastValue,
 }

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