timeseries

package
v0.0.0-...-27e1478 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrOutsideDomain = errors.New("time is outside domain of time series")

Functions

This section is empty.

Types

type Point

type Point struct {
	Timestamp time.Time
	Value     float64
}

func (Point) FmtRelative

func (p Point) FmtRelative() string

FmtRelative formats the point nicely for log output, or any other output where the current point in time is known.

func (Point) MarshalBinary

func (p Point) MarshalBinary() (data []byte, err error)

MarshalBinary implements the encoding.BinaryMarshaler interface.

func (*Point) UnmarshalBinary

func (p *Point) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.

type TimeSeries

type TimeSeries []Point

func (*TimeSeries) AppendAndExpSmooth

func (ts *TimeSeries) AppendAndExpSmooth(p Point, v, τ float64) float64

AppendAndExpSmooth returns the exponentially smoothed value at the end of the time series. The time constant of smoothing is τ, given in seconds. `v` is the latest smoothed value as returned by this function or [ExpSmooth]. If the time series is empty, `v` is ignored and the value of the given point returned.

func (TimeSeries) ExpSmooth

func (ts TimeSeries) ExpSmooth(τ float64) (v float64)

ExpSmooth returns the exponentially smoothed value at the end of the time series. The time constant of smoothing is τ, given in seconds.

func (TimeSeries) Interpolate

func (ts TimeSeries) Interpolate(t time.Time) (float64, error)

Interpolate returns the value interpolated at the given time. If the timestamp is outside the domain of the time series, ErrOutsideDomain is returned.

func (TimeSeries) MarshalBinary

func (ts TimeSeries) MarshalBinary() (data []byte, err error)

MarshalBinary implements the encoding.BinaryMarshaler interface.

func (TimeSeries) Mollify

func (ts TimeSeries) Mollify(width float64, samples int, defaultV float64) (yMol float64)

Mollify returns the smoothed value of the y value which is the latest of the series. The windows width determines the intensity of smoothing and is given in seconds. The number of samples should be larger than the number of data points you expect within the window width. If there are too few data points for calculation, defaultV is returned. Note that a zero width yields the expected behavior, namely returning the latest value.

func (*TimeSeries) Prune

func (ts *TimeSeries) Prune(width float64)

Prune prunes the time series to the most recent data points not older than the last data point by the given width in seconds.

func (TimeSeries) String

func (ts TimeSeries) String() string

String implements the Stringer interface.

func (*TimeSeries) UnmarshalBinary

func (ts *TimeSeries) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.

Jump to

Keyboard shortcuts

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