Added medianBy() aggregation.
This commit is contained in:
@@ -190,6 +190,11 @@ function (angular, _, moment, utils) {
|
||||
return nearestLeft;
|
||||
}
|
||||
|
||||
this.medianBy = function(interval, timeseries) {
|
||||
var flatten_series = _.flatten(timeseries, true);
|
||||
return self.groupBy(interval, self.MEDIAN, flatten_series);
|
||||
};
|
||||
|
||||
this.AVERAGE = function(values) {
|
||||
var sum = 0;
|
||||
_.each(values, function(value) {
|
||||
@@ -206,6 +211,11 @@ function (angular, _, moment, utils) {
|
||||
return _.max(values);
|
||||
};
|
||||
|
||||
this.MEDIAN = function(values) {
|
||||
var sorted = _.sortBy(values);
|
||||
return sorted[Math.floor(sorted.length / 2)];
|
||||
};
|
||||
|
||||
this.setAlias = function(alias, timeseries) {
|
||||
timeseries.target = alias;
|
||||
return timeseries;
|
||||
@@ -215,6 +225,7 @@ function (angular, _, moment, utils) {
|
||||
avg: this.AVERAGE,
|
||||
min: this.MIN,
|
||||
max: this.MAX,
|
||||
median: this.MEDIAN
|
||||
};
|
||||
|
||||
this.groupByWrapper = function(interval, groupFunc, datapoints) {
|
||||
@@ -233,6 +244,7 @@ function (angular, _, moment, utils) {
|
||||
min: _.partial(this.aggregateWrapper, this.MIN),
|
||||
max: _.partial(this.aggregateWrapper, this.MAX),
|
||||
sumSeries: this.sumSeries,
|
||||
medianBy: this.medianBy,
|
||||
setAlias: this.setAlias,
|
||||
};
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ function (_, $) {
|
||||
category: 'Transform',
|
||||
params: [
|
||||
{ name: 'interval', type: 'string'},
|
||||
{ name: 'function', type: 'string', options: ['avg', 'min', 'max'] }
|
||||
{ name: 'function', type: 'string', options: ['avg', 'min', 'max', 'median'] }
|
||||
],
|
||||
defaultParams: ['1m', 'avg'],
|
||||
});
|
||||
@@ -40,6 +40,15 @@ function (_, $) {
|
||||
defaultParams: [],
|
||||
});
|
||||
|
||||
addFuncDef({
|
||||
name: 'medianBy',
|
||||
category: 'Aggregate',
|
||||
params: [
|
||||
{ name: 'interval', type: 'string'}
|
||||
],
|
||||
defaultParams: ['1m'],
|
||||
});
|
||||
|
||||
addFuncDef({
|
||||
name: 'average',
|
||||
category: 'Aggregate',
|
||||
|
||||
Reference in New Issue
Block a user