Documentation
¶
Index ¶
- Variables
- type Point
- type TimeSeries
- func (ts *TimeSeries) AppendAndExpSmooth(p Point, v, τ float64) float64
- func (ts TimeSeries) ExpSmooth(τ float64) (v float64)
- func (ts TimeSeries) Interpolate(t time.Time) (float64, error)
- func (ts TimeSeries) MarshalBinary() (data []byte, err error)
- func (ts TimeSeries) Mollify(width float64, samples int, defaultV float64) (yMol float64)
- func (ts *TimeSeries) Prune(width float64)
- func (ts TimeSeries) String() string
- func (ts *TimeSeries) UnmarshalBinary(data []byte) error
Constants ¶
This section is empty.
Variables ¶
var ErrOutsideDomain = errors.New("time is outside domain of time series")
Functions ¶
This section is empty.
Types ¶
type Point ¶
func (Point) FmtRelative ¶
FmtRelative formats the point nicely for log output, or any other output where the current point in time is known.
func (Point) MarshalBinary ¶
MarshalBinary implements the encoding.BinaryMarshaler interface.
func (*Point) UnmarshalBinary ¶
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.