From: Florian Forster Date: Fri, 24 Dec 2010 09:17:08 +0000 (+0100) Subject: "instance_data_json" action: Implement the "resolution" parameter. X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=3fbe261b1de541590f5d3be1bef49b3b3605f392;p=collection4.git "instance_data_json" action: Implement the "resolution" parameter. --- diff --git a/share/collection.js b/share/collection.js index e071f2f..7bcdc54 100644 --- a/share/collection.js +++ b/share/collection.js @@ -428,7 +428,7 @@ function inst_fetch_data (inst, begin, end) /* {{{ */ params.action = "instance_data_json"; params.begin = begin || inst.begin; params.end = end || inst.end; - params.resolution = Math.round ((params.end - params.begin) / c4.config.width); + params.resolution = (params.end - params.begin) / c4.config.width; $.getJSON ("collection.fcgi", params, function (data) diff --git a/src/action_instance_data_json.c b/src/action_instance_data_json.c index 53823f3..a2de10e 100644 --- a/src/action_instance_data_json.c +++ b/src/action_instance_data_json.c @@ -48,6 +48,29 @@ static void write_callback (__attribute__((unused)) void *ctx, /* {{{ */ fwrite ((void *) str, /* size = */ len, /* nmemb = */ 1, stdout); } /* }}} void write_callback */ +static int param_get_resolution (dp_time_t *resolution) /* {{{ */ +{ + const char *tmp; + char *endptr; + double value; + + tmp = param ("resolution"); + if (tmp == NULL) + return (ENOENT); + + errno = 0; + endptr = NULL; + value = strtod (tmp, &endptr); + if (errno != 0) + return (errno); + else if ((value <= 0.0) || (endptr == tmp)) + return (EINVAL); + + resolution->tv_sec = (time_t) value; + resolution->tv_nsec = (long) ((value - ((double) resolution->tv_sec)) * 1000000000.0); + return (0); +} /* }}} int param_get_resolution */ + int action_instance_data_json (void) /* {{{ */ { graph_config_t *cfg; @@ -59,6 +82,7 @@ int action_instance_data_json (void) /* {{{ */ dp_time_t dp_begin = { 0, 0 }; dp_time_t dp_end = { 0, 0 }; + dp_time_t dp_resolution = { 0, 0 }; yajl_gen_config handler_config; yajl_gen handler; @@ -86,6 +110,9 @@ int action_instance_data_json (void) /* {{{ */ dp_end.tv_sec = tt_end; dp_end.tv_nsec = 0; + dp_resolution.tv_sec = (tt_end - tt_begin) / 324; + param_get_resolution (&dp_resolution); + memset (&handler_config, 0, sizeof (handler_config)); handler_config.beautify = 0; handler_config.indentString = " "; @@ -114,7 +141,7 @@ int action_instance_data_json (void) /* {{{ */ printf ("\n"); status = inst_data_to_json (inst, - dp_begin, dp_end, handler); + dp_begin, dp_end, dp_resolution, handler); yajl_gen_free (handler); diff --git a/src/graph_ident.c b/src/graph_ident.c index 02e1aaa..abf396d 100644 --- a/src/graph_ident.c +++ b/src/graph_ident.c @@ -33,6 +33,7 @@ #include #include #include +#include #include "graph_ident.h" #include "common.h" @@ -545,6 +546,7 @@ struct ident_data_to_json__data_s { dp_time_t begin; dp_time_t end; + dp_time_t interval; yajl_gen handler; }; typedef struct ident_data_to_json__data_s ident_data_to_json__data_t; @@ -564,21 +566,21 @@ static int ident_data_to_json__get_ident_data ( double first_value_time_double; double interval_double; - - /* TODO: Make points_num_limit configurable. */ - /* points_num_limit: The number of data-points to send at least. */ - size_t points_num_limit = 400; + double interval_requested; size_t points_consolidate; first_value_time_double = ((double) first_value_time.tv_sec) + (((double) first_value_time.tv_nsec) / 1000000000.0); interval_double = ((double) interval.tv_sec) + (((double) interval.tv_nsec) / 1000000000.0); + interval_requested = ((double) data->interval.tv_sec) + + (((double) data->interval.tv_nsec) / 1000000000.0); - if (data_points_num <= points_num_limit) + if (interval_requested < (2.0 * interval_double)) points_consolidate = 1; else - points_consolidate = data_points_num / points_num_limit; + points_consolidate = (size_t) (interval_requested / interval_double); + assert (points_consolidate >= 1); if (points_consolidate > 1) { @@ -654,7 +656,7 @@ static int ident_data_to_json__get_ds_name (graph_ident_t *ident, /* {{{ */ } /* }}} int ident_data_to_json__get_ds_name */ int ident_data_to_json (graph_ident_t *ident, /* {{{ */ - dp_time_t begin, dp_time_t end, + dp_time_t begin, dp_time_t end, dp_time_t res, yajl_gen handler) { ident_data_to_json__data_t data; @@ -662,6 +664,7 @@ int ident_data_to_json (graph_ident_t *ident, /* {{{ */ data.begin = begin; data.end = end; + data.interval = res; data.handler = handler; /* Iterate over all DS names */ diff --git a/src/graph_ident.h b/src/graph_ident.h index 5f7b2d4..9cbd08a 100644 --- a/src/graph_ident.h +++ b/src/graph_ident.h @@ -93,7 +93,7 @@ char *ident_to_file (const graph_ident_t *ident); int ident_to_json (const graph_ident_t *ident, yajl_gen handler); int ident_data_to_json (graph_ident_t *ident, - dp_time_t begin, dp_time_t end, + dp_time_t begin, dp_time_t end, dp_time_t interval, yajl_gen handler); int ident_describe (const graph_ident_t *ident, const graph_ident_t *selector, diff --git a/src/graph_instance.c b/src/graph_instance.c index 2249cc0..f2bb3ba 100644 --- a/src/graph_instance.c +++ b/src/graph_instance.c @@ -605,14 +605,14 @@ int inst_to_json (const graph_instance_t *inst, /* {{{ */ } /* }}} int inst_to_json */ int inst_data_to_json (const graph_instance_t *inst, /* {{{ */ - dp_time_t begin, dp_time_t end, + dp_time_t begin, dp_time_t end, dp_time_t res, yajl_gen handler) { size_t i; yajl_gen_array_open (handler); for (i = 0; i < inst->files_num; i++) - ident_data_to_json (inst->files[i], begin, end, handler); + ident_data_to_json (inst->files[i], begin, end, res, handler); yajl_gen_array_close (handler); return (0); diff --git a/src/graph_instance.h b/src/graph_instance.h index 5685853..37c6b69 100644 --- a/src/graph_instance.h +++ b/src/graph_instance.h @@ -86,7 +86,7 @@ _Bool inst_matches_field (graph_instance_t *inst, int inst_to_json (const graph_instance_t *inst, yajl_gen handler); int inst_data_to_json (const graph_instance_t *inst, - dp_time_t begin, dp_time_t end, + dp_time_t begin, dp_time_t end, dp_time_t res, yajl_gen handler); int inst_describe (graph_config_t *cfg, graph_instance_t *inst,