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/des | |
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/des')
-rw-r--r-- | web/api/queries/des/des.c | 40 | ||||
-rw-r--r-- | web/api/queries/des/des.h | 2 |
2 files changed, 20 insertions, 22 deletions
diff --git a/web/api/queries/des/des.c b/web/api/queries/des/des.c index c6236f31a..8e4ca4bd4 100644 --- a/web/api/queries/des/des.c +++ b/web/api/queries/des/des.c @@ -69,14 +69,14 @@ static inline void set_beta(RRDR *r, struct grouping_des *g) { //info("beta for chart '%s' is " CALCULATED_NUMBER_FORMAT, r->st->name, g->beta); } -void *grouping_create_des(RRDR *r) { - struct grouping_des *g = (struct grouping_des *)malloc(sizeof(struct grouping_des)); +void grouping_create_des(RRDR *r) { + struct grouping_des *g = (struct grouping_des *)mallocz(sizeof(struct grouping_des)); set_alpha(r, g); set_beta(r, g); g->level = 0.0; g->trend = 0.0; g->count = 0; - return g; + r->internal.grouping_data = g; } // resets when switches dimensions @@ -99,28 +99,26 @@ void grouping_free_des(RRDR *r) { void grouping_add_des(RRDR *r, calculated_number value) { struct grouping_des *g = (struct grouping_des *)r->internal.grouping_data; - if(calculated_number_isnumber(value)) { - if(likely(g->count > 0)) { - // we have at least a number so far + if(likely(g->count > 0)) { + // we have at least a number so far - if(unlikely(g->count == 1)) { - // the second value we got - g->trend = value - g->trend; - g->level = value; - } - - // for the values, except the first - calculated_number last_level = g->level; - g->level = (g->alpha * value) + (g->alpha_other * (g->level + g->trend)); - g->trend = (g->beta * (g->level - last_level)) + (g->beta_other * g->trend); - } - else { - // the first value we got - g->level = g->trend = value; + if(unlikely(g->count == 1)) { + // the second value we got + g->trend = value - g->trend; + g->level = value; } - g->count++; + // for the values, except the first + calculated_number last_level = g->level; + g->level = (g->alpha * value) + (g->alpha_other * (g->level + g->trend)); + g->trend = (g->beta * (g->level - last_level)) + (g->beta_other * g->trend); } + else { + // the first value we got + g->level = g->trend = value; + } + + g->count++; //fprintf(stderr, "value: " CALCULATED_NUMBER_FORMAT ", level: " CALCULATED_NUMBER_FORMAT ", trend: " CALCULATED_NUMBER_FORMAT "\n", value, g->level, g->trend); } diff --git a/web/api/queries/des/des.h b/web/api/queries/des/des.h index 360513e9c..bd361b865 100644 --- a/web/api/queries/des/des.h +++ b/web/api/queries/des/des.h @@ -8,7 +8,7 @@ extern void grouping_init_des(void); -extern void *grouping_create_des(RRDR *r); +extern void grouping_create_des(RRDR *r); extern void grouping_reset_des(RRDR *r); extern void grouping_free_des(RRDR *r); extern void grouping_add_des(RRDR *r, calculated_number value); |