Added timeShift() function, closes #307.

This commit is contained in:
Alexander Zobnin
2016-11-17 17:48:08 +03:00
parent 092b6c897c
commit 54c03e6ece
4 changed files with 84 additions and 6 deletions

View File

@@ -251,6 +251,23 @@ function findNearestLeft(series, point) {
return nearestLeft;
}
function timeShift(interval, range) {
let shift = utils.parseTimeShiftInterval(interval) / 1000;
return range.map(time => {
return time - shift;
});
}
function unShiftTimeSeries(interval, datapoints) {
let unshift = utils.parseTimeShiftInterval(interval);
return datapoints.map(dp => {
return [
dp[0],
dp[1] + unshift
];
});
}
let metricFunctions = {
groupBy: groupByWrapper,
scale: scale,
@@ -263,6 +280,7 @@ let metricFunctions = {
sumSeries: sumSeries,
top: _.partial(limit, 'top'),
bottom: _.partial(limit, 'bottom'),
timeShift: timeShift,
setAlias: setAlias
};
@@ -280,6 +298,7 @@ export default {
MIN: MIN,
MAX: MAX,
MEDIAN: MEDIAN,
unShiftTimeSeries: unShiftTimeSeries,
get aggregationFunctions() {
return aggregationFunctions;