From: oetiker Date: Sat, 8 Sep 2007 05:23:23 +0000 (+0000) Subject: added STDEV aggregation function for VDEF. -- Patrick J Cherry patrick bytemark.co.uk X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=21b3ca8cfe6df4b08e98190dcf7296b9a7f877a7;p=rrdtool-all.git added STDEV aggregation function for VDEF. -- Patrick J Cherry patrick bytemark.co.uk git-svn-id: svn://svn.oetiker.ch/rrdtool/trunk@1201 a5681a0c-68f1-0310-ab6d-d61299d08faa --- diff --git a/program/CONTRIBUTORS b/program/CONTRIBUTORS index 54a6a6ce..a44edcb5 100644 --- a/program/CONTRIBUTORS +++ b/program/CONTRIBUTORS @@ -38,6 +38,7 @@ Mike Mitchell Mike Slifcak many rrdtool-1.1.x fixes Oleg Cherevko Otmar Lendl (lots of bugfixes) +Patrick Cherry Paul Joslin Peter Speck eps/svg/pdf file format code in rrdtool-1.x Peter Stamfest initial multi-thread support diff --git a/program/doc/rrdgraph_rpn.pod b/program/doc/rrdgraph_rpn.pod index cf62c080..3718349c 100644 --- a/program/doc/rrdgraph_rpn.pod +++ b/program/doc/rrdgraph_rpn.pod @@ -257,6 +257,12 @@ the first occurrence of that value in the time component. Example: C +=item STDEV + +Returns the standard deviation of the values. + +Example: C + =item LAST, FIRST Return the last/first value including its time. The time for diff --git a/program/src/rrd_graph.c b/program/src/rrd_graph.c index 348a5a5e..b624171c 100644 --- a/program/src/rrd_graph.c +++ b/program/src/rrd_graph.c @@ -4285,6 +4285,8 @@ int vdef_parse( gdes->vf.op = VDEF_MAXIMUM; else if (!strcmp("AVERAGE", func)) gdes->vf.op = VDEF_AVERAGE; + else if (!strcmp("STDEV", func)) + gdes->vf.op = VDEF_STDEV; else if (!strcmp("MINIMUM", func)) gdes->vf.op = VDEF_MINIMUM; else if (!strcmp("TOTAL", func)) @@ -4324,6 +4326,7 @@ int vdef_parse( break; case VDEF_MAXIMUM: case VDEF_AVERAGE: + case VDEF_STDEV: case VDEF_MINIMUM: case VDEF_TOTAL: case VDEF_FIRST: @@ -4412,9 +4415,11 @@ int vdef_calc( } break; case VDEF_TOTAL: + case VDEF_STDEV: case VDEF_AVERAGE:{ int cnt = 0; double sum = 0.0; + double average = 0.0; for (step = 0; step < steps; step++) { if (finite(data[step * src->ds_cnt])) { @@ -4426,9 +4431,19 @@ int vdef_calc( if (dst->vf.op == VDEF_TOTAL) { dst->vf.val = sum * src->step; dst->vf.when = 0; /* no time component */ - } else { + } else if (dst->vf.op == VDEF_AVERAGE){ dst->vf.val = sum / cnt; dst->vf.when = 0; /* no time component */ + } else { + average = sum / cnt; + sum = 0.0; + for (step=0;stepds_cnt])) { + sum += pow((data[step*src->ds_cnt] - average),2.0); + }; + } + dst->vf.val = pow(sum / cnt,0.5); + dst->vf.when = 0; /* no time component */ }; } else { dst->vf.val = DNAN; diff --git a/program/src/rrd_graph.h b/program/src/rrd_graph.h index 00ab15ba..dd132378 100644 --- a/program/src/rrd_graph.h +++ b/program/src/rrd_graph.h @@ -54,6 +54,7 @@ enum vdef_op_en { VDEF_MAXIMUM = 0 /* like the MAX in (G)PRINT */ , VDEF_MINIMUM /* like the MIN in (G)PRINT */ , VDEF_AVERAGE /* like the AVERAGE in (G)PRINT */ + , VDEF_STDEV /* the standard deviation */ , VDEF_PERCENT /* Nth percentile */ , VDEF_TOTAL /* average multiplied by time */ , VDEF_FIRST /* first non-unknown value and time */