Changed groupBy() function for working with grafana-style intervals.
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
define([
|
||||
'angular',
|
||||
'lodash',
|
||||
'moment'
|
||||
'moment',
|
||||
'./utils'
|
||||
],
|
||||
function (angular, _, moment) {
|
||||
function (angular, _, moment, utils) {
|
||||
'use strict';
|
||||
|
||||
var module = angular.module('grafana.services');
|
||||
@@ -65,7 +66,8 @@ function (angular, _, moment) {
|
||||
* Group points by given time interval
|
||||
* datapoints: [[<value>, <unixtime>], ...]
|
||||
*/
|
||||
this.groupBy = function(datapoints, ms_interval, groupByCallback) {
|
||||
this.groupBy = function(interval, groupByCallback, datapoints) {
|
||||
var ms_interval = utils.parseInterval(interval);
|
||||
var frames = _.groupBy(datapoints, function(point) {
|
||||
var group_time = Number(moment.utc(point[1]).startOf('minute').valueOf());
|
||||
group_time = Math.ceil(point[1] / ms_interval) * ms_interval;
|
||||
|
||||
@@ -144,12 +144,11 @@ function (angular, _, dateMath, utils) {
|
||||
|
||||
return getHistory.then(function (timeseries_data) {
|
||||
return _.map(timeseries_data, function (timeseries) {
|
||||
var groupBuInterval = utils.parseInterval(options.interval);
|
||||
|
||||
// Series downsampling
|
||||
// Metric data processing
|
||||
var dp = timeseries.datapoints;
|
||||
if (false) {
|
||||
dp = DataProcessingService.groupBy(dp, groupBuInterval,
|
||||
dp = DataProcessingService.groupBy(dp, options.interval,
|
||||
DataProcessingService.AVERAGE);
|
||||
timeseries.datapoints = dp;
|
||||
}
|
||||
@@ -215,10 +214,8 @@ function (angular, _, dateMath, utils) {
|
||||
|
||||
// Series downsampling
|
||||
var DPS = DataProcessingService;
|
||||
var groupBuInterval = utils.parseInterval(options.interval);
|
||||
if (timeseries.datapoints.length > options.maxDataPoints) {
|
||||
timeseries.datapoints = DPS.groupBy(timeseries.datapoints, groupBuInterval,
|
||||
DPS.AVERAGE);
|
||||
timeseries.datapoints = DPS.groupBy(options.interval, DPS.AVERAGE, timeseries.datapoints);
|
||||
}
|
||||
return timeseries;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user