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
6882dcfb
Commit
6882dcfb
authored
Nov 22, 2016
by
bergquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(alerting): add backend support for median reducer
parent
51f80aff
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
0 deletions
+34
-0
pkg/services/alerting/conditions/reducer.go
+20
-0
pkg/services/alerting/conditions/reducer_test.go
+14
-0
No files found.
pkg/services/alerting/conditions/reducer.go
View file @
6882dcfb
...
...
@@ -3,6 +3,8 @@ package conditions
import
(
"math"
"sort"
"github.com/grafana/grafana/pkg/tsdb"
"gopkg.in/guregu/null.v3"
)
...
...
@@ -71,6 +73,24 @@ func (s *SimpleReducer) Reduce(series *tsdb.TimeSeries) null.Float {
break
}
}
case
"median"
:
var
values
[]
float64
for
_
,
v
:=
range
series
.
Points
{
if
v
[
0
]
.
Valid
{
allNull
=
false
values
=
append
(
values
,
v
[
0
]
.
Float64
)
}
}
if
len
(
values
)
>=
1
{
sort
.
Float64s
(
values
)
length
:=
len
(
values
)
if
length
%
2
==
1
{
value
=
values
[(
length
-
1
)
/
2
]
}
else
{
value
=
(
values
[(
length
/
2
)
-
1
]
+
values
[
length
/
2
])
/
2
}
}
}
if
allNull
{
...
...
pkg/services/alerting/conditions/reducer_test.go
View file @
6882dcfb
...
...
@@ -41,6 +41,20 @@ func TestSimpleReducer(t *testing.T) {
So
(
result
,
ShouldEqual
,
float64
(
3000
))
})
Convey
(
"median odd amount of numbers"
,
func
()
{
result
:=
testReducer
(
"median"
,
1
,
2
,
3000
)
So
(
result
,
ShouldEqual
,
float64
(
2
))
})
Convey
(
"median even amount of numbers"
,
func
()
{
result
:=
testReducer
(
"median"
,
1
,
2
,
4
,
3000
)
So
(
result
,
ShouldEqual
,
float64
(
3
))
})
Convey
(
"median with one values"
,
func
()
{
result
:=
testReducer
(
"median"
,
1
)
So
(
result
,
ShouldEqual
,
float64
(
1
))
})
})
}
...
...
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