timeserie

package module
v0.0.0-...-4c32af8 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2025 License: BSD-2-Clause Imports: 11 Imported by: 0

README

timeserie

'time' package based time series.

This package deals with timeseries.

It defines a Support, that holds couples of time.Time and float64 value in chronological order.

It defines a Function, based on a support, that can support different operations (add, mult, etc.).

It provides a jsonline format to serialize Supports into a value change dump format.

It provides utilities function to deal with filtering, grouping, sampling timeserie Supports.

Documentation

Index

Constants

View Source
const Day = 24 * time.Hour

Variables

View Source
var (
	CondPositive = func(v float64) bool { return v > 0 }
	CondNegative = func(v float64) bool { return v < 0 }
)
View Source
var (
	// list all scanner function
	ScannerAcc = func(c, v float64) float64 { return c + v }
)

Acc is a Scanner to compute the cumulative value of a support.

Functions

func CondEndOfMonth

func CondEndOfMonth(t time.Time) bool

CondEndOfMonth return true if 't' represent the last day of the month.

func CondQuarterly

func CondQuarterly(t time.Time) bool

CondQuarterly returns true if 't' represent the first day of a new quarter, jan or apr or jul or oct 1st.

func CondYearly

func CondYearly(t time.Time) bool

Condyearly returns true if 't' represent the first day of a new year (a january first).

func DayDate

func DayDate(year int, month time.Month, day int) time.Time

DayDate returns a comparable Time to identity a single day.

func Days

func Days(from, end time.Time, accept TimeCond) []time.Time

Days returns a list of all days starting with 'from' (included) ends after 'end' and return only days accepted by time condition.

func Format

func Format(w io.Writer, dict map[string]*Support) error

func Iterate

func Iterate(functions ...*Function) iter.Seq[time.Time]

Iterate returns an iterator over all event time in chronological order, without repetition.

func Load

func Load(dict map[string]*Support, r io.Reader) error

Load support from a value change dump stream.

func Open

func Open(dict map[string]*Support, filenames ...string) (map[string]*Support, error)

Open supports from a value change dump file.

Types

type Function

type Function struct {
	Support
	// contains filtered or unexported fields
}

Function is the interface of all support-based functions.

func Add

func Add(functions ...*Function) *Function

Add returns a new function that is the result of adding all functions

func Div

func Div(a, b *Function) *Function

Div returns a new function that is the result of a-b

func New

func New(s *Support, mode Mode) *Function

New creates a new function defined by its support and the interpolation mode.

func Sample

func Sample(times []time.Time, f *Function) *Function

Sample resample functions on a daily basis.

func Sub

func Sub(a, b *Function) *Function

Sub returns a new function that is the result of a-b

func Times

func Times(functions ...*Function) *Function

Times returns a new function that is the result of multiplying all functions

func (*Function) F

func (f *Function) F(t time.Time) float64

F returns the function value at a given time. If not defined on that time, it returns NaN.

type Mode

type Mode int
const (
	ModeNullset Mode = iota // function defined only on the support, NaN everywhere else.
	ModeStep                // Function's value between two support events is the value of the earliest.
	//ModeLinear              // Function's value between two support events is a linear interpolation between the two.
	LenMode // not a mode but the length of modes
)

type Scanner

type Scanner func(c, s float64) float64

Scanner is a function that can be used in the Scan method.

func ScannerIf

func ScannerIf(cond ValueCond) Scanner

ScannerIf returns a Scanner based on a condition. If condition is true the value is return, otherwise NaN is returned.

type Support

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

Support struct contains the time based finite support for real-valued functions.

func (*Support) Append

func (s *Support) Append(on time.Time, q float64)

Append a point to this support.

func (Support) At

func (s Support) At(i int) (time.Time, float64)

At return the point at given position in the support.

func (*Support) Delta

func (s *Support) Delta() *Support

Delta loop over all interval in this support and returns a new support defined at the end of each interval with the delta on this interval.

func (Support) Find

func (s Support) Find(t time.Time) int

Find returns the index of the closest value before 't'.

func (*Support) If

func (s *Support) If(cond ValueCond) *Support

If computes a new Support by keep only the value for a given condition.

func (Support) Len

func (s Support) Len() int

Len returns the timeserie support's length.

func (*Support) Scan

func (s *Support) Scan(initial float64, scanner Scanner) *Support

Scan computes a new Support by cumulating values, so that

c:= initial

for value 'v' in support 's' do c <- f(c, v) and append c to the new support

func (*Support) Times

func (s *Support) Times() iter.Seq[time.Time]

Iterate over dates in the support.

func (*Support) Values

func (s *Support) Values() iter.Seq2[time.Time, float64]

Values return an iterator over all values in the support.

type TimeCond

type TimeCond func(day time.Time) bool

TimeCond is a function to filter in some events

func CondMonthday

func CondMonthday(day int) TimeCond

func CondWeekday

func CondWeekday(day time.Weekday) TimeCond

type ValueCond

type ValueCond func(v float64) bool

ValueCond is a function that can be used to filter a support.

Jump to

Keyboard shortcuts

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