代码拉取完成,页面将自动刷新
package oncall
import "time"
// RulesCalculator provides a single interface for calculating active users of a set of ResolvedRules.
type RulesCalculator struct {
*TimeIterator
rules []*SingleRuleCalculator
userIDs []string
changed bool
}
// NewRulesCalculator will create a new RulesCalculator bound to the TimeIterator.
func (t *TimeIterator) NewRulesCalculator(loc *time.Location, rules []ResolvedRule) *RulesCalculator {
calc := &RulesCalculator{
TimeIterator: t,
}
for _, r := range rules {
calc.rules = append(calc.rules, t.NewSingleRuleCalculator(loc, r))
}
t.Register(calc)
return calc
}
// Process implements the SubIterator.Process method.
func (rCalc *RulesCalculator) Process(int64) int64 {
rCalc.changed = false
for _, r := range rCalc.rules {
if !r.Changed() {
continue
}
rCalc.changed = true
break
}
// no rules changed, abort
if !rCalc.changed {
return 0
}
rCalc.userIDs = rCalc.userIDs[:0]
for _, r := range rCalc.rules {
id := r.ActiveUser()
if id == "" {
continue
}
rCalc.userIDs = append(rCalc.userIDs, id)
}
return 0
}
// Done implements the SubIterator.Done method.
func (rCalc *RulesCalculator) Done() {}
// ActiveUsers returns the current set of active users for the current timestamp.
// It is only valid until the following Next() call and should not be modified.
func (rCalc *RulesCalculator) ActiveUsers() []string { return rCalc.userIDs }
// Changed will return true if there has been any change this tick.
func (rCalc *RulesCalculator) Changed() bool { return rCalc.changed }
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。