Sum and count aggregations added

Sum and count aggregations of metrics (I really need this)

Signed-off-by: Ruslan Semov <me@recluse.ru>
This commit is contained in:
Ruslan Semov
2017-03-23 18:47:41 +03:00
parent 9c427942b9
commit 9cbc1d3c09
4 changed files with 52 additions and 8 deletions

View File

@@ -130,6 +130,18 @@ function limit(order, n, orderByFunc, timeseries) {
}
}
function SUM(values) {
var sum = 0;
_.each(values, function(value) {
sum += value;
});
return sum;
}
function COUNT(values) {
return values.length;
}
function AVERAGE(values) {
var sum = 0;
_.each(values, function(value) {
@@ -289,6 +301,8 @@ let metricFunctions = {
min: _.partial(aggregateWrapper, MIN),
max: _.partial(aggregateWrapper, MAX),
median: _.partial(aggregateWrapper, MEDIAN),
sum: _.partial(aggregateWrapper, SUM),
count: _.partial(aggregateWrapper, COUNT),
sumSeries: sumSeries,
top: _.partial(limit, 'top'),
bottom: _.partial(limit, 'bottom'),
@@ -301,7 +315,9 @@ let aggregationFunctions = {
avg: AVERAGE,
min: MIN,
max: MAX,
median: MEDIAN
median: MEDIAN,
sum: SUM,
count: COUNT
};
export default {
@@ -311,6 +327,8 @@ export default {
MIN: MIN,
MAX: MAX,
MEDIAN: MEDIAN,
SUM: SUM,
COUNT: COUNT,
unShiftTimeSeries: unShiftTimeSeries,
get aggregationFunctions() {
@@ -320,4 +338,4 @@ export default {
get metricFunctions() {
return metricFunctions;
}
};
};