timeseries

package
v1.18.2 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2022 License: MIT Imports: 17 Imported by: 1

README

Time Series

The timeseries package is used to hold time series data, often for creating time-based bar or line charts. Each time value can be stored as a float or an integer. Data for multiple series are stored by TimeSeriesSet.

Major structs

  • TimeSeries: a single time series
  • TimeSeriesSet: mulitple time series sets

Documentation

Overview

timeseries provides tools for adding and formatting static time series data for reporting purposes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReportAxisX

func ReportAxisX(set TimeSeriesSet, cols int, conv func(time.Time) string) []string

ReportAxisX generates data for use with `C3Chart.C3Axis.C3AxisX.Categories`.

func TimeFormatNiceMonth

func TimeFormatNiceMonth(dt time.Time) string

func TimeFormatNiceQuarter

func TimeFormatNiceQuarter(dt time.Time) string

func TimeFormatRFC3339

func TimeFormatRFC3339(dt time.Time) string

func TimeSeriesMapMinMaxTimes

func TimeSeriesMapMinMaxTimes(tsm map[string]TimeSeries) (time.Time, time.Time, error)

func TimeSeriesMapMinMaxValues

func TimeSeriesMapMinMaxValues(tsm map[string]TimeSeries) (int64, int64, error)

func TimeSeriesSliceNames

func TimeSeriesSliceNames(tsSlice []TimeSeries) []string

func TimeSeriesSliceTable

func TimeSeriesSliceTable(tsSlice []TimeSeries) table.Table

func TimeSeriesSliceTimes

func TimeSeriesSliceTimes(tsSlice []TimeSeries) []string

func TimeSeriesSliceWriteXLSX

func TimeSeriesSliceWriteXLSX(filename string, tsSlice []TimeSeries) error

TimeSeries writes a slice of TimeSeries to an Excel XLSX file for easy consumption.

Types

type RowFloat64

type RowFloat64 struct {
	Name   string
	Values []float64
}

func ReportFunnelPct

func ReportFunnelPct(rows []RowInt64) []RowFloat64

func ReportGrowthPct

func ReportGrowthPct(rows []RowInt64) []RowFloat64

func (*RowFloat64) Flatten

func (row *RowFloat64) Flatten(conv func(v float64) string, preCount int, preVal string) []string

type RowInt64

type RowInt64 struct {
	Name         string
	DisplayName  string
	HavePlusOne  bool
	ValuePlusOne int64
	Values       []int64
}

func Report

func Report(set TimeSeriesSet, cols int, lowFirst bool) []RowInt64

Report generates data for use with `C3Chart.C3ChartData.Columns`.

func (*RowInt64) Flatten

func (row *RowInt64) Flatten(conv func(v int64) string) []string

type TableConfig

type TableConfig struct {
	CountColIdx         uint
	TimeColIdx          uint
	TimeFormat          string
	SeriesSetNameColIdx int // optional. Set < 0 to discard.
	SeriesNameColIdx    int
	Interval            timeutil.Interval
}

func (*TableConfig) GetTimeFormat

func (cfg *TableConfig) GetTimeFormat() string

type TimeItem

type TimeItem struct {
	SeriesName    string
	SeriesSetName string
	Time          time.Time
	IsFloat       bool
	Value         int64
	ValueFloat    float64
}

func ParseRecordsTimeItems added in v1.7.1

func ParseRecordsTimeItems(records [][]string, cfg TableConfig) ([]TimeItem, error)

func (*TimeItem) Float64 added in v1.16.0

func (item *TimeItem) Float64() float64

func (*TimeItem) Int64 added in v1.16.0

func (item *TimeItem) Int64() int64

type TimeSeries

type TimeSeries struct {
	SeriesName    string
	SeriesSetName string
	ItemMap       map[string]TimeItem
	IsFloat       bool
	Interval      timeutil.Interval // Informational
}

func AggregateSeries

func AggregateSeries(series TimeSeries) TimeSeries

func NewTimeSeries

