Skip to content

Commit

Permalink
Merge branch 'jsvisa-feature/spread-expr'
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanielc committed Jun 3, 2016
2 parents 4bb4713 + 35bed88 commit d893d1c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ In order to know if subscription writes are being dropped you should monitor the
- [#595](https://github.com/influxdata/kapacitor/pull/595): Support counting and summing empty batches to 0.
- [#596](https://github.com/influxdata/kapacitor/pull/596): Support new group by time offset i.e. time(30s, 5s)
- [#416](https://github.com/influxdata/kapacitor/issues/416): Track ingress counts by database, retention policy, and measurement. Expose stats via cli.
- [#586](https://github.com/influxdata/kapacitor/pull/586): Add spread stateful function.

- [#600](https://github.com/influxdata/kapacitor/pull/600): Add close http response after handler laert post

Expand Down Expand Up @@ -500,8 +501,8 @@ See note on a breaking change in the HTTP API below. #163
- [#153](https://github.com/influxdata/kapacitor/issues/153): Fix panic if referencing non existant field in MapReduce function.
- [#138](https://github.com/influxdata/kapacitor/issues/138): Change over to influxdata github org.
- [#164](https://github.com/influxdata/kapacitor/issues/164): Update imports etc from InfluxDB as per the new meta store/client changes.
- [#163](https://github.com/influxdata/kapacitor/issues/163): BREAKING CHANGE: Removed the 'api/v1' pathing from the HTTP API so that Kapacitor is
path compatible with InfluxDB. While this is a breaking change the kapacitor cli has been updated accordingly and you will not experience any distruptions unless you
- [#163](https://github.com/influxdata/kapacitor/issues/163): BREAKING CHANGE: Removed the 'api/v1' pathing from the HTTP API so that Kapacitor is
path compatible with InfluxDB. While this is a breaking change the kapacitor cli has been updated accordingly and you will not experience any distruptions unless you
were calling the HTTP API directly.
- [#147](https://github.com/influxdata/kapacitor/issues/147): Compress .tar archives from builds.

Expand Down
34 changes: 33 additions & 1 deletion tick/stateful/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,15 @@ func init() {

// Return set of built-in Funcs
func NewFunctions() Funcs {
funcs := make(Funcs, len(statelessFuncs)+2)
funcs := make(Funcs, len(statelessFuncs)+3)
for n, f := range statelessFuncs {
funcs[n] = f
}

// Statefull functions -- need new instance
funcs["sigma"] = &sigma{}
funcs["count"] = &count{}
funcs["spread"] = &spread{min: math.Inf(+1), max: math.Inf(-1)}

return funcs
}
Expand Down Expand Up @@ -447,6 +448,37 @@ func (s *sigma) Call(args ...interface{}) (interface{}, error) {
return math.Abs(x-s.mean) / math.Sqrt(s.variance), nil
}

type spread struct {
min float64
max float64
}

func (s *spread) Reset() {
s.min = math.Inf(+1)
s.max = math.Inf(-1)
}

// Computes the running range of all values
func (s *spread) Call(args ...interface{}) (interface{}, error) {
if len(args) != 1 {
return 0, errors.New("spread expects exactly one argument")
}
x, ok := args[0].(float64)
if !ok {
return nil, ErrNotFloat
}

if x < s.min {
s.min = x
}

if x > s.max {
s.max = x
}

return s.max - s.min, nil
}

type minute struct {
}

Expand Down

0 comments on commit d893d1c

Please sign in to comment.