Backend: Merge master into the backend branch (#845)

* CI: fix shellcheck issues (#789)

Signed-off-by: Mario Trangoni <mjtrangoni@gmail.com>

* annotations: fix options in grafana 6.x, fix #813

* fix function editor in Grafana 6.4, closes #810

* add typings for grafana packages

* Add $__range_series variable for calculating function over the whole series, #531

* fix tests

* Don't set alert styles for react panels, fix #823

* docs: add range variables

* docs: percentile reference

* fix codespell

Co-authored-by: Mario Trangoni <mario@mariotrangoni.de>
Co-authored-by: Alexander Zobnin <alexanderzobnin@gmail.com>
This commit is contained in:
vignesh-reddy
2019-12-30 01:45:47 -06:00
committed by Alexander Zobnin
parent b4b0c5b8f4
commit c300debe35
15 changed files with 499 additions and 52 deletions

View File

@@ -11,6 +11,7 @@
import _ from 'lodash';
import * as utils from './utils';
import * as c from './constants';
const POINT_VALUE = 0;
const POINT_TIMESTAMP = 1;
@@ -94,11 +95,15 @@ function groupBy(datapoints, interval, groupByCallback) {
}));
}
function groupBy_perf(datapoints, interval, groupByCallback) {
export function groupBy_perf(datapoints, interval, groupByCallback) {
if (datapoints.length === 0) {
return [];
}
if (interval === c.RANGE_VARIABLE_VALUE) {
return groupByRange(datapoints, groupByCallback);
}
let ms_interval = utils.parseInterval(interval);
let grouped_series = [];
let frame_values = [];
@@ -132,6 +137,19 @@ function groupBy_perf(datapoints, interval, groupByCallback) {
return grouped_series;
}
export function groupByRange(datapoints, groupByCallback) {
const frame_values = [];
const frame_start = datapoints[0][POINT_TIMESTAMP];
const frame_end = datapoints[datapoints.length - 1][POINT_TIMESTAMP];
let point;
for (let i=0; i < datapoints.length; i++) {
point = datapoints[i];
frame_values.push(point[POINT_VALUE]);
}
const frame_value = groupByCallback(frame_values);
return [[frame_value, frame_start], [frame_value, frame_end]];
}
/**
* Summarize set of time series into one.
* @param {datapoints[]} timeseries array of time series
@@ -495,6 +513,7 @@ const exportedFunctions = {
downsample,
groupBy,
groupBy_perf,
groupByRange,
sumSeries,
scale,
offset,