func NewTimeSeries(name string) TimeSeries

NewTimeSeries instantiates a `TimeSeries` struct.

func ReadFileTimeSeries added in v1.15.2

func ReadFileTimeSeries(filename string) (TimeSeries, error)

ReadFileTimeSeries reads a time series file in JSON.

func TimeSeriesDivide

func TimeSeriesDivide(numer, denom TimeSeries) (TimeSeries, error)

func (*TimeSeries) AddFloat64 added in v1.9.0

func (ts *TimeSeries) AddFloat64(dt time.Time, value float64)

AddFloat64 adds a time value, converting it to a int64 on the series type.

func (*TimeSeries) AddInt64 added in v1.9.0

func (ts *TimeSeries) AddInt64(dt time.Time, value int64)

AddInt64 adds a time value, converting it to a float on the series type.

func (*TimeSeries) AddItems added in v1.9.0

func (ts *TimeSeries) AddItems(items ...TimeItem)

AddItems adds a `TimeItem`. It will sum values when existing time unit is encountered.

func (*TimeSeries) DeleteTime added in v1.7.3

func (ts *TimeSeries) DeleteTime(dt time.Time)

func (*TimeSeries) Get added in v1.16.0

func (ts *TimeSeries) Get(dt time.Time) (TimeItem, error)

Get returns a `TimeItem` given a `time.Time`.

func (*TimeSeries) ItemTimes

func (ts *TimeSeries) ItemTimes() []time.Time

func (*TimeSeries) ItemsSorted

func (ts *TimeSeries) ItemsSorted() []TimeItem

ItemsSorted returns sorted TimeItems. This currently uses a simple string sort on RFC3339 times.

func (*TimeSeries) Keys

func (ts *TimeSeries) Keys() []string

Keys returns a sorted listed of Item keys.

func (*TimeSeries) Last

func (ts *TimeSeries) Last() (TimeItem, error)

func (*TimeSeries) LastItem

func (ts *TimeSeries) LastItem(skipIfTimePartialValueLessPrev bool) (TimeItem, error)

func (*TimeSeries) MaxValue

func (ts *TimeSeries) MaxValue() int64

func (*TimeSeries) MinMaxTimes

func (ts *TimeSeries) MinMaxTimes() (time.Time, time.Time)

func (*TimeSeries) MinMaxValues

func (ts *TimeSeries) MinMaxValues() (int64, int64)

func (*TimeSeries) MinMaxValuesFloat64

func (ts *TimeSeries) MinMaxValuesFloat64() (float64, float64)

func (*TimeSeries) MinValue

func (ts *TimeSeries) MinValue() int64

func (*TimeSeries) OneItemMaxValue

func (ts *TimeSeries) OneItemMaxValue() (TimeItem, error)

func (*TimeSeries) Pop

func (ts *TimeSeries) Pop() (TimeItem, error)

Pop removes the item with the chronologically last time. This is useful when generating interval charts and the last period has not concluded, thus providing an inaccurate projection when compared to previous full months of data.

func (*TimeSeries) SetSeriesName

func (ts *TimeSeries) SetSeriesName(seriesName string)

func (*TimeSeries) Stats

func (ts *TimeSeries) Stats() point.PointSet

func (*TimeSeries) TimeSeries

func (ts *TimeSeries) TimeSeries(interval timeutil.Interval) []time.Time

func (*TimeSeries) TimeSlice

func (ts *TimeSeries) TimeSlice(sortSlice bool) timeslice.TimeSlice

func (*TimeSeries) ToMonth

func (ts *TimeSeries) ToMonth(inflate bool) TimeSeries

ToMonth aggregates time values into months. `inflate` is used to add months with `0` values.

func (*TimeSeries) ToMonthCumulative

func (ts *TimeSeries) ToMonthCumulative(inflate bool, timesInput ...time.Time) (TimeSeries, error)

func (*TimeSeries) ToQuarter

func (ts *TimeSeries) ToQuarter() TimeSeries

