Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
c0beef75
Commit
c0beef75
authored
Nov 20, 2015
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3252 from alechenninger/avg-ignore-null
Ignore nulls unless 'null as zero' for series.stats.avg
parents
5ec44886
2a600b25
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
1 deletions
+14
-1
public/app/core/time_series.ts
+3
-1
public/test/core/time_series_specs.js
+11
-0
No files found.
public/app/core/time_series.ts
View file @
c0beef75
...
...
@@ -101,6 +101,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
];
...
...
@@ -117,6 +118,7 @@ class TimeSeries {
if
(
_
.
isNumber
(
currentValue
))
{
this
.
stats
.
total
+=
currentValue
;
this
.
allIsNull
=
false
;
nonNulls
++
;
}
if
(
currentValue
>
this
.
stats
.
max
)
{
...
...
@@ -139,7 +141,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
];
...
...
public/test/core/time_series_specs.js
View file @
c0beef75
...
...
@@ -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
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment