diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2022-06-09 04:52:39 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2022-06-09 04:52:39 +0000 |
commit | 89f3604407aff8f4cb2ed958252c61e23c767e24 (patch) | |
tree | 7fbf408102cab051557d38193524d8c6e991d070 /web/api/queries/stddev | |
parent | Adding upstream version 1.34.1. (diff) | |
download | netdata-89f3604407aff8f4cb2ed958252c61e23c767e24.tar.xz netdata-89f3604407aff8f4cb2ed958252c61e23c767e24.zip |
Adding upstream version 1.35.0.upstream/1.35.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'web/api/queries/stddev')
-rw-r--r-- | web/api/queries/stddev/stddev.c | 31 | ||||
-rw-r--r-- | web/api/queries/stddev/stddev.h | 2 |
2 files changed, 15 insertions, 18 deletions
diff --git a/web/api/queries/stddev/stddev.c b/web/api/queries/stddev/stddev.c index 16258445c..ffe7a47c0 100644 --- a/web/api/queries/stddev/stddev.c +++ b/web/api/queries/stddev/stddev.c @@ -14,9 +14,8 @@ struct grouping_stddev { calculated_number m_oldM, m_newM, m_oldS, m_newS; }; -void *grouping_create_stddev(RRDR *r) { - UNUSED (r); - return callocz(1, sizeof(struct grouping_stddev)); +void grouping_create_stddev(RRDR *r) { + r->internal.grouping_data = callocz(1, sizeof(struct grouping_stddev)); } // resets when switches dimensions @@ -34,22 +33,20 @@ void grouping_free_stddev(RRDR *r) { void grouping_add_stddev(RRDR *r, calculated_number value) { struct grouping_stddev *g = (struct grouping_stddev *)r->internal.grouping_data; - if(calculated_number_isnumber(value)) { - g->count++; + g->count++; - // See Knuth TAOCP vol 2, 3rd edition, page 232 - if (g->count == 1) { - g->m_oldM = g->m_newM = value; - g->m_oldS = 0.0; - } - else { - g->m_newM = g->m_oldM + (value - g->m_oldM) / g->count; - g->m_newS = g->m_oldS + (value - g->m_oldM) * (value - g->m_newM); + // See Knuth TAOCP vol 2, 3rd edition, page 232 + if (g->count == 1) { + g->m_oldM = g->m_newM = value; + g->m_oldS = 0.0; + } + else { + g->m_newM = g->m_oldM + (value - g->m_oldM) / g->count; + g->m_newS = g->m_oldS + (value - g->m_oldM) * (value - g->m_newM); - // set up for next iteration - g->m_oldM = g->m_newM; - g->m_oldS = g->m_newS; - } + // set up for next iteration + g->m_oldM = g->m_newM; + g->m_oldS = g->m_newS; } } diff --git a/web/api/queries/stddev/stddev.h b/web/api/queries/stddev/stddev.h index 7a4697572..ab58fbe50 100644 --- a/web/api/queries/stddev/stddev.h +++ b/web/api/queries/stddev/stddev.h @@ -6,7 +6,7 @@ #include "../query.h" #include "../rrdr.h" -extern void *grouping_create_stddev(RRDR *r); +extern void grouping_create_stddev(RRDR *r); extern void grouping_reset_stddev(RRDR *r); extern void grouping_free_stddev(RRDR *r); extern void grouping_add_stddev(RRDR *r, calculated_number value); |