Documentation ¶
Index ¶
- Variables
- func GuessTimeFreq(ctx context.Context, ts *dataframe.SeriesTime, opts ...GuessTimeFreqOptions) (string, bool, error)
- func NewSeriesTime(ctx context.Context, name string, timeFreq string, startTime time.Time, ...) (*dataframe.SeriesTime, error)
- func ValidateSeriesTime(ctx context.Context, ts *dataframe.SeriesTime, timeFreq string, ...) error
- type GuessTimeFreqOptions
- type MissingValueOption
- type NewSeriesTimeOptions
- type NextTime
- type TimeGenerator
- type ValidateSeriesTimeOptions
Constants ¶
This section is empty.
Variables ¶
var ( // ErrContainsNil means that the SeriesTime contains nil values. ErrContainsNil = errors.New("contains nil") // ErrNoPattern means that no pattern was detected. ErrNoPattern = errors.New("no pattern detected") )
var ( // ErrCantValidate means that the validation algorithm could not determine whether the Series was in the reverse direction or not. ErrCantValidate = errors.New("can't validate") // ErrCantReplace means that the Validation algorithm was not able to determine what a missing value should be replaced as. ErrCantReplace = errors.New("can't replace") // ErrValidationFailed means that validation of the SeriesTime failed. ErrValidationFailed = errors.New("validation failed") )
Functions ¶
func GuessTimeFreq ¶
func GuessTimeFreq(ctx context.Context, ts *dataframe.SeriesTime, opts ...GuessTimeFreqOptions) (string, bool, error)
GuessTimeFreq will attempt to guess the time interval in a SeriesTime. It will return a string that is compatible with TimeIntervalGenerator. It will also return a bool indicating whether the sequence is in reverse.
Due to daylight savings and varying days per month, it is not always possible to determine a pattern with 100% confidence.
NOTE: As currently implemented, nil values are not tolerated.
func NewSeriesTime ¶
func NewSeriesTime(ctx context.Context, name string, timeFreq string, startTime time.Time, reverse bool, opts NewSeriesTimeOptions) (*dataframe.SeriesTime, error)
NewSeriesTime will create a new SeriesTime with timeFreq prescribing the intervals between each row. Setting reverse will make the time series decrement per row.
See https://godoc.org/github.com/jdfergason/dataframe-go/utils/utime#TimeIntervalGenerator for setting timeFreq.
func ValidateSeriesTime ¶
func ValidateSeriesTime(ctx context.Context, ts *dataframe.SeriesTime, timeFreq string, opts ValidateSeriesTimeOptions) error
ValidateSeriesTime will return an error if the SeriesTime's intervals don't match timeFreq.
Types ¶
type GuessTimeFreqOptions ¶
type GuessTimeFreqOptions struct { // Hint can be set if you have some idea what timeFreq may be. Hint string // R is used to limit the range of the Series. R *dataframe.Range // DontLock can be set to true if the Series should not be locked. DontLock bool }
GuessTimeFreqOptions configures how GuessTimeFreq behaves.
type MissingValueOption ¶
type MissingValueOption int
MissingValueOption sets how the ValidateSeriesTime behaves when a missing (nil) value is encountered.
const ( // Tolerate will ignore a missing value. Tolerate MissingValueOption = 0 // Replace will replace the missing value with a valid time.Time. Replace MissingValueOption = 1 // Error will generate an error if a missing value is encountered. Error MissingValueOption = 2 )
type NewSeriesTimeOptions ¶
type NewSeriesTimeOptions struct { // Size determines how many rows are generated. // This option can't be used with Until option. Size *int // Until is the maximum time in the generated Series. // This option can't be used with Size option. Until *time.Time }
NewSeriesTimeOptions sets how NewSeriesTime decides at which row to stop.
type NextTime ¶
NextTime will return the next time in the sequence. You can call it repeatedly to obtain a sequence.
type TimeGenerator ¶
TimeGenerator will create a generator function, which when called will return a sequence of times. The sequence will begin at startTime. When reverse is true, the sequence will be backwards.
func TimeIntervalGenerator ¶
func TimeIntervalGenerator(timeFreq string) (TimeGenerator, error)
TimeIntervalGenerator is used to create a sequence of times based on an interval defined by timeFreq. timeFreq can be in the format: nYnMnWnD, where n is a non-negative integer and Y, M, W and D represent years, months, weeks and days respectively. Alternatively, timeFreq can be a valid positive input to time.ParseDuration.
Example:
gen, _ := utime.TimeIntervalGenerator("1W1D") ntg := gen(time.Now().UTC(), false) for { fmt.Println(ntg()) time.Sleep(500 * time.Millisecond) }
type ValidateSeriesTimeOptions ¶
type ValidateSeriesTimeOptions struct { // MissingValue configures what must happen when a nil Value is encountered. MissingValue MissingValueOption // DontLock can be set to true if the Series should not be locked. DontLock bool }
ValidateSeriesTimeOptions configures how ValidateSeriesTime behaves.