timeseries.js refactor
This commit is contained in:
14
dist/datasource-zabbix/dataProcessor.js
vendored
14
dist/datasource-zabbix/dataProcessor.js
vendored
@@ -3,7 +3,7 @@
|
|||||||
System.register(['lodash', './utils', './timeseries'], function (_export, _context) {
|
System.register(['lodash', './utils', './timeseries'], function (_export, _context) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var _, utils, ts, downsampleSeries, groupBy, sumSeries, scale, delta, SUM, COUNT, AVERAGE, MIN, MAX, MEDIAN, metricFunctions, aggregationFunctions;
|
var _, utils, ts, downsampleSeries, groupBy, sumSeries, delta, scale, SUM, COUNT, AVERAGE, MIN, MAX, MEDIAN, metricFunctions, aggregationFunctions;
|
||||||
|
|
||||||
function limit(order, n, orderByFunc, timeseries) {
|
function limit(order, n, orderByFunc, timeseries) {
|
||||||
var orderByCallback = aggregationFunctions[orderByFunc];
|
var orderByCallback = aggregationFunctions[orderByFunc];
|
||||||
@@ -53,19 +53,19 @@ System.register(['lodash', './utils', './timeseries'], function (_export, _conte
|
|||||||
|
|
||||||
function groupByWrapper(interval, groupFunc, datapoints) {
|
function groupByWrapper(interval, groupFunc, datapoints) {
|
||||||
var groupByCallback = aggregationFunctions[groupFunc];
|
var groupByCallback = aggregationFunctions[groupFunc];
|
||||||
return groupBy(interval, groupByCallback, datapoints);
|
return groupBy(datapoints, interval, groupByCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
function aggregateByWrapper(interval, aggregateFunc, datapoints) {
|
function aggregateByWrapper(interval, aggregateFunc, datapoints) {
|
||||||
// Flatten all points in frame and then just use groupBy()
|
// Flatten all points in frame and then just use groupBy()
|
||||||
var flattenedPoints = _.flatten(datapoints, true);
|
var flattenedPoints = _.flatten(datapoints, true);
|
||||||
var groupByCallback = aggregationFunctions[aggregateFunc];
|
var groupByCallback = aggregationFunctions[aggregateFunc];
|
||||||
return groupBy(interval, groupByCallback, flattenedPoints);
|
return groupBy(flattenedPoints, interval, groupByCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
function aggregateWrapper(groupByCallback, interval, datapoints) {
|
function aggregateWrapper(groupByCallback, interval, datapoints) {
|
||||||
var flattenedPoints = _.flatten(datapoints, true);
|
var flattenedPoints = _.flatten(datapoints, true);
|
||||||
return groupBy(interval, groupByCallback, flattenedPoints);
|
return groupBy(flattenedPoints, interval, groupByCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
function timeShift(interval, range) {
|
function timeShift(interval, range) {
|
||||||
@@ -94,8 +94,12 @@ System.register(['lodash', './utils', './timeseries'], function (_export, _conte
|
|||||||
downsampleSeries = ts.downsample;
|
downsampleSeries = ts.downsample;
|
||||||
groupBy = ts.groupBy;
|
groupBy = ts.groupBy;
|
||||||
sumSeries = ts.sumSeries;
|
sumSeries = ts.sumSeries;
|
||||||
scale = ts.scale;
|
|
||||||
delta = ts.delta;
|
delta = ts.delta;
|
||||||
|
|
||||||
|
scale = function scale(factor, datapoints) {
|
||||||
|
return ts.scale(datapoints, factor);
|
||||||
|
};
|
||||||
|
|
||||||
SUM = ts.SUM;
|
SUM = ts.SUM;
|
||||||
COUNT = ts.COUNT;
|
COUNT = ts.COUNT;
|
||||||
AVERAGE = ts.AVERAGE;
|
AVERAGE = ts.AVERAGE;
|
||||||
|
|||||||
2
dist/datasource-zabbix/dataProcessor.js.map
vendored
2
dist/datasource-zabbix/dataProcessor.js.map
vendored
File diff suppressed because one or more lines are too long
10
dist/datasource-zabbix/timeseries.js
vendored
10
dist/datasource-zabbix/timeseries.js
vendored
@@ -12,6 +12,10 @@ System.register(['lodash', './utils'], function (_export, _context) {
|
|||||||
* timeseries.js
|
* timeseries.js
|
||||||
*
|
*
|
||||||
* This module contains functions for working with time series.
|
* This module contains functions for working with time series.
|
||||||
|
*
|
||||||
|
* datapoints - array of points where point is [value, timestamp]. In almost all cases (if other wasn't
|
||||||
|
* explicitly said) we assume datapoints are sorted by timestamp.
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function downsample(datapoints, time_to, ms_interval, func) {
|
function downsample(datapoints, time_to, ms_interval, func) {
|
||||||
@@ -64,7 +68,7 @@ System.register(['lodash', './utils'], function (_export, _context) {
|
|||||||
* Group points by given time interval
|
* Group points by given time interval
|
||||||
* datapoints: [[<value>, <unixtime>], ...]
|
* datapoints: [[<value>, <unixtime>], ...]
|
||||||
*/
|
*/
|
||||||
function groupBy(interval, groupByCallback, datapoints) {
|
function groupBy(datapoints, interval, groupByCallback) {
|
||||||
var ms_interval = utils.parseInterval(interval);
|
var ms_interval = utils.parseInterval(interval);
|
||||||
|
|
||||||
// Calculate frame timestamps
|
// Calculate frame timestamps
|
||||||
@@ -90,7 +94,7 @@ System.register(['lodash', './utils'], function (_export, _context) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Summarize set of time series into one.
|
* Summarize set of time series into one.
|
||||||
* @param {object[]} timeseries
|
* @param {datapoints[]} timeseries array of time series
|
||||||
*/
|
*/
|
||||||
function sumSeries(timeseries) {
|
function sumSeries(timeseries) {
|
||||||
|
|
||||||
@@ -124,7 +128,7 @@ System.register(['lodash', './utils'], function (_export, _context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return sortByTime(new_timeseries);
|
return sortByTime(new_timeseries);
|
||||||
}function scale(factor, datapoints) {
|
}function scale(datapoints, factor) {
|
||||||
return _.map(datapoints, function (point) {
|
return _.map(datapoints, function (point) {
|
||||||
return [point[0] * factor, point[1]];
|
return [point[0] * factor, point[1]];
|
||||||
});
|
});
|
||||||
|
|||||||
2
dist/datasource-zabbix/timeseries.js.map
vendored
2
dist/datasource-zabbix/timeseries.js.map
vendored
File diff suppressed because one or more lines are too long
10
dist/test/datasource-zabbix/dataProcessor.js
vendored
10
dist/test/datasource-zabbix/dataProcessor.js
vendored
@@ -23,8 +23,10 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|||||||
var downsampleSeries = _timeseries2.default.downsample;
|
var downsampleSeries = _timeseries2.default.downsample;
|
||||||
var groupBy = _timeseries2.default.groupBy;
|
var groupBy = _timeseries2.default.groupBy;
|
||||||
var sumSeries = _timeseries2.default.sumSeries;
|
var sumSeries = _timeseries2.default.sumSeries;
|
||||||
var scale = _timeseries2.default.scale;
|
|
||||||
var delta = _timeseries2.default.delta;
|
var delta = _timeseries2.default.delta;
|
||||||
|
var scale = function scale(factor, datapoints) {
|
||||||
|
return _timeseries2.default.scale(datapoints, factor);
|
||||||
|
};
|
||||||
|
|
||||||
var SUM = _timeseries2.default.SUM;
|
var SUM = _timeseries2.default.SUM;
|
||||||
var COUNT = _timeseries2.default.COUNT;
|
var COUNT = _timeseries2.default.COUNT;
|
||||||
@@ -81,19 +83,19 @@ function extractText(str, pattern) {
|
|||||||
|
|
||||||
function groupByWrapper(interval, groupFunc, datapoints) {
|
function groupByWrapper(interval, groupFunc, datapoints) {
|
||||||
var groupByCallback = aggregationFunctions[groupFunc];
|
var groupByCallback = aggregationFunctions[groupFunc];
|
||||||
return groupBy(interval, groupByCallback, datapoints);
|
return groupBy(datapoints, interval, groupByCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
function aggregateByWrapper(interval, aggregateFunc, datapoints) {
|
function aggregateByWrapper(interval, aggregateFunc, datapoints) {
|
||||||
// Flatten all points in frame and then just use groupBy()
|
// Flatten all points in frame and then just use groupBy()
|
||||||
var flattenedPoints = _lodash2.default.flatten(datapoints, true);
|
var flattenedPoints = _lodash2.default.flatten(datapoints, true);
|
||||||
var groupByCallback = aggregationFunctions[aggregateFunc];
|
var groupByCallback = aggregationFunctions[aggregateFunc];
|
||||||
return groupBy(interval, groupByCallback, flattenedPoints);
|
return groupBy(flattenedPoints, interval, groupByCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
function aggregateWrapper(groupByCallback, interval, datapoints) {
|
function aggregateWrapper(groupByCallback, interval, datapoints) {
|
||||||
var flattenedPoints = _lodash2.default.flatten(datapoints, true);
|
var flattenedPoints = _lodash2.default.flatten(datapoints, true);
|
||||||
return groupBy(interval, groupByCallback, flattenedPoints);
|
return groupBy(flattenedPoints, interval, groupByCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
function timeShift(interval, range) {
|
function timeShift(interval, range) {
|
||||||
|
|||||||
10
dist/test/datasource-zabbix/timeseries.js
vendored
10
dist/test/datasource-zabbix/timeseries.js
vendored
@@ -23,6 +23,10 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|||||||
* timeseries.js
|
* timeseries.js
|
||||||
*
|
*
|
||||||
* This module contains functions for working with time series.
|
* This module contains functions for working with time series.
|
||||||
|
*
|
||||||
|
* datapoints - array of points where point is [value, timestamp]. In almost all cases (if other wasn't
|
||||||
|
* explicitly said) we assume datapoints are sorted by timestamp.
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function downsample(datapoints, time_to, ms_interval, func) {
|
function downsample(datapoints, time_to, ms_interval, func) {
|
||||||
@@ -75,7 +79,7 @@ function downsample(datapoints, time_to, ms_interval, func) {
|
|||||||
* Group points by given time interval
|
* Group points by given time interval
|
||||||
* datapoints: [[<value>, <unixtime>], ...]
|
* datapoints: [[<value>, <unixtime>], ...]
|
||||||
*/
|
*/
|
||||||
function groupBy(interval, groupByCallback, datapoints) {
|
function groupBy(datapoints, interval, groupByCallback) {
|
||||||
var ms_interval = utils.parseInterval(interval);
|
var ms_interval = utils.parseInterval(interval);
|
||||||
|
|
||||||
// Calculate frame timestamps
|
// Calculate frame timestamps
|
||||||
@@ -101,7 +105,7 @@ function groupBy(interval, groupByCallback, datapoints) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Summarize set of time series into one.
|
* Summarize set of time series into one.
|
||||||
* @param {object[]} timeseries
|
* @param {datapoints[]} timeseries array of time series
|
||||||
*/
|
*/
|
||||||
function sumSeries(timeseries) {
|
function sumSeries(timeseries) {
|
||||||
|
|
||||||
@@ -137,7 +141,7 @@ function sumSeries(timeseries) {
|
|||||||
return sortByTime(new_timeseries);
|
return sortByTime(new_timeseries);
|
||||||
}
|
}
|
||||||
|
|
||||||
function scale(factor, datapoints) {
|
function scale(datapoints, factor) {
|
||||||
return _lodash2.default.map(datapoints, function (point) {
|
return _lodash2.default.map(datapoints, function (point) {
|
||||||
return [point[0] * factor, point[1]];
|
return [point[0] * factor, point[1]];
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ import ts from './timeseries';
|
|||||||
let downsampleSeries = ts.downsample;
|
let downsampleSeries = ts.downsample;
|
||||||
let groupBy = ts.groupBy;
|
let groupBy = ts.groupBy;
|
||||||
let sumSeries = ts.sumSeries;
|
let sumSeries = ts.sumSeries;
|
||||||
let scale = ts.scale;
|
|
||||||
let delta = ts.delta;
|
let delta = ts.delta;
|
||||||
|
let scale = (factor, datapoints) => ts.scale(datapoints, factor);
|
||||||
|
|
||||||
let SUM = ts.SUM;
|
let SUM = ts.SUM;
|
||||||
let COUNT = ts.COUNT;
|
let COUNT = ts.COUNT;
|
||||||
@@ -63,19 +63,19 @@ function extractText(str, pattern) {
|
|||||||
|
|
||||||
function groupByWrapper(interval, groupFunc, datapoints) {
|
function groupByWrapper(interval, groupFunc, datapoints) {
|
||||||
var groupByCallback = aggregationFunctions[groupFunc];
|
var groupByCallback = aggregationFunctions[groupFunc];
|
||||||
return groupBy(interval, groupByCallback, datapoints);
|
return groupBy(datapoints, interval, groupByCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
function aggregateByWrapper(interval, aggregateFunc, datapoints) {
|
function aggregateByWrapper(interval, aggregateFunc, datapoints) {
|
||||||
// Flatten all points in frame and then just use groupBy()
|
// Flatten all points in frame and then just use groupBy()
|
||||||
var flattenedPoints = _.flatten(datapoints, true);
|
var flattenedPoints = _.flatten(datapoints, true);
|
||||||
var groupByCallback = aggregationFunctions[aggregateFunc];
|
var groupByCallback = aggregationFunctions[aggregateFunc];
|
||||||
return groupBy(interval, groupByCallback, flattenedPoints);
|
return groupBy(flattenedPoints, interval, groupByCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
function aggregateWrapper(groupByCallback, interval, datapoints) {
|
function aggregateWrapper(groupByCallback, interval, datapoints) {
|
||||||
var flattenedPoints = _.flatten(datapoints, true);
|
var flattenedPoints = _.flatten(datapoints, true);
|
||||||
return groupBy(interval, groupByCallback, flattenedPoints);
|
return groupBy(flattenedPoints, interval, groupByCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
function timeShift(interval, range) {
|
function timeShift(interval, range) {
|
||||||
|
|||||||
@@ -2,6 +2,10 @@
|
|||||||
* timeseries.js
|
* timeseries.js
|
||||||
*
|
*
|
||||||
* This module contains functions for working with time series.
|
* This module contains functions for working with time series.
|
||||||
|
*
|
||||||
|
* datapoints - array of points where point is [value, timestamp]. In almost all cases (if other wasn't
|
||||||
|
* explicitly said) we assume datapoints are sorted by timestamp.
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
@@ -62,7 +66,7 @@ function downsample(datapoints, time_to, ms_interval, func) {
|
|||||||
* Group points by given time interval
|
* Group points by given time interval
|
||||||
* datapoints: [[<value>, <unixtime>], ...]
|
* datapoints: [[<value>, <unixtime>], ...]
|
||||||
*/
|
*/
|
||||||
function groupBy(interval, groupByCallback, datapoints) {
|
function groupBy(datapoints, interval, groupByCallback) {
|
||||||
var ms_interval = utils.parseInterval(interval);
|
var ms_interval = utils.parseInterval(interval);
|
||||||
|
|
||||||
// Calculate frame timestamps
|
// Calculate frame timestamps
|
||||||
@@ -88,7 +92,7 @@ function groupBy(interval, groupByCallback, datapoints) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Summarize set of time series into one.
|
* Summarize set of time series into one.
|
||||||
* @param {object[]} timeseries
|
* @param {datapoints[]} timeseries array of time series
|
||||||
*/
|
*/
|
||||||
function sumSeries(timeseries) {
|
function sumSeries(timeseries) {
|
||||||
|
|
||||||
@@ -124,7 +128,7 @@ function sumSeries(timeseries) {
|
|||||||
return sortByTime(new_timeseries);
|
return sortByTime(new_timeseries);
|
||||||
}
|
}
|
||||||
|
|
||||||
function scale(factor, datapoints) {
|
function scale(datapoints, factor) {
|
||||||
return _.map(datapoints, point => {
|
return _.map(datapoints, point => {
|
||||||
return [
|
return [
|
||||||
point[0] * factor,
|
point[0] * factor,
|
||||||
|
|||||||
Reference in New Issue
Block a user