2016-03-02 20:52:03 +00:00
|
|
|
package influxql
|
|
|
|
|
|
|
|
type FloatMeanReducer struct {
|
|
|
|
sum float64
|
|
|
|
count uint32
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewFloatMeanReducer() *FloatMeanReducer {
|
|
|
|
return &FloatMeanReducer{}
|
|
|
|
}
|
|
|
|
|
2016-03-07 18:25:45 +00:00
|
|
|
func (r *FloatMeanReducer) AggregateFloat(p *FloatPoint) {
|
2016-03-02 20:52:03 +00:00
|
|
|
if p.Aggregated >= 2 {
|
|
|
|
r.sum += p.Value * float64(p.Aggregated)
|
|
|
|
r.count += p.Aggregated
|
|
|
|
} else {
|
|
|
|
r.sum += p.Value
|
|
|
|
r.count++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-07 18:25:45 +00:00
|
|
|
func (r *FloatMeanReducer) Emit() []FloatPoint {
|
|
|
|
return []FloatPoint{{
|
2016-03-04 01:53:45 +00:00
|
|
|
Time: ZeroTime,
|
2016-03-02 20:52:03 +00:00
|
|
|
Value: r.sum / float64(r.count),
|
|
|
|
Aggregated: r.count,
|
2016-03-07 18:25:45 +00:00
|
|
|
}}
|
2016-03-02 20:52:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type IntegerMeanReducer struct {
|
|
|
|
sum int64
|
|
|
|
count uint32
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewIntegerMeanReducer() *IntegerMeanReducer {
|
|
|
|
return &IntegerMeanReducer{}
|
|
|
|
}
|
|
|
|
|
2016-03-07 18:25:45 +00:00
|
|
|
func (r *IntegerMeanReducer) AggregateInteger(p *IntegerPoint) {
|
2016-03-02 20:52:03 +00:00
|
|
|
if p.Aggregated >= 2 {
|
|
|
|
r.sum += p.Value * int64(p.Aggregated)
|
|
|
|
r.count += p.Aggregated
|
|
|
|
} else {
|
|
|
|
r.sum += p.Value
|
|
|
|
r.count++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-07 18:25:45 +00:00
|
|
|
func (r *IntegerMeanReducer) Emit() []FloatPoint {
|
|
|
|
return []FloatPoint{{
|
2016-03-04 01:53:45 +00:00
|
|
|
Time: ZeroTime,
|
2016-03-02 20:52:03 +00:00
|
|
|
Value: float64(r.sum) / float64(r.count),
|
|
|
|
Aggregated: r.count,
|
2016-03-07 18:25:45 +00:00
|
|
|
}}
|
2016-03-02 20:52:03 +00:00
|
|
|
}
|