Documentation
¶
Overview ¶
Package stats computes live per-tag rolling statistics (min/max/avg/count) over a core.TagDB stream — running KPIs for FameView 统计 dashboards.
A Collector subscribes to each tracked tag and folds every published sample into that tag's Stat. Because core.Tag.Subscribe PRIMES the callback once with the tag's current value at subscribe time, the first fold reflects the value present when Track was called: Count starts at 1 immediately after Track (the primed sample), before any further SetValue/Publish. Callers who want clean, predictable counts should set a known initial value before Track (or account for that one primed sample). Note also that core.Tag.Publish is notify-on-change: publishing a value equal to the current one is a no-op and is not folded.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Collector ¶
type Collector struct {
// contains filtered or unexported fields
}
Collector folds each tracked tag's value stream into a per-tag Stat. All methods are safe for concurrent use: samples fold on whatever goroutine drives SetValue/Publish, while readers call Get from any goroutine.
func NewCollector ¶
NewCollector returns a Collector reading from tags.
func (*Collector) Get ¶
Get returns a snapshot copy of the named tag's Stat and whether it is tracked. The returned Stat is a value copy and never mutates afterward.
func (*Collector) Reset ¶
Reset zeroes the named tag's Stat in place without dropping the subscription: subsequent values keep folding from a clean slate.
func (*Collector) StopAll ¶
func (c *Collector) StopAll()
StopAll unsubscribes from every tracked tag. Accumulated Stats remain readable via Get; only the subscriptions are torn down.
func (*Collector) Track ¶
Track resolves (creating if needed) the named tag and subscribes to it, folding each value's Float() into the tag's Stat. Subscribe primes with the tag's current value, so that primed sample is the first fold (Count 1). Tracking an already-tracked name is a no-op (it does not re-subscribe).