summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 02b3e17)
raw | patch | inline | side by side (parent: 02b3e17)
author | Florian Forster <octo@verplant.org> | |
Sat, 11 Sep 2010 07:53:23 +0000 (09:53 +0200) | ||
committer | Florian Forster <octo@verplant.org> | |
Sat, 11 Sep 2010 07:53:23 +0000 (09:53 +0200) |
... 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.
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.
src/graph_ident.c | patch | blob | history |
diff --git a/src/graph_ident.c b/src/graph_ident.c
index 7f37035512c273c60df0d3356e40f4869c3e158d..24f89c5e76c2003b8dd2f9dd7bc2c6742df3c084 100644 (file)
--- a/src/graph_ident.c
+++ b/src/graph_ident.c
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);
}