tserie

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2023 License: MIT Imports: 3 Imported by: 2

README

tserie

Time Series data generator

Go Reference

Example

package main

import (
    "fmt"
    "time"

    "github.com/licaonfee/tserie"
)

func main() {
    start := time.Date(2022, 6, 26, 0, 0, 0, 0, time.UTC)
    stop := time.Date(2022, 6, 26, 1, 0, 0, 0, time.UTC)
    step := time.Minute
    value := tserie.Sine(time.Hour, 1, 0)
    ts := tserie.MakeTS(start, stop, step, value)
    for _, t := range ts {
        fmt.Printf("%02d = %.02f\n", t.Time.Minute(), t.Value)
    }
}

// This will generate 
// 00 = 0.00
// 01 = 0.10
// 02 = 0.21
// 03 = 0.31
// 04 = 0.41
// 05 = 0.50
// 06 = 0.59
// 07 = 0.67
// 08 = 0.74
// 09 = 0.81
// 10 = 0.87
// 11 = 0.91
// 12 = 0.95
// 13 = 0.98
// 14 = 0.99
// 15 = 1.00
// 16 = 0.99
// 17 = 0.98
// 18 = 0.95
// 19 = 0.91
// 20 = 0.87
// 21 = 0.81
// 22 = 0.74
// 23 = 0.67
// 24 = 0.59
// 25 = 0.50
// 26 = 0.41
// 27 = 0.31
// 28 = 0.21
// 29 = 0.10
// 30 = 0.00
// 31 = -0.10
// 32 = -0.21
// 33 = -0.31
// 34 = -0.41
// 35 = -0.50
// 36 = -0.59
// 37 = -0.67
// 38 = -0.74
// 39 = -0.81
// 40 = -0.87
// 41 = -0.91
// 42 = -0.95
// 43 = -0.98
// 44 = -0.99
// 45 = -1.00
// 46 = -0.99
// 47 = -0.98
// 48 = -0.95
// 49 = -0.91
// 50 = -0.87
// 51 = -0.81
// 52 = -0.74
// 53 = -0.67
// 54 = -0.59
// 55 = -0.50
// 56 = -0.41
// 57 = -0.31
// 58 = -0.21
// 59 = -0.10

Documentation

Overview

Package tserie generate time series data

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Cos added in v0.3.0

func Cos(period time.Duration, amplitude, vshift float64) func(time.Time) float64

Cos as y = amplitude*sin(frequency * relativeTime)+vshift

Example

ExampleCos generates a cosinusoidal function with period of one hour and samples every one minute

package main

import (
	"fmt"
	"time"

	"github.com/licaonfee/tserie"
)

func main() {
	start := time.Date(2022, 6, 26, 0, 0, 0, 0, time.UTC)
	stop := time.Date(2022, 6, 26, 1, 0, 0, 0, time.UTC)
	step := time.Minute
	value := tserie.Sin(time.Hour, 1, 0)
	ts := tserie.MakeTS(start, stop, step, value)
	for _, t := range ts {
		fmt.Printf("%02d = %.02f\n", t.Time.Minute(), t.Value)
	}

}
Output:

00 = 0.00
01 = 0.10
02 = 0.21
03 = 0.31
04 = 0.41
05 = 0.50
06 = 0.59
07 = 0.67
08 = 0.74
09 = 0.81
10 = 0.87
11 = 0.91
12 = 0.95
13 = 0.98
14 = 0.99
15 = 1.00
16 = 0.99
17 = 0.98
18 = 0.95
19 = 0.91
20 = 0.87
21 = 0.81
22 = 0.74
23 = 0.67
24 = 0.59
25 = 0.50
26 = 0.41
27 = 0.31
28 = 0.21
29 = 0.10
30 = 0.00
31 = -0.10
32 = -0.21
33 = -0.31
34 = -0.41
35 = -0.50
36 = -0.59
37 = -0.67
38 = -0.74
39 = -0.81
40 = -0.87
41 = -0.91
42 = -0.95
43 = -0.98
44 = -0.99
45 = -1.00
46 = -0.99
47 = -0.98
48 = -0.95
49 = -0.91
50 = -0.87
51 = -0.81
52 = -0.74
53 = -0.67
54 = -0.59
55 = -0.50
56 = -0.41
57 = -0.31
58 = -0.21
59 = -0.10
00 = 0.00

func Normal

func Normal(std, mean float64) func(time.Time) float64

Normal returns a normally distributed float64 as rand.NormFloat64() * std + mean

func Sin added in v0.3.0

func Sin(period time.Duration, amplitude, vshift float64) func(time.Time) float64

Sin as y = amplitude*sin(frequency * relativeTime)+vshift

Example

ExampleSin generates a sinusoidal function with period of one hour and samples every one minute

package main

import (
	"fmt"
	"time"

	"github.com/licaonfee/tserie"
)

func main() {
	start := time.Date(2022, 6, 26, 0, 0, 0, 0, time.UTC)
	stop := time.Date(2022, 6, 26, 1, 0, 0, 0, time.UTC)
	step := time.Minute
	value := tserie.Sin(time.Hour, 1, 0)
	ts := tserie.MakeTS(start, stop, step, value)
	for _, t := range ts {
		fmt.Printf("%02d = %.02f\n", t.Time.Minute(), t.Value)
	}

}
Output:

00 = 0.00
01 = 0.10
02 = 0.21
03 = 0.31
04 = 0.41
05 = 0.50
06 = 0.59
07 = 0.67
08 = 0.74
09 = 0.81
10 = 0.87
11 = 0.91
12 = 0.95
13 = 0.98
14 = 0.99
15 = 1.00
16 = 0.99
17 = 0.98
18 = 0.95
19 = 0.91
20 = 0.87
21 = 0.81
22 = 0.74
23 = 0.67
24 = 0.59
25 = 0.50
26 = 0.41
27 = 0.31
28 = 0.21
29 = 0.10
30 = 0.00
31 = -0.10
32 = -0.21
33 = -0.31
34 = -0.41
35 = -0.50
36 = -0.59
37 = -0.67
38 = -0.74
39 = -0.81
40 = -0.87
41 = -0.91
42 = -0.95
43 = -0.98
44 = -0.99
45 = -1.00
46 = -0.99
47 = -0.98
48 = -0.95
49 = -0.91
50 = -0.87
51 = -0.81
52 = -0.74
53 = -0.67
54 = -0.59
55 = -0.50
56 = -0.41
57 = -0.31
58 = -0.21
59 = -0.10
00 = 0.00

func Sine added in v0.2.0

func Sine(period time.Duration, amplitude, vshift float64) func(time.Time) float64

Sine as y = amplitude*sin(bx)+vshift

Types

type Point

type Point struct {
	Time  time.Time
	Value float64
}

Point contains a pair time,value

func MakeTS

func MakeTS(start, stop time.Time, step time.Duration, getValue func(time.Time) float64) []Point

MakeTS create a new time serie between start and stop with all the time values given by step

type TimeIterator

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

TimeIterator generates datapoints in the same way as MakeTS but is suitable for big datasets

func NewTimeIterator

func NewTimeIterator(start, stop time.Time, step time.Duration, gen func(time.Time) float64) *TimeIterator

NewTimeIterator creates a new TimeIterator

func (*TimeIterator) Item

func (it *TimeIterator) Item() Point

Item returns the current data point

func (*TimeIterator) Next

func (it *TimeIterator) Next() bool

Next returns true while current time is before stop

Jump to

Keyboard shortcuts

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