Added aggregateBy() function with aggregation type as parameter.
This commit is contained in:
@@ -147,6 +147,13 @@ export default class DataProcessor {
|
|||||||
return DataProcessor.groupBy(interval, groupByCallback, datapoints);
|
return DataProcessor.groupBy(interval, groupByCallback, datapoints);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static aggregateByWrapper(interval, aggregateFunc, datapoints) {
|
||||||
|
// Flatten all points in frame and then just use groupBy()
|
||||||
|
var flattenedPoints = _.flatten(datapoints, true);
|
||||||
|
var groupByCallback = DataProcessor.aggregationFunctions[aggregateFunc];
|
||||||
|
return DataProcessor.groupBy(interval, groupByCallback, flattenedPoints);
|
||||||
|
}
|
||||||
|
|
||||||
static aggregateWrapper(groupByCallback, interval, datapoints) {
|
static aggregateWrapper(groupByCallback, interval, datapoints) {
|
||||||
var flattenedPoints = _.flatten(datapoints, true);
|
var flattenedPoints = _.flatten(datapoints, true);
|
||||||
return DataProcessor.groupBy(interval, groupByCallback, flattenedPoints);
|
return DataProcessor.groupBy(interval, groupByCallback, flattenedPoints);
|
||||||
@@ -164,6 +171,7 @@ export default class DataProcessor {
|
|||||||
static get metricFunctions() {
|
static get metricFunctions() {
|
||||||
return {
|
return {
|
||||||
groupBy: this.groupByWrapper,
|
groupBy: this.groupByWrapper,
|
||||||
|
aggregateBy: this.aggregateByWrapper,
|
||||||
average: _.partial(this.aggregateWrapper, this.AVERAGE),
|
average: _.partial(this.aggregateWrapper, this.AVERAGE),
|
||||||
min: _.partial(this.aggregateWrapper, this.MIN),
|
min: _.partial(this.aggregateWrapper, this.MIN),
|
||||||
max: _.partial(this.aggregateWrapper, this.MAX),
|
max: _.partial(this.aggregateWrapper, this.MAX),
|
||||||
|
|||||||
@@ -73,6 +73,16 @@ addFuncDef({
|
|||||||
defaultParams: ['1m'],
|
defaultParams: ['1m'],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
addFuncDef({
|
||||||
|
name: 'aggregateBy',
|
||||||
|
category: 'Aggregate',
|
||||||
|
params: [
|
||||||
|
{ name: 'interval', type: 'string' },
|
||||||
|
{ name: 'function', type: 'string', options: ['avg', 'min', 'max', 'median'] }
|
||||||
|
],
|
||||||
|
defaultParams: ['1m', 'avg'],
|
||||||
|
});
|
||||||
|
|
||||||
addFuncDef({
|
addFuncDef({
|
||||||
name: 'trendValue',
|
name: 'trendValue',
|
||||||
category: 'Trends',
|
category: 'Trends',
|
||||||
|
|||||||
Reference in New Issue
Block a user