new function percentil
This commit is contained in:
@@ -158,6 +158,32 @@ export default class DataProcessor {
|
|||||||
return timeseries;
|
return timeseries;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static PERCENTIL(interval, n, datapoints) {
|
||||||
|
var flattenedPoints = _.flatten(datapoints, true);
|
||||||
|
var ms_interval = utils.parseInterval(interval);
|
||||||
|
|
||||||
|
// Calculate frame timestamps
|
||||||
|
var frames = _.groupBy(flattenedPoints, function(point) {
|
||||||
|
// Calculate time for group of points
|
||||||
|
return Math.floor(point[1] / ms_interval) * ms_interval;
|
||||||
|
});
|
||||||
|
|
||||||
|
// frame: { '<unixtime>': [[<value>, <unixtime>], ...] }
|
||||||
|
// return [{ '<unixtime>': <value> }, { '<unixtime>': <value> }, ...]
|
||||||
|
var grouped = _.mapValues(frames, function(frame) {
|
||||||
|
var points = _.map(frame, function(point) {
|
||||||
|
return point[0];
|
||||||
|
});
|
||||||
|
var sorted = _.sortBy(points);
|
||||||
|
return sorted[Math.floor(sorted.length*n/100)];
|
||||||
|
});
|
||||||
|
|
||||||
|
// Convert points to Grafana format
|
||||||
|
return sortByTime(_.map(grouped, function(value, timestamp) {
|
||||||
|
return [Number(value), Number(timestamp)];
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
static scale(factor, datapoints) {
|
static scale(factor, datapoints) {
|
||||||
return _.map(datapoints, point => {
|
return _.map(datapoints, point => {
|
||||||
return [
|
return [
|
||||||
@@ -208,6 +234,7 @@ export default class DataProcessor {
|
|||||||
groupBy: this.groupByWrapper,
|
groupBy: this.groupByWrapper,
|
||||||
scale: this.scale,
|
scale: this.scale,
|
||||||
delta: this.delta,
|
delta: this.delta,
|
||||||
|
percentil: this.PERCENTIL,
|
||||||
aggregateBy: this.aggregateByWrapper,
|
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),
|
||||||
|
|||||||
@@ -72,6 +72,16 @@ addFuncDef({
|
|||||||
defaultParams: ['1m'],
|
defaultParams: ['1m'],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
addFuncDef({
|
||||||
|
name: 'percentil',
|
||||||
|
category: 'Aggregate',
|
||||||
|
params: [
|
||||||
|
{ name: 'interval', type: 'string' },
|
||||||
|
{ name: 'percent', type: 'string' }
|
||||||
|
],
|
||||||
|
defaultParams: ['1m','95'],
|
||||||
|
});
|
||||||
|
|
||||||
addFuncDef({
|
addFuncDef({
|
||||||
name: 'min',
|
name: 'min',
|
||||||
category: 'Aggregate',
|
category: 'Aggregate',
|
||||||
|
|||||||
Reference in New Issue
Block a user