Hi!

Attatched now also a patch that not only does a AVG but also a SUM...
This might help you, George...

Ciao,
      Martin

P.s: Tob, this time it includes a patch to the documentation as well ;-)

Martin Sperl wrote:
Hi!

I remember submitting a patch to Tobi that defines a CDEF called AVG, that does ignore NULL values. I now did check if this is in the SVN branch and I can confirm this is included.
Maybe this is what you can use...

Martin

P.s: I remember having used a very complex CDEF to work around this for just 4 values and the patch to rrdtool was much shorter ;)

--- src/rrd_rpncalc.h.org       2007-02-10 20:51:48.000000000 +0000
+++ src/rrd_rpncalc.h   2007-02-10 20:52:10.000000000 +0000
@@ -18,7 +18,7 @@
            OP_UN,OP_END,OP_LTIME,OP_NE,OP_ISINF,OP_PREV_OTHER,OP_COUNT,
            OP_ATAN,OP_SQRT,OP_SORT,OP_REV,OP_TREND,
            OP_ATAN2,OP_RAD2DEG,OP_DEG2RAD,
-           OP_AVG};
+           OP_AVG,OP_SUM};

 typedef struct rpnp_t {
     enum op_en   op;
--- src/rrd_rpncalc.c.org       2007-02-10 20:51:55.000000000 +0000
+++ src/rrd_rpncalc.c   2007-02-10 20:54:59.000000000 +0000
@@ -162,6 +162,7 @@
          add_op(OP_RAD2DEG,RAD2DEG)
          add_op(OP_DEG2RAD,DEG2RAD)
          add_op(OP_AVG,AVG)
+         add_op(OP_SUM,SUM)
 #undef add_op
               }
     (*str)[offset] = '\0';
@@ -340,6 +341,7 @@
        match_op(OP_RAD2DEG,RAD2DEG)
        match_op(OP_DEG2RAD,DEG2RAD)
        match_op(OP_AVG,AVG)
+       match_op(OP_SUM,SUM)
 #undef match_op


@@ -779,6 +781,28 @@
                    }
                 }
                 break;
+           case OP_SUM:
+               stackunderflow(0);
+                {
+                   int i=rpnstack -> s[stptr--];
+                   double sum=0;
+                   int count=0;
+                   stackunderflow(i-1);
+                   while(i>0) {
+                     double val=rpnstack -> s[stptr--];
+                     i--;
+                     if (isnan(val)) { continue; }
+                     count++;
+                     sum+=val;
+                   }
+                   // now push the result bavk on stack
+                   if (count>0) {
+                     rpnstack -> s[++stptr]=sum;
+                   } else {
+                     rpnstack -> s[++stptr]=DNAN;
+                   }
+                }
+                break;
            case OP_END:
                break;
        }
--- doc/rrdgraph_rpn.pod.orig   2007-02-10 20:57:27.000000000 +0000
+++ doc/rrdgraph_rpn.pod        2007-02-10 20:58:12.000000000 +0000
@@ -146,6 +146,13 @@

 Example: C<CDEF:x=a,b,c,d,4,AVG>

+B<SUM>
+
+Pop one element (I<count>) from the stack. Now pop I<count> elements and build 
the
+sum, ignoring all UNKNOWN values in the process.
+
+Example: C<CDEF:x=a,b,c,d,4,SUM>
+
 B<TREND>

 Create a "sliding window" average of another data series.

_______________________________________________
rrd-users mailing list
[email protected]
https://lists.oetiker.ch/cgi-bin/listinfo/rrd-users

Reply via email to