Added initial metric functions processing.
This commit is contained in:
@@ -10,6 +10,7 @@ function (angular, _, moment, utils) {
|
|||||||
var module = angular.module('grafana.services');
|
var module = angular.module('grafana.services');
|
||||||
|
|
||||||
module.service('DataProcessingService', function() {
|
module.service('DataProcessingService', function() {
|
||||||
|
var self = this;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Downsample datapoints series
|
* Downsample datapoints series
|
||||||
@@ -105,5 +106,20 @@ function (angular, _, moment, utils) {
|
|||||||
return _.max(values);
|
return _.max(values);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.aggregationFunctions = {
|
||||||
|
avg: this.AVERAGE,
|
||||||
|
min: this.MIN,
|
||||||
|
max: this.MAX,
|
||||||
|
};
|
||||||
|
|
||||||
|
this.groupByWrapper = function(interval, groupFunc, datapoints) {
|
||||||
|
var groupByCallback = self.aggregationFunctions[groupFunc];
|
||||||
|
return self.groupBy(interval, groupByCallback, datapoints);
|
||||||
|
};
|
||||||
|
|
||||||
|
this.metricFunctions = {
|
||||||
|
groupBy: this.groupByWrapper,
|
||||||
|
};
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -153,6 +153,15 @@ function (angular, _, dateMath, utils) {
|
|||||||
timeseries.datapoints = dp;
|
timeseries.datapoints = dp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var functions = _.map(target.functions, function(func) {
|
||||||
|
return func.bindFunction(DataProcessingService.metricFunctions);
|
||||||
|
});
|
||||||
|
if (functions.length) {
|
||||||
|
//console.log(functions);
|
||||||
|
dp = functions[0](dp);
|
||||||
|
timeseries.datapoints = dp;
|
||||||
|
}
|
||||||
|
|
||||||
return timeseries;
|
return timeseries;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -103,6 +103,21 @@ function (_, $) {
|
|||||||
this.updateText();
|
this.updateText();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FuncInstance.prototype.bindFunction = function(metricFunctions) {
|
||||||
|
var func = metricFunctions[this.def.name];
|
||||||
|
if (func) {
|
||||||
|
|
||||||
|
// Bind function arguments
|
||||||
|
var bindedFunc = func;
|
||||||
|
for (var i = 0; i < this.params.length; i++) {
|
||||||
|
bindedFunc = _.partial(bindedFunc, this.params[i]);
|
||||||
|
}
|
||||||
|
return bindedFunc;
|
||||||
|
} else {
|
||||||
|
throw { message: 'Method not found ' + this.def.name };
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
FuncInstance.prototype.render = function(metricExp) {
|
FuncInstance.prototype.render = function(metricExp) {
|
||||||
var str = this.def.name + '(';
|
var str = this.def.name + '(';
|
||||||
var parameters = _.map(this.params, function(value, index) {
|
var parameters = _.map(this.params, function(value, index) {
|
||||||
|
|||||||
@@ -262,6 +262,7 @@ define([
|
|||||||
|
|
||||||
$scope.targetChanged = function() {
|
$scope.targetChanged = function() {
|
||||||
console.log($scope.target.functions);
|
console.log($scope.target.functions);
|
||||||
|
$scope.get_data();
|
||||||
};
|
};
|
||||||
|
|
||||||
// Validate target and set validation info
|
// Validate target and set validation info
|
||||||
|
|||||||
Reference in New Issue
Block a user