From 6c5fc794f077c9affe6892d24d8e1d5a78956fc6 Mon Sep 17 00:00:00 2001 From: Costa Tsaousis Date: Wed, 24 Oct 2018 23:55:22 +0300 Subject: fix query sum (#4482) * fix sum * added query rsd as an alias of cv --- web/api/queries/query.c | 12 +++++++++++- web/api/queries/stddev/README.md | 4 +++- web/api/queries/sum/sum.c | 7 ++----- 3 files changed, 16 insertions(+), 7 deletions(-) (limited to 'web/api/queries') diff --git a/web/api/queries/query.c b/web/api/queries/query.c index 070b4be9ef..764375932a 100644 --- a/web/api/queries/query.c +++ b/web/api/queries/query.c @@ -145,7 +145,17 @@ static struct { .hash = 0, .value = RRDR_GROUPING_CV, .init = NULL, - .create= grouping_create_stddev, // not an error, stddev calculates this too + .create= grouping_create_stddev, // not an error, stddev calculates this too + .reset = grouping_reset_stddev, // not an error, stddev calculates this too + .free = grouping_free_stddev, // not an error, stddev calculates this too + .add = grouping_add_stddev, // not an error, stddev calculates this too + .flush = grouping_flush_coefficient_of_variation + }, + {.name = "rsd", // alias of 'cv' + .hash = 0, + .value = RRDR_GROUPING_CV, + .init = NULL, + .create= grouping_create_stddev, // not an error, stddev calculates this too .reset = grouping_reset_stddev, // not an error, stddev calculates this too .free = grouping_free_stddev, // not an error, stddev calculates this too .add = grouping_add_stddev, // not an error, stddev calculates this too diff --git a/web/api/queries/stddev/README.md b/web/api/queries/stddev/README.md index a404b49025..3436ff834f 100644 --- a/web/api/queries/stddev/README.md +++ b/web/api/queries/stddev/README.md @@ -41,7 +41,9 @@ Check [https://en.wikipedia.org/wiki/Standard_deviation](https://en.wikipedia.or # Coefficient of variation (`cv`) -The coefficient of variation (`cv``), also known as relative standard deviation (RSD), +> This query is also available as `rsd`. + +The coefficient of variation (`cv`), also known as relative standard deviation (`rsd`), is a standardized measure of dispersion of a probability distribution or frequency distribution. It is defined as the ratio of the **standard deviation** to the **mean**. diff --git a/web/api/queries/sum/sum.c b/web/api/queries/sum/sum.c index ed81156cf3..0da9937a3a 100644 --- a/web/api/queries/sum/sum.c +++ b/web/api/queries/sum/sum.c @@ -31,11 +31,8 @@ void grouping_free_sum(RRDR *r) { void grouping_add_sum(RRDR *r, calculated_number value) { if(!isnan(value)) { struct grouping_sum *g = (struct grouping_sum *)r->internal.grouping_data; - - if(!g->count || calculated_number_fabs(value) > calculated_number_fabs(g->sum)) { - g->sum += value; - g->count++; - } + g->sum += value; + g->count++; } } -- cgit v1.2.3