func (*TimeSeries) ToTable added in v1.7.3

func (ts *TimeSeries) ToTable(tableName, dateColumnName, countColumnName string, dtFmt func(dt time.Time) string) table.Table

ToTable generates a `table.Table` given a `TimeSeries`.

func (*TimeSeries) WriteJSON added in v1.15.1

func (ts *TimeSeries) WriteJSON(filename string, perm os.FileMode, prefix, indent string) error

WriteJSON writes the data to a JSON file. To write a minimized JSON file use an empty string for `prefix` and `indent`.

func (*TimeSeries) WriteXLSX

func (ts *TimeSeries) WriteXLSX(filename string, sheetName, dateColumnName, countColumnName string) error

WriteXLSX writes an XSLX file given a `TimeSeries`

type TimeSeriesFunnel

type TimeSeriesFunnel struct {
	Series map[string]TimeSeriesSimple
	Order  []string
}

func (*TimeSeriesFunnel) TimeSeriesSetByQuarter

func (tsf *TimeSeriesFunnel) TimeSeriesSetByQuarter() (TimeSeriesSet, error)

func (*TimeSeriesFunnel) Times

func (tsf *TimeSeriesFunnel) Times() []time.Time

func (*TimeSeriesFunnel) TimesSorted

func (tsf *TimeSeriesFunnel) TimesSorted() []time.Time

type TimeSeriesSet

type TimeSeriesSet struct {
	Name     string
	Series   map[string]TimeSeries
	Times    []time.Time
	Order    []string
	IsFloat  bool
	Interval timeutil.Interval
}

func NewTimeSeriesSet

func NewTimeSeriesSet(name string) TimeSeriesSet

func ReadFileTimeSeriesSet added in v1.15.3

func ReadFileTimeSeriesSet(filename string) (TimeSeriesSet, error)

ReadFileTimeSeriesSet reads a time series set file in JSON.

func (*TimeSeriesSet) AddFloat64 added in v1.9.0

func (set *TimeSeriesSet) AddFloat64(seriesName string, dt time.Time, value float64)

AddFloat64 adds a time value, converting it to a int64 on the series type.

func (*TimeSeriesSet) AddInt64 added in v1.9.0

func (set *TimeSeriesSet) AddInt64(seriesName string, dt time.Time, value int64)

func (*TimeSeriesSet) AddItems

func (set *TimeSeriesSet) AddItems(items ...TimeItem)

func (*TimeSeriesSet) AddSeries added in v1.7.1

func (set *TimeSeriesSet) AddSeries(timeSeries ...TimeSeries) error

func (*TimeSeriesSet) DeleteTime added in v1.7.3

func (set *TimeSeriesSet) DeleteTime(dt time.Time)

func (*TimeSeriesSet) GetSeriesByIndex

func (set *TimeSeriesSet) GetSeriesByIndex(index int) (TimeSeries, error)

func (*TimeSeriesSet) Inflate

func (set *TimeSeriesSet) Inflate()

func (*TimeSeriesSet) Item

func (set *TimeSeriesSet) Item(seriesName, rfc3339 string) (TimeItem, error)

func (*TimeSeriesSet) MinMaxTimes

func (set *TimeSeriesSet) MinMaxTimes() (time.Time, time.Time)

func (*TimeSeriesSet) MinMaxValues

func (set *TimeSeriesSet) MinMaxValues() (int64, int64)

func (*TimeSeriesSet) MinMaxValuesFloat64

func (set *TimeSeriesSet) MinMaxValuesFloat64() (float64, float64)

func (*TimeSeriesSet) PopLast

func (set *TimeSeriesSet) PopLast()

func (*TimeSeriesSet) SeriesNames

func (set *TimeSeriesSet) SeriesNames() []string

func (*TimeSeriesSet) TimeSlice

func (set *TimeSeriesSet) TimeSlice(sortAsc bool) timeslice.TimeSlice

func (*TimeSeriesSet) TimeStrings

func (set *TimeSeriesSet) TimeStrings() []string

