activity

package module
v0.0.0-...-1592289 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2015 License: Unlicense Imports: 3 Imported by: 0

README

go-activity

GoDoc

Package activity provides a decaying counter to estimate activity in a time series of events.

Documentation

Overview

Package activity provides a decaying activity counter.

A decaying counter is appropriate to estimate the best candidate to evict from, say, a cache, assuming the event stream is some Poisson process.

TODO redo the correction factors.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Counter

type Counter struct {
	Tau       time.Duration // Characteristic (filter decay) time
	Value     float64       // Decaying value
	Timestamp time.Time     // Time of last Tick
}

Counter contains a current Value and a Timestamp. To initialize, all you need to provide is Tau, eg

a := Counter{Tau: time.Hour}

Good choices or Tau are larger than the period with which you expect events to happen and small enough that your application adapts to changing circumstances. Eg. if you have an event stream of several events per second, and you have to make decisions about evicting a cache every few minutes, then a tau of a few minutes makes sense.

func Add

func Add(a, b Counter) Counter

Add returns the Activity that would be the result of the two event streams that lead to a and b combined. This is only really meaningful if a.Tau == b.Tau, but we will return an Activity with the min(Tau) of the two and apply a plausible correction factor.

func (Counter) Hz

func (a Counter) Hz() float64

Hz returns the current estimated frequency (in Hertz)

func (Counter) NextExpected

func (a Counter) NextExpected(now time.Time) time.Duration

NextExpected returns duration (relative to now) until the next expected event given the state of a, the fact that no new event happened until now, and assuming the event source is a Poisson process with a mean interval time much smaller than our Tau.

func (Counter) String

func (a Counter) String() string

String produces a nicely readable presentation.

func (*Counter) Tick

func (a *Counter) Tick()

Update the decaying activity counter by 1 event at now.

func (*Counter) TickN

func (a *Counter) TickN(ts time.Time, N int)

Update the decaying activity counter by N

Jump to

Keyboard shortcuts

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