stats

package
v0.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 16, 2026 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package stats provides streaming measurement math — running mean/variance, jitter, and sequence-based loss/duplicate/reorder detection — as pure values with no global state. See docs/blueprints/stats-engine.md and DESIGN.md §7.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Jitter

type Jitter struct {
	// contains filtered or unexported fields
}

Jitter tracks the mean absolute difference between consecutive observations.

func (*Jitter) Add

func (j *Jitter) Add(x float64)

Add incorporates one observation.

func (*Jitter) Mean

func (j *Jitter) Mean() float64

Mean returns the mean absolute consecutive difference (0 if fewer than two).

type SeqTracker

type SeqTracker struct {
	// contains filtered or unexported fields
}

SeqTracker detects loss, duplicates, and reordering over a stream of sequence numbers (e.g. from the patterned payloader). Loss is inferred from the highest sequence seen versus the count of distinct sequences received.

It retains the set of seen sequences, so memory grows with distinct sequences; a windowed variant is a later optimization.

func NewSeqTracker

func NewSeqTracker() *SeqTracker

NewSeqTracker returns an empty tracker.

func (*SeqTracker) Duplicates

func (t *SeqTracker) Duplicates() uint64

Duplicates returns the count of repeated sequences.

func (*SeqTracker) Expected

func (t *SeqTracker) Expected() uint64

Expected returns maxSeq+1 — the number of packets that should have arrived if sequences start at 0 and are contiguous.

func (*SeqTracker) LossPercent

func (t *SeqTracker) LossPercent() float64

LossPercent returns loss as a percentage of Expected.

func (*SeqTracker) Lost

func (t *SeqTracker) Lost() uint64

Lost returns Expected minus distinct Received (never negative).

func (*SeqTracker) Observe

func (t *SeqTracker) Observe(seq uint64)

Observe records one received sequence number.

func (*SeqTracker) Received

func (t *SeqTracker) Received() uint64

Received returns the number of distinct sequences received.

func (*SeqTracker) Reordered

func (t *SeqTracker) Reordered() uint64

Reordered returns the count of sequences that arrived below the running max.

func (*SeqTracker) Total

func (t *SeqTracker) Total() uint64

Total returns the count of observations including duplicates.

type Stream

type Stream struct {
	// contains filtered or unexported fields
}

Stream computes count, min, max, mean, variance, std-dev, and coefficient of variation incrementally (Welford's algorithm) without retaining samples.

func (*Stream) Add

func (s *Stream) Add(x float64)

Add incorporates one observation.

func (*Stream) CoV

func (s *Stream) CoV() float64

CoV returns the coefficient of variation (std-dev / mean), 0 if mean is 0.

func (*Stream) Count

func (s *Stream) Count() uint64

Count returns the number of observations.

func (*Stream) Max

func (s *Stream) Max() float64

Max returns the largest observation (0 if empty).

func (*Stream) Mean

func (s *Stream) Mean() float64

Mean returns the running mean (0 if empty).

func (*Stream) Min

func (s *Stream) Min() float64

Min returns the smallest observation (0 if empty).

func (*Stream) StdDev

func (s *Stream) StdDev() float64

StdDev returns the sample standard deviation.

func (*Stream) Variance

func (s *Stream) Variance() float64

Variance returns the sample variance (0 with fewer than two observations).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL