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
49dda7e5
Commit
49dda7e5
authored
Nov 23, 2016
by
Dirk le Roux
Committed by
Dirk le Roux
Nov 29, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
first, delta, range passing unit tests
Signed-off-by: Dirk le Roux <dirk.leroux@gmail.com>
parent
f7e8e9c9
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
84 additions
and
1 deletions
+84
-1
public/app/core/time_series2.ts
+26
-0
public/app/plugins/panel/singlestat/module.ts
+1
-1
public/test/core/time_series_specs.js
+57
-0
No files found.
public/app/core/time_series2.ts
View file @
49dda7e5
...
...
@@ -102,6 +102,9 @@ export default class TimeSeries {
this
.
stats
.
min
=
Number
.
MAX_VALUE
;
this
.
stats
.
avg
=
null
;
this
.
stats
.
current
=
null
;
this
.
stats
.
first
=
null
;
this
.
stats
.
delta
=
0
;
this
.
stats
.
range
=
null
;
this
.
stats
.
timeStep
=
Number
.
MAX_VALUE
;
this
.
allIsNull
=
true
;
this
.
allIsZero
=
true
;
...
...
@@ -112,6 +115,8 @@ export default class TimeSeries {
var
currentValue
;
var
nonNulls
=
0
;
var
previousTime
;
var
previousValue
=
0
;
var
previousDeltaUp
=
true
;
for
(
var
i
=
0
;
i
<
this
.
datapoints
.
length
;
i
++
)
{
currentValue
=
this
.
datapoints
[
i
][
0
];
...
...
@@ -148,6 +153,24 @@ export default class TimeSeries {
if
(
currentValue
<
this
.
stats
.
min
)
{
this
.
stats
.
min
=
currentValue
;
}
if
(
this
.
stats
.
first
===
null
){
this
.
stats
.
first
=
currentValue
;
}
else
{
if
(
previousValue
>
currentValue
)
{
// counter reset
previousDeltaUp
=
false
;
if
(
i
===
this
.
datapoints
.
length
-
1
)
{
// reset on last
this
.
stats
.
delta
+=
currentValue
;
}
}
else
{
if
(
previousDeltaUp
)
{
this
.
stats
.
delta
+=
currentValue
-
previousValue
;
// normal increment
}
else
{
this
.
stats
.
delta
+=
currentValue
;
// account for counter reset
}
previousDeltaUp
=
true
;
}
}
previousValue
=
currentValue
;
}
if
(
currentValue
!==
0
)
{
...
...
@@ -167,6 +190,9 @@ export default class TimeSeries {
this
.
stats
.
current
=
result
[
result
.
length
-
2
][
1
];
}
}
if
(
this
.
stats
.
max
!==
null
&&
this
.
stats
.
min
!==
null
)
{
this
.
stats
.
range
=
this
.
stats
.
max
-
this
.
stats
.
min
;
}
this
.
stats
.
count
=
result
.
length
;
return
result
;
...
...
public/app/plugins/panel/singlestat/module.ts
View file @
49dda7e5
...
...
@@ -21,7 +21,7 @@ class SingleStatCtrl extends MetricsPanelCtrl {
invalidGaugeRange
:
boolean
;
panel
:
any
;
events
:
any
;
valueNameOptions
:
any
[]
=
[
'min'
,
'max'
,
'avg'
,
'current'
,
'total'
,
'name'
];
valueNameOptions
:
any
[]
=
[
'min'
,
'max'
,
'avg'
,
'current'
,
'total'
,
'name'
,
'first'
,
'delta'
,
'range'
];
// Set and populate defaults
panelDefaults
=
{
...
...
public/test/core/time_series_specs.js
View file @
49dda7e5
...
...
@@ -49,6 +49,63 @@ define([
expect
(
series
.
stats
.
avg
).
to
.
be
(
6.333333333333333
);
});
it
(
'the delta value should account for nulls'
,
function
()
{
series
=
new
TimeSeries
({
datapoints
:
[[
1
,
2
],[
3
,
3
],[
null
,
4
],[
10
,
5
],[
15
,
6
]]
});
series
.
getFlotPairs
(
'null'
,
yAxisFormats
);
expect
(
series
.
stats
.
delta
).
to
.
be
(
14
);
});
it
(
'the delta value should account for nulls on first'
,
function
()
{
series
=
new
TimeSeries
({
datapoints
:
[[
null
,
2
],[
1
,
3
],[
10
,
4
],[
15
,
5
]]
});
series
.
getFlotPairs
(
'null'
,
yAxisFormats
);
expect
(
series
.
stats
.
delta
).
to
.
be
(
14
);
});
it
(
'the delta value should account for nulls on last'
,
function
()
{
series
=
new
TimeSeries
({
datapoints
:
[[
1
,
2
],[
5
,
3
],[
10
,
4
],[
null
,
5
]]
});
series
.
getFlotPairs
(
'null'
,
yAxisFormats
);
expect
(
series
.
stats
.
delta
).
to
.
be
(
9
);
});
it
(
'the delta value should account for resets'
,
function
()
{
series
=
new
TimeSeries
({
datapoints
:
[[
1
,
2
],[
5
,
3
],[
10
,
4
],[
0
,
5
],[
10
,
6
]]
});
series
.
getFlotPairs
(
'null'
,
yAxisFormats
);
expect
(
series
.
stats
.
delta
).
to
.
be
(
19
);
});
it
(
'the delta value should account for resets on last'
,
function
()
{
series
=
new
TimeSeries
({
datapoints
:
[[
1
,
2
],[
2
,
3
],[
10
,
4
],[
8
,
5
]]
});
series
.
getFlotPairs
(
'null'
,
yAxisFormats
);
expect
(
series
.
stats
.
delta
).
to
.
be
(
17
);
});
it
(
'the range value should be max - min'
,
function
()
{
series
=
new
TimeSeries
(
testData
);
series
.
getFlotPairs
(
'null'
,
yAxisFormats
);
expect
(
series
.
stats
.
range
).
to
.
be
(
9
);
});
it
(
'first value should ingone nulls'
,
function
()
{
series
=
new
TimeSeries
(
testData
);
series
.
getFlotPairs
(
'null'
,
yAxisFormats
);
expect
(
series
.
stats
.
first
).
to
.
be
(
1
);
series
=
new
TimeSeries
({
datapoints
:
[[
null
,
2
],[
1
,
3
],[
10
,
4
],[
8
,
5
]]
});
series
.
getFlotPairs
(
'null'
,
yAxisFormats
);
expect
(
series
.
stats
.
first
).
to
.
be
(
1
);
});
it
(
'with null as zero style, average value should treat nulls as 0'
,
function
()
{
series
=
new
TimeSeries
(
testData
);
series
.
getFlotPairs
(
'null as zero'
,
yAxisFormats
);
...
...
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