Added aggregation functions processing.
This commit is contained in:
@@ -2,10 +2,9 @@ define([
|
|||||||
'angular',
|
'angular',
|
||||||
'lodash',
|
'lodash',
|
||||||
'moment',
|
'moment',
|
||||||
'./utils',
|
'./utils'
|
||||||
'./metricFunctions'
|
|
||||||
],
|
],
|
||||||
function (angular, _, moment, utils, metricFunctions) {
|
function (angular, _, moment, utils) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var module = angular.module('grafana.services');
|
var module = angular.module('grafana.services');
|
||||||
@@ -118,8 +117,16 @@ function (angular, _, moment, utils, metricFunctions) {
|
|||||||
return self.groupBy(interval, groupByCallback, datapoints);
|
return self.groupBy(interval, groupByCallback, datapoints);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.aggregateWrapper = function(groupByCallback, interval, datapoints) {
|
||||||
|
var flattenedPoints = _.flatten(datapoints, true);
|
||||||
|
return self.groupBy(interval, groupByCallback, flattenedPoints);
|
||||||
|
};
|
||||||
|
|
||||||
this.metricFunctions = {
|
this.metricFunctions = {
|
||||||
groupBy: this.groupByWrapper,
|
groupBy: this.groupByWrapper,
|
||||||
|
average: _.partial(this.aggregateWrapper, this.AVERAGE),
|
||||||
|
min: _.partial(this.aggregateWrapper, this.MIN),
|
||||||
|
max: _.partial(this.aggregateWrapper, this.MAX),
|
||||||
};
|
};
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -144,7 +144,7 @@ function (angular, _, dateMath, utils, metricFunctions) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return getHistory.then(function (timeseries_data) {
|
return getHistory.then(function (timeseries_data) {
|
||||||
return _.map(timeseries_data, function (timeseries) {
|
timeseries_data = _.map(timeseries_data, function (timeseries) {
|
||||||
|
|
||||||
// Filter only transform functions
|
// Filter only transform functions
|
||||||
var transformFunctions = _.map(metricFunctions.getCategories()['Transform'], 'name');
|
var transformFunctions = _.map(metricFunctions.getCategories()['Transform'], 'name');
|
||||||
@@ -164,6 +164,27 @@ function (angular, _, dateMath, utils, metricFunctions) {
|
|||||||
|
|
||||||
return timeseries;
|
return timeseries;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Aggregations
|
||||||
|
var aggregationFunctions = _.map(metricFunctions.getCategories()['Aggregate'], 'name');
|
||||||
|
var aggFuncDefs = _.filter(target.functions, function(func) {
|
||||||
|
return _.contains(aggregationFunctions, func.def.name);
|
||||||
|
});
|
||||||
|
var functions = _.map(aggFuncDefs, function(func) {
|
||||||
|
return func.bindFunction(DataProcessingService.metricFunctions);
|
||||||
|
});
|
||||||
|
var dp = _.map(timeseries_data, 'datapoints');
|
||||||
|
|
||||||
|
if (functions.length) {
|
||||||
|
for (var i = 0; i < functions.length; i++) {
|
||||||
|
dp = functions[i](dp);
|
||||||
|
}
|
||||||
|
timeseries_data = {
|
||||||
|
target: 'agg',
|
||||||
|
datapoints: dp
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return timeseries_data;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -219,9 +240,9 @@ function (angular, _, dateMath, utils, metricFunctions) {
|
|||||||
return $q.all(_.flatten(promises))
|
return $q.all(_.flatten(promises))
|
||||||
.then(_.flatten)
|
.then(_.flatten)
|
||||||
.then(function (timeseries_data) {
|
.then(function (timeseries_data) {
|
||||||
var data = _.map(timeseries_data, function(timeseries) {
|
|
||||||
|
|
||||||
// Series downsampling
|
// Series downsampling
|
||||||
|
var data = _.map(timeseries_data, function(timeseries) {
|
||||||
var DPS = DataProcessingService;
|
var DPS = DataProcessingService;
|
||||||
if (timeseries.datapoints.length > options.maxDataPoints) {
|
if (timeseries.datapoints.length > options.maxDataPoints) {
|
||||||
timeseries.datapoints = DPS.groupBy(options.interval, DPS.AVERAGE, timeseries.datapoints);
|
timeseries.datapoints = DPS.groupBy(options.interval, DPS.AVERAGE, timeseries.datapoints);
|
||||||
|
|||||||
@@ -65,10 +65,37 @@ function (_, $) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
addFuncDef({
|
addFuncDef({
|
||||||
name: "holtWintersConfidenceBands",
|
name: 'sum',
|
||||||
category: categories.Aggregate,
|
category: categories.Aggregate,
|
||||||
params: [{ name: "delta", type: 'int' }],
|
params: [],
|
||||||
defaultParams: [3]
|
defaultParams: [],
|
||||||
|
});
|
||||||
|
|
||||||
|
addFuncDef({
|
||||||
|
name: 'average',
|
||||||
|
category: categories.Aggregate,
|
||||||
|
params: [
|
||||||
|
{ name: 'interval', type: 'string' }
|
||||||
|
],
|
||||||
|
defaultParams: ['1m'],
|
||||||
|
});
|
||||||
|
|
||||||
|
addFuncDef({
|
||||||
|
name: 'min',
|
||||||
|
category: categories.Aggregate,
|
||||||
|
params: [
|
||||||
|
{ name: 'interval', type: 'string' }
|
||||||
|
],
|
||||||
|
defaultParams: ['1m'],
|
||||||
|
});
|
||||||
|
|
||||||
|
addFuncDef({
|
||||||
|
name: 'max',
|
||||||
|
category: categories.Aggregate,
|
||||||
|
params: [
|
||||||
|
{ name: 'interval', type: 'string' }
|
||||||
|
],
|
||||||
|
defaultParams: ['1m'],
|
||||||
});
|
});
|
||||||
|
|
||||||
addFuncDef({
|
addFuncDef({
|
||||||
|
|||||||
Reference in New Issue
Block a user