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);
|
||||
}
|
||||
|
||||
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) {
|
||||
var flattenedPoints = _.flatten(datapoints, true);
|
||||
return DataProcessor.groupBy(interval, groupByCallback, flattenedPoints);
|
||||
@@ -164,6 +171,7 @@ export default class DataProcessor {
|
||||
static get metricFunctions() {
|
||||
return {
|
||||
groupBy: this.groupByWrapper,
|
||||
aggregateBy: this.aggregateByWrapper,
|
||||
average: _.partial(this.aggregateWrapper, this.AVERAGE),
|
||||
min: _.partial(this.aggregateWrapper, this.MIN),
|
||||
max: _.partial(this.aggregateWrapper, this.MAX),
|
||||
|
||||
@@ -73,6 +73,16 @@ addFuncDef({
|
||||
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({
|
||||
name: 'trendValue',
|
||||
category: 'Trends',
|
||||
|
||||
Reference in New Issue
Block a user