1 Star 0 Fork 2

QunXiongZhuLu/kratos

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
reduce.go 1.38 KB
一键复制 编辑 原始数据 按行查看 历史
felixhao 提交于 2019-04-12 21:07 . add wiki
package metric
// Sum the values within the window.
func Sum(iterator Iterator) float64 {
var result = 0.0
for iterator.Next() {
bucket := iterator.Bucket()
for _, p := range bucket.Points {
result = result + p
}
}
return result
}
// Avg the values within the window.
func Avg(iterator Iterator) float64 {
var result = 0.0
var count = 0.0
for iterator.Next() {
bucket := iterator.Bucket()
for _, p := range bucket.Points {
result = result + p
count = count + 1
}
}
return result / count
}
// Min the values within the window.
func Min(iterator Iterator) float64 {
var result = 0.0
var started = false
for iterator.Next() {
bucket := iterator.Bucket()
for _, p := range bucket.Points {
if !started {
result = p
started = true
continue
}
if p < result {
result = p
}
}
}
return result
}
// Max the values within the window.
func Max(iterator Iterator) float64 {
var result = 0.0
var started = false
for iterator.Next() {
bucket := iterator.Bucket()
for _, p := range bucket.Points {
if !started {
result = p
started = true
continue
}
if p > result {
result = p
}
}
}
return result
}
// Count sums the count value within the window.
func Count(iterator Iterator) float64 {
var result int64
for iterator.Next() {
bucket := iterator.Bucket()
result += bucket.Count
}
return float64(result)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/QunXiongZhuLu/kratos.git
git@gitee.com:QunXiongZhuLu/kratos.git
QunXiongZhuLu
kratos
kratos
v0.6.2

搜索帮助