Documentation ¶
Overview ¶
timeseries provides tools for adding and formatting static time series data for reporting purposes.
Index ¶
- func ReportAxisX(set TimeSeriesSet, cols int, conv func(time.Time) string) []string
- func TimeFormatNiceMonth(dt time.Time) string
- func TimeFormatNiceQuarter(dt time.Time) string
- func TimeFormatRFC3339(dt time.Time) string
- func TimeSeriesMapMinMaxTimes(dsm map[string]TimeSeries) (time.Time, time.Time, error)
- func TimeSeriesMapMinMaxValues(tsm map[string]TimeSeries) (int64, int64, error)
- func TimeSeriesSliceNames(dsSlice []TimeSeries) []string
- func TimeSeriesSliceTable(dsSlice []TimeSeries) table.Table
- func TimeSeriesSliceTimes(dsSlice []TimeSeries) []string
- func TimeSeriesSliceWriteXLSX(filename string, dsSlice []TimeSeries) error
- type RowFloat64
- type RowInt64
- type TableConfig
- type TimeItem
- type TimeSeries
- func (ts *TimeSeries) AddFloat64(dt time.Time, value float64)
- func (ts *TimeSeries) AddInt64(dt time.Time, value int64)
- func (ts *TimeSeries) AddItems(items ...TimeItem)
- func (ts *TimeSeries) DeleteTime(dt time.Time)
- func (ts *TimeSeries) Get(dt time.Time) (TimeItem, error)
- func (ts *TimeSeries) ItemTimes() []time.Time
- func (ts *TimeSeries) ItemsSorted() []TimeItem
- func (ts *TimeSeries) Keys() []string
- func (ts *TimeSeries) Last() (TimeItem, error)
- func (ts *TimeSeries) LastItem(skipIfTimePartialValueLessPrev bool) (TimeItem, error)
- func (ts *TimeSeries) MaxValue() int64
- func (ts *TimeSeries) MinMaxTimes() (time.Time, time.Time)
- func (ts *TimeSeries) MinMaxValues() (int64, int64)
- func (ts *TimeSeries) MinMaxValuesFloat64() (float64, float64)
- func (ts *TimeSeries) MinValue() int64
- func (ts *TimeSeries) OneItemMaxValue() (TimeItem, error)
- func (ts *TimeSeries) Pop() (TimeItem, error)
- func (ts *TimeSeries) SetSeriesName(seriesName string)
- func (ts *TimeSeries) Stats() point.PointSet
- func (ts *TimeSeries) TimeSeries(interval timeutil.Interval) []time.Time
- func (ts *TimeSeries) TimeSlice(sortSlice bool) timeslice.TimeSlice
- func (ts *TimeSeries) ToMonth(inflate bool) TimeSeries
- func (ts *TimeSeries) ToMonthCumulative(inflate bool, timesInput ...time.Time) (TimeSeries, error)
- func (ts *TimeSeries) ToQuarter() TimeSeries
- func (ts *TimeSeries) ToTable(tableName, dateColumnName, countColumnName string, ...) table.Table
- func (ts *TimeSeries) WriteJSON(filename string, perm os.FileMode, prefix, indent string) error
- func (ts *TimeSeries) WriteXLSX(filename string, sheetName, dateColumnName, countColumnName string) error
- type TimeSeriesFunnel
- type TimeSeriesSet
- func (set *TimeSeriesSet) AddFloat64(seriesName string, dt time.Time, value float64)
- func (set *TimeSeriesSet) AddInt64(seriesName string, dt time.Time, value int64)
- func (set *TimeSeriesSet) AddItems(items ...TimeItem)
- func (set *TimeSeriesSet) AddSeries(timeSeries ...TimeSeries) error
- func (set *TimeSeriesSet) DeleteTime(dt time.Time)
- func (set *TimeSeriesSet) GetSeriesByIndex(index int) (TimeSeries, error)
- func (set *TimeSeriesSet) Inflate()
- func (set *TimeSeriesSet) Item(seriesName, rfc3339 string) (TimeItem, error)
- func (set *TimeSeriesSet) MinMaxTimes() (time.Time, time.Time)
- func (set *TimeSeriesSet) MinMaxValues() (int64, int64)
- func (set *TimeSeriesSet) MinMaxValuesFloat64() (float64, float64)
- func (set *TimeSeriesSet) PopLast()
- func (set *TimeSeriesSet) SeriesNames() []string
- func (set *TimeSeriesSet) TimeSlice(sortAsc bool) timeslice.TimeSlice
- func (set *TimeSeriesSet) TimeStrings() []string
- func (set *TimeSeriesSet) ToMonth(cumulative, inflate, popLast bool) (TimeSeriesSet, error)
- func (set *TimeSeriesSet) ToNewSeriesNames(seriesNames, seriesSetNames map[string]string) TimeSeriesSet
- func (set *TimeSeriesSet) ToSetTimesRangeUpper(inclusive bool, times ...time.Time) (TimeSeriesSet, error)
- func (set *TimeSeriesSet) ToTable(opts *TimeSeriesSetTableOpts) (table.Table, error)
- func (set *TimeSeriesSet) WriteJSON(filename string, perm os.FileMode, prefix, indent string) error
- func (set *TimeSeriesSet) WriteXLSX(filename string, opts *TimeSeriesSetTableOpts) error
- type TimeSeriesSetTableOpts
- type TimeSeriesSets
- type TimeSeriesSimple
- type TimeStats
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ReportAxisX ¶
ReportAxisX generates data for use with `C3Chart.C3Axis.C3AxisX.Categories`.
func TimeFormatNiceMonth ¶
func TimeFormatNiceQuarter ¶
func TimeFormatRFC3339 ¶
func TimeSeriesMapMinMaxValues ¶
func TimeSeriesMapMinMaxValues(tsm map[string]TimeSeries) (int64, int64, error)
func TimeSeriesSliceNames ¶
func TimeSeriesSliceNames(dsSlice []TimeSeries) []string
func TimeSeriesSliceTable ¶
func TimeSeriesSliceTable(dsSlice []TimeSeries) table.Table
func TimeSeriesSliceTimes ¶
func TimeSeriesSliceTimes(dsSlice []TimeSeries) []string
func TimeSeriesSliceWriteXLSX ¶
func TimeSeriesSliceWriteXLSX(filename string, dsSlice []TimeSeries) error
TimeSeries writes a slice of TimeSeries to an Excel XLSX file for easy consumption.
Types ¶
type RowFloat64 ¶
func ReportFunnelPct ¶
func ReportFunnelPct(rows []RowInt64) []RowFloat64
func ReportGrowthPct ¶
func ReportGrowthPct(rows []RowInt64) []RowFloat64
type RowInt64 ¶
type RowInt64 struct { Name string DisplayName string HavePlusOne bool ValuePlusOne int64 Values []int64 }
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)
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) 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`.
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
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
type TimeSeriesSimple ¶
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.