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.verplant.org/?a=commitdiff_plain;h=c6bbce5f7558012214b35a712b4953f1121f849d;p=rrdtool.git added STDEV aggregation function for VDEF. -- Patrick J Cherry patrick bytemark.co.uk git-svn-id: svn://svn.oetiker.ch/rrdtool/trunk/program@1201 a5681a0c-68f1-0310-ab6d-d61299d08faa --- diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 54a6a6c..a44edcb 100644 --- a/CONTRIBUTORS +++ b/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/doc/rrdgraph_rpn.pod b/doc/rrdgraph_rpn.pod index cf62c08..3718349 100644 --- a/doc/rrdgraph_rpn.pod +++ b/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/src/rrd_graph.c b/src/rrd_graph.c index 348a5a5..b624171 100644 --- a/src/rrd_graph.c +++ b/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/src/rrd_graph.h b/src/rrd_graph.h index 00ab15b..dd13237 100644 --- a/src/rrd_graph.h +++ b/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 */