percentil: refactor

This commit is contained in:
Alexander Zobnin
2017-10-16 15:25:02 +03:00
parent 872f1ac9c8
commit f53eac6f08
12 changed files with 65 additions and 9 deletions

View File

@@ -3,7 +3,7 @@
System.register(['lodash', './utils', './timeseries'], function (_export, _context) {
"use strict";
var _, utils, ts, downsampleSeries, groupBy, groupBy_exported, sumSeries, delta, rate, scale, simpleMovingAverage, expMovingAverage, SUM, COUNT, AVERAGE, MIN, MAX, MEDIAN, metricFunctions, aggregationFunctions;
var _, utils, ts, downsampleSeries, groupBy, groupBy_exported, sumSeries, delta, rate, scale, simpleMovingAverage, expMovingAverage, SUM, COUNT, AVERAGE, MIN, MAX, MEDIAN, PERCENTIL, metricFunctions, aggregationFunctions;
function limit(order, n, orderByFunc, timeseries) {
var orderByCallback = aggregationFunctions[orderByFunc];
@@ -68,6 +68,12 @@ System.register(['lodash', './utils', './timeseries'], function (_export, _conte
return groupBy(flattenedPoints, interval, groupByCallback);
}
function percentil(interval, n, datapoints) {
var flattenedPoints = _.flatten(datapoints, true);
var groupByCallback = _.partial(PERCENTIL, n);
return groupBy(flattenedPoints, interval, groupByCallback);
}
function timeShift(interval, range) {
var shift = utils.parseTimeShiftInterval(interval) / 1000;
return _.map(range, function (time) {
@@ -120,6 +126,7 @@ System.register(['lodash', './utils', './timeseries'], function (_export, _conte
MIN = ts.MIN;
MAX = ts.MAX;
MEDIAN = ts.MEDIAN;
PERCENTIL = ts.PERCENTIL;
metricFunctions = {
groupBy: groupByWrapper,
scale: scale,
@@ -129,6 +136,7 @@ System.register(['lodash', './utils', './timeseries'], function (_export, _conte
exponentialMovingAverage: expMovingAverage,
aggregateBy: aggregateByWrapper,
// Predefined aggs
percentil: percentil,
average: _.partial(aggregateWrapper, AVERAGE),
min: _.partial(aggregateWrapper, MIN),
max: _.partial(aggregateWrapper, MAX),

File diff suppressed because one or more lines are too long

View File

@@ -148,6 +148,13 @@ System.register(['lodash', 'jquery'], function (_export, _context) {
defaultParams: ['1m']
});
addFuncDef({
name: 'percentil',
category: 'Aggregate',
params: [{ name: 'interval', type: 'string' }, { name: 'percent', type: 'float', options: [25, 50, 75, 90, 95, 99, 99.9] }],
defaultParams: ['1m', 95]
});
addFuncDef({
name: 'min',
category: 'Aggregate',

File diff suppressed because one or more lines are too long

View File

@@ -305,6 +305,11 @@ System.register(['lodash', './utils'], function (_export, _context) {
return ema;
}
function PERCENTIL(n, values) {
var sorted = _.sortBy(values);
return sorted[Math.floor(sorted.length * n / 100)];
}
function COUNT(values) {
return values.length;
}
@@ -474,7 +479,8 @@ System.register(['lodash', './utils'], function (_export, _context) {
AVERAGE: AVERAGE,
MIN: MIN,
MAX: MAX,
MEDIAN: MEDIAN
MEDIAN: MEDIAN,
PERCENTIL: PERCENTIL
};
_export('default', exportedFunctions);

File diff suppressed because one or more lines are too long