func (*TimeSeriesSet) ToMonth

func (set *TimeSeriesSet) ToMonth(cumulative, inflate, popLast bool) (TimeSeriesSet, error)

ToMonth aggregates time values into months. `inflate` is used to add months with `0` values.

func (*TimeSeriesSet) ToNewSeriesNames

func (set *TimeSeriesSet) ToNewSeriesNames(seriesNames, seriesSetNames map[string]string) TimeSeriesSet

func (*TimeSeriesSet) ToSetTimesRangeUpper added in v1.14.2

func (set *TimeSeriesSet) ToSetTimesRangeUpper(inclusive bool, times ...time.Time) (TimeSeriesSet, error)

func (*TimeSeriesSet) ToTable

func (set *TimeSeriesSet) ToTable(opts *TimeSeriesSetTableOpts) (table.Table, error)

ToTable returns a `table.TableData`.

func (*TimeSeriesSet) WriteJSON added in v1.15.1

func (set *TimeSeriesSet) WriteJSON(filename string, perm os.FileMode, prefix, indent string) error

WriteJSON writes the TimeSeriesSet to a JSON file. To write a minimized JSON file use an empty string for `prefix` and `indent`.

func (*TimeSeriesSet) WriteXLSX

func (set *TimeSeriesSet) WriteXLSX(filename string, opts *TimeSeriesSetTableOpts) error

WriteXLSX writes the TimeSeriesSet as a XLSX spreadsheet file.

type TimeSeriesSetTableOpts added in v1.9.0

type TimeSeriesSetTableOpts struct {
	TimeColumnTitle string
	FuncFormatTime  func(time.Time) string
	TotalInclude    bool
	TotalTitle      string
	PercentInclude  bool
	PercentSuffix   string
}

func (*TimeSeriesSetTableOpts) PercentSuffixOrDefault added in v1.9.0

func (opts *TimeSeriesSetTableOpts) PercentSuffixOrDefault() string

func (*TimeSeriesSetTableOpts) TotalTitleOrDefault added in v1.9.0

func (opts *TimeSeriesSetTableOpts) TotalTitleOrDefault() string

type TimeSeriesSets added in v1.7.4

type TimeSeriesSets struct {
	Name      string
	SetsMap   map[string]TimeSeriesSet
	Order     []string
	KeyIsTime bool
	Interval  timeutil.Interval
}

func NewTimeSeriesSets added in v1.7.4

func NewTimeSeriesSets(name string) TimeSeriesSets

func (*TimeSeriesSets) AddItems added in v1.7.4

func (sets *TimeSeriesSets) AddItems(items ...TimeItem)

func (*TimeSeriesSets) SeriesNames added in v1.14.1

func (sets *TimeSeriesSets) SeriesNames() []string

func (*TimeSeriesSets) SetNames added in v1.14.1

func (sets *TimeSeriesSets) SetNames() []string

func (*TimeSeriesSets) WriteJSON added in v1.15.1

func (sets *TimeSeriesSets) WriteJSON(filename string, perm os.FileMode, prefix, indent string) error

WriteJSON writes the data to a JSON file. To write a minimized JSON file use an empty string for `prefix` and `indent`.

type TimeSeriesSimple

type TimeSeriesSimple struct {
	Name        string
	DisplayName string
	Times       []time.Time
}

func NewTimeSeriesSimple

func NewTimeSeriesSimple(name, displayName string) TimeSeriesSimple

func (*TimeSeriesSimple) ToTimeSeriesQuarter

func (tss *TimeSeriesSimple) ToTimeSeriesQuarter() TimeSeries

type TimeStats

type TimeStats struct {
	Items []TimeItem
}

TimeStats is used to generate unique counts stats for an array of with time ane names.

func (*TimeStats) UniqueCountsByMonth

func (ts *TimeStats) UniqueCountsByMonth() map[string]int

func (*TimeStats) UniqueCountsByQuarter

func (ts *TimeStats) UniqueCountsByQuarter() map[string]int

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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