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