From: Florian Forster Date: Sat, 11 Sep 2010 07:53:23 +0000 (+0200) Subject: src/graph_ident.c: ident_data_to_json: Average data points ... X-Git-Tag: v4.0.0~2 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=e0517eecbe0add2e72bef226f6d1bf0f279c9ed0;p=collection4.git src/graph_ident.c: ident_data_to_json: Average data points ... ... to send between 400 and 800 values. This reduces the time taken to receive the values sent by the "instance_data_json" action considerably. We should, however, do this in the data provider function or possibly in the "instance_data_json" action. Also supporting other CFs would be a wise move and while we're scanning the data we might compute total average, minimum and maximum as well. --- diff --git a/src/graph_ident.c b/src/graph_ident.c index 7f37035..24f89c5 100644 --- a/src/graph_ident.c +++ b/src/graph_ident.c @@ -561,16 +561,42 @@ static int ident_data_to_json__get_ident_data ( ident_data_to_json__data_t *data = user_data; size_t i; + /* TODO: Make points_num_limit configurable. */ + /* points_num_limit: The number of data-points to send at least. */ + size_t points_num_limit = 400; + size_t points_consolidate; + + if (dp_num <= points_num_limit) + points_consolidate = 1; + else + points_consolidate = dp_num / points_num_limit; + yajl_gen_array_open (data->handler); - for (i = 0; i < dp_num; i++) + for (i = (dp_num % points_consolidate); i < dp_num; i += points_consolidate) { + size_t j; + + double sum = 0.0; + long num = 0; + yajl_gen_array_open (data->handler); yajl_gen_integer (data->handler, (long) dp[i].time.tv_sec); - if (isnan (dp[i].value)) + + for (j = 0; j < points_consolidate; j++) + { + if (isnan (dp[i+j].value)) + continue; + + sum += dp[i+j].value; + num++; + } + + if (num == 0) yajl_gen_null (data->handler); else - yajl_gen_double (data->handler, dp[i].value); + yajl_gen_double (data->handler, sum / ((double) num)); + yajl_gen_array_close (data->handler); }