Added aggregation functions processing.
This commit is contained in:
@@ -2,10 +2,9 @@ define([
|
||||
'angular',
|
||||
'lodash',
|
||||
'moment',
|
||||
'./utils',
|
||||
'./metricFunctions'
|
||||
'./utils'
|
||||
],
|
||||
function (angular, _, moment, utils, metricFunctions) {
|
||||
function (angular, _, moment, utils) {
|
||||
'use strict';
|
||||
|
||||
var module = angular.module('grafana.services');
|
||||
@@ -118,8 +117,16 @@ function (angular, _, moment, utils, metricFunctions) {
|
||||
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 = {
|
||||
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 _.map(timeseries_data, function (timeseries) {
|
||||
timeseries_data = _.map(timeseries_data, function (timeseries) {
|
||||
|
||||
// Filter only transform functions
|
||||
var transformFunctions = _.map(metricFunctions.getCategories()['Transform'], 'name');
|
||||
@@ -164,6 +164,27 @@ function (angular, _, dateMath, utils, metricFunctions) {
|
||||
|
||||
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))
|
||||
.then(_.flatten)
|
||||
.then(function (timeseries_data) {
|
||||
var data = _.map(timeseries_data, function(timeseries) {
|
||||
|
||||
// Series downsampling
|
||||
var data = _.map(timeseries_data, function(timeseries) {
|
||||
var DPS = DataProcessingService;
|
||||
if (timeseries.datapoints.length > options.maxDataPoints) {
|
||||
timeseries.datapoints = DPS.groupBy(options.interval, DPS.AVERAGE, timeseries.datapoints);
|
||||
|
||||
@@ -65,10 +65,37 @@ function (_, $) {
|
||||
});
|
||||
|
||||
addFuncDef({
|
||||
name: "holtWintersConfidenceBands",
|
||||
name: 'sum',
|
||||
category: categories.Aggregate,
|
||||
params: [{ name: "delta", type: 'int' }],
|
||||
defaultParams: [3]
|
||||
params: [],
|
||||
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({
|
||||
|
||||
Reference in New Issue
Block a user