long c;
for( rd = st->dimensions, c = 0 ; rd && c < dimensions ; rd = rd->next, c++) {
last_values[c] = 0;
- group_values[c] = 0;
+ group_values[c] = (group_method == GROUP_MAX || group_method == GROUP_MIN)?NAN:0;
group_counts[c] = 0;
group_options[c] = 0;
found_non_zero[c] = 0;
group_options[c] |= RRDR_RESET;
switch(group_method) {
+ case GROUP_MIN:
+ if(unlikely(isnan(group_values[c])) ||
+ fabsl(value) < fabsl(group_values[c]))
+ group_values[c] = value;
+ break;
+
case GROUP_MAX:
- if(unlikely(fabsl(value) > fabsl(group_values[c])))
+ if(unlikely(isnan(group_values[c])) ||
+ fabsl(value) > fabsl(group_values[c]))
group_values[c] = value;
break;
default:
case GROUP_SUM:
case GROUP_AVERAGE:
+ case GROUP_UNDEFINED:
group_values[c] += value;
break;
if(unlikely(group_counts[c] == 0)) {
cn[c] = 0.0;
co[c] |= RRDR_EMPTY;
- }
- else if(unlikely(group_method == GROUP_AVERAGE)) {
- // GROUP_AVERAGE
- cn[c] = group_values[c] / group_counts[c];
+ group_values[c] = (group_method == GROUP_MAX || group_method == GROUP_MIN)?NAN:0;
}
else {
- // GROUP_SUM
- // GROUP_MAX
- // GROUP_INCREMENTAL_SUM
- cn[c] = group_values[c];
- }
+ switch(group_method) {
+ case GROUP_MIN:
+ case GROUP_MAX:
+ if(unlikely(isnan(group_values[c])))
+ cn[c] = 0;
+ else {
+ cn[c] = group_values[c];
+ group_values[c] = NAN;
+ }
+ break;
+
+ case GROUP_SUM:
+ case GROUP_INCREMENTAL_SUM:
+ cn[c] = group_values[c];
+ group_values[c] = 0;
+ break;
+
+ default:
+ case GROUP_AVERAGE:
+ case GROUP_UNDEFINED:
+ cn[c] = group_values[c] / group_counts[c];
+ group_values[c] = 0;
+ break;
+ }
- if(cn[c] < r->min) r->min = cn[c];
- if(cn[c] > r->max) r->max = cn[c];
+ if(cn[c] < r->min) r->min = cn[c];
+ if(cn[c] > r->max) r->max = cn[c];
+ }
- // reset them for the next loop
- group_values[c] = 0;
+ // reset for the next loop
group_counts[c] = 0;
group_options[c] = 0;
}
#define DATASOURCE_FORMAT_SSV_COMMA "ssvcomma"
#define DATASOURCE_FORMAT_CSV_JSON_ARRAY "csvjsonarray"
-#define GROUP_AVERAGE 0
-#define GROUP_MAX 1
-#define GROUP_SUM 2
-#define GROUP_INCREMENTAL_SUM 3
+#define GROUP_UNDEFINED 0
+#define GROUP_AVERAGE 1
+#define GROUP_MIN 2
+#define GROUP_MAX 3
+#define GROUP_SUM 4
+#define GROUP_INCREMENTAL_SUM 5
#define RRDR_OPTION_NONZERO 0x00000001 // don't output dimensions will just zero values
#define RRDR_OPTION_REVERSED 0x00000002 // output the rows in reverse order (oldest to newest)
int web_client_api_request_v1_data_group(char *name, int def)
{
- if(!strcmp(name, "max"))
- return GROUP_MAX;
-
- else if(!strcmp(name, "average"))
+ if(!strcmp(name, "average"))
return GROUP_AVERAGE;
+ else if(!strcmp(name, "min"))
+ return GROUP_MIN;
+
+ else if(!strcmp(name, "max"))
+ return GROUP_MAX;
+
else if(!strcmp(name, "sum"))
return GROUP_SUM;
default: 20
- name: group
in: query
- description: 'The grouping method. If multiple collected values are to be grouped in order to return fewer points, this parameters defines the method of grouping. 4 methods are supported, "max", "average", "sum", "incremental-sum". "max" is actually calculated on the absolute value collected (so it works for both positive and negative dimesions to return the most extreme value in either direction).'
+ description: 'The grouping method. If multiple collected values are to be grouped in order to return fewer points, this parameters defines the method of grouping. methods supported "min", "max", "average", "sum", "incremental-sum". "max" is actually calculated on the absolute value collected (so it works for both positive and negative dimesions to return the most extreme value in either direction).'
required: true
type: string
- enum: [ 'max', 'average', 'sum', 'incremental-sum' ]
+ enum: [ 'min', 'max', 'average', 'sum', 'incremental-sum' ]
default: 'average'
allowEmptyValue: false
- name: format
default: 0
- name: group
in: query
- description: 'The grouping method. If multiple collected values are to be grouped in order to return fewer points, this parameters defines the method of grouping. 4 methods are supported, "max", "average", "sum", "incremental-sum". "max" is actually calculated on the absolute value collected (so it works for both positive and negative dimesions to return the most extreme value in either direction).'
+ description: 'The grouping method. If multiple collected values are to be grouped in order to return fewer points, this parameters defines the method of grouping. methods are supported "min", "max", "average", "sum", "incremental-sum". "max" is actually calculated on the absolute value collected (so it works for both positive and negative dimesions to return the most extreme value in either direction).'
required: true
type: string
- enum: [ 'max', 'average', 'sum', 'incremental-sum' ]
+ enum: [ 'min', 'max', 'average', 'sum', 'incremental-sum' ]
default: 'average'
allowEmptyValue: false
- name: options