mirror of
https://github.com/grafana/grafana.git
synced 2024-11-29 04:04:00 -06:00
Ignore nulls unless 'null as zero' for series.stats.avg
This commit is contained in:
parent
305f8d6982
commit
2a600b25e7
@ -98,6 +98,7 @@ class TimeSeries {
|
||||
var nullAsZero = fillStyle === 'null as zero';
|
||||
var currentTime;
|
||||
var currentValue;
|
||||
var nonNulls = 0;
|
||||
|
||||
for (var i = 0; i < this.datapoints.length; i++) {
|
||||
currentValue = this.datapoints[i][0];
|
||||
@ -114,6 +115,7 @@ class TimeSeries {
|
||||
if (_.isNumber(currentValue)) {
|
||||
this.stats.total += currentValue;
|
||||
this.allIsNull = false;
|
||||
nonNulls++;
|
||||
}
|
||||
|
||||
if (currentValue > this.stats.max) {
|
||||
@ -136,7 +138,7 @@ class TimeSeries {
|
||||
if (this.stats.min === Number.MAX_VALUE) { this.stats.min = null; }
|
||||
|
||||
if (result.length) {
|
||||
this.stats.avg = (this.stats.total / result.length);
|
||||
this.stats.avg = (this.stats.total / nonNulls);
|
||||
this.stats.current = result[result.length-1][1];
|
||||
if (this.stats.current === null && result.length > 1) {
|
||||
this.stats.current = result[result.length-2][1];
|
||||
|
@ -43,6 +43,17 @@ define([
|
||||
expect(series.stats.max).to.be(-4);
|
||||
});
|
||||
|
||||
it('average value should ignore nulls', function() {
|
||||
series = new TimeSeries(testData);
|
||||
series.getFlotPairs('null', yAxisFormats);
|
||||
expect(series.stats.avg).to.be(6.333333333333333);
|
||||
});
|
||||
|
||||
it('with null as zero style, average value should treat nulls as 0', function() {
|
||||
series = new TimeSeries(testData);
|
||||
series.getFlotPairs('null as zero', yAxisFormats);
|
||||
expect(series.stats.avg).to.be(4.75);
|
||||
});
|
||||
});
|
||||
|
||||
describe('series overrides', function() {
|
||||
|
Loading…
Reference in New Issue
Block a user