timeseries.js refactor
This commit is contained in:
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 groupBy = _timeseries2.default.groupBy;
|
||||
var sumSeries = _timeseries2.default.sumSeries;
|
||||
var scale = _timeseries2.default.scale;
|
||||
var delta = _timeseries2.default.delta;
|
||||
var scale = function scale(factor, datapoints) {
|
||||
return _timeseries2.default.scale(datapoints, factor);
|
||||
};
|
||||
|
||||
var SUM = _timeseries2.default.SUM;
|
||||
var COUNT = _timeseries2.default.COUNT;
|
||||
@@ -81,19 +83,19 @@ function extractText(str, pattern) {
|
||||
|
||||
function groupByWrapper(interval, groupFunc, datapoints) {
|
||||
var groupByCallback = aggregationFunctions[groupFunc];
|
||||
return groupBy(interval, groupByCallback, datapoints);
|
||||
return groupBy(datapoints, interval, groupByCallback);
|
||||
}
|
||||
|
||||
function aggregateByWrapper(interval, aggregateFunc, datapoints) {
|
||||
// Flatten all points in frame and then just use groupBy()
|
||||
var flattenedPoints = _lodash2.default.flatten(datapoints, true);
|
||||
var groupByCallback = aggregationFunctions[aggregateFunc];
|
||||
return groupBy(interval, groupByCallback, flattenedPoints);
|
||||
return groupBy(flattenedPoints, interval, groupByCallback);
|
||||
}
|
||||
|
||||
function aggregateWrapper(groupByCallback, interval, datapoints) {
|
||||
var flattenedPoints = _lodash2.default.flatten(datapoints, true);
|
||||
return groupBy(interval, groupByCallback, flattenedPoints);
|
||||
return groupBy(flattenedPoints, interval, groupByCallback);
|
||||
}
|
||||
|
||||
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
|
||||
*
|
||||
* 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) {
|
||||
@@ -75,7 +79,7 @@ function downsample(datapoints, time_to, ms_interval, func) {
|
||||
* Group points by given time interval
|
||||
* datapoints: [[<value>, <unixtime>], ...]
|
||||
*/
|
||||
function groupBy(interval, groupByCallback, datapoints) {
|
||||
function groupBy(datapoints, interval, groupByCallback) {
|
||||
var ms_interval = utils.parseInterval(interval);
|
||||
|
||||
// Calculate frame timestamps
|
||||
@@ -101,7 +105,7 @@ function groupBy(interval, groupByCallback, datapoints) {
|
||||
|
||||
/**
|
||||
* Summarize set of time series into one.
|
||||
* @param {object[]} timeseries
|
||||
* @param {datapoints[]} timeseries array of time series
|
||||
*/
|
||||
function sumSeries(timeseries) {
|
||||
|
||||
@@ -137,7 +141,7 @@ function sumSeries(timeseries) {
|
||||
return sortByTime(new_timeseries);
|
||||
}
|
||||
|
||||
function scale(factor, datapoints) {
|
||||
function scale(datapoints, factor) {
|
||||
return _lodash2.default.map(datapoints, function (point) {
|
||||
return [point[0] * factor, point[1]];
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user