histogram

package
v2.18.5 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2024 License: MIT Imports: 23 Imported by: 10

Documentation

Index

Constants

View Source
const (
	SortNameAsc   = maputil.SortNameAsc
	SortNameDesc  = maputil.SortNameDesc
	SortValueAsc  = maputil.SortValueAsc
	SortValueDesc = maputil.SortValueDesc
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Histogram

type Histogram struct {
	Name        string
	Bins        map[string]int
	Counts      map[string]int // how many items have counts.
	Percentages map[string]float64
}

Histogram is used to count how many times an item appears and how many times number of appearances appear. It can be used with simple string keys or `map[string]string` keys which are converted to soerted query strings.

func NewHistogram

func NewHistogram(name string) *Histogram

func ParseFileCSV

func ParseFileCSV(file string, name string, binNameColIdx, binFrequencyColIdx uint) (*Histogram, error)

ParseFileCSV reads a CSV using default settings of `,` separator, header row and BOM to be stripped. If you have other configurations, use `table.ReadFile()` directly and call `HistogramFromTable()`.

func ParseTable

func ParseTable(tbl table.Table, binNameColIdx, binFrequencyColIdx uint) (*Histogram, error)

ParseTable parses a `table.Table` to a `Histogram` given a table, binName column index and binFrequency column index. Empty rows are skipped.

func (*Histogram) Add

func (hist *Histogram) Add(binName string, binCount int)

func (*Histogram) AddBulk added in v2.11.0

func (hist *Histogram) AddBulk(m map[string]int)

func (*Histogram) AddMap added in v2.10.0

func (hist *Histogram) AddMap(binMap map[string]string, binCount int)

AddMap provides a helper function to automatically create url encoded string keys. This can be used with `TableMap` to generate tables with arbitrary columns easily.

func (*Histogram) BinCount

func (hist *Histogram) BinCount(binName string) (int, error)

func (*Histogram) BinCountOrDefault added in v2.13.0

func (hist *Histogram) BinCountOrDefault(binName string, def int) int

func (*Histogram) BinNameExists

func (hist *Histogram) BinNameExists(binName string) bool

func (*Histogram) BinNames

func (hist *Histogram) BinNames() []string

func (*Histogram) Inflate

func (hist *Histogram) Inflate()

func (*Histogram) ItemCount added in v2.11.2

func (hist *Histogram) ItemCount() uint

func (*Histogram) ItemCounts

func (hist *Histogram) ItemCounts(sortBy string) []maputil.Record

ItemCounts returns sorted item names and values.

func (*Histogram) ItemNames added in v2.12.0

func (hist *Histogram) ItemNames() []string

func (*Histogram) Map added in v2.16.0

func (hist *Histogram) Map() map[string]int

func (*Histogram) MapAdd added in v2.16.0

func (hist *Histogram) MapAdd(m map[string]int)

func (*Histogram) MapKeySplit added in v2.16.2

func (hist *Histogram) MapKeySplit(mapKey string, mapValIncl []string) (*HistogramSet, error)

MapKeySplit returns a new `HistogramSet` where the supplied key is the HistogramSet key.

func (*Histogram) MapKeyValues added in v2.16.2

func (hist *Histogram) MapKeyValues(key string, dedupe bool) ([]string, error)

MapKeyValues returns a list of keys using query string keys.

func (*Histogram) MapKeys added in v2.10.0

func (hist *Histogram) MapKeys() ([]string, error)

MapKeys returns a list of keys using query string keys.

func (*Histogram) MapKeysFlattenSingle added in v2.17.0

func (hist *Histogram) MapKeysFlattenSingle(mapKeyFilter string) (*Histogram, error)

func (*Histogram) MapKeysReduce added in v2.17.0

func (hist *Histogram) MapKeysReduce(mapKeysFilter []string) (*Histogram, error)

MapKeysReduce returns a new `Histogram` with only the supplied keys present.

func (*Histogram) Stats

func (hist *Histogram) Stats() point.PointSet

func (*Histogram) Sum

func (hist *Histogram) Sum() int

func (*Histogram) Table

func (hist *Histogram) Table(colNameBinName, colNameBinCount string) *table.Table

func (*Histogram) TableMap added in v2.10.0

func (hist *Histogram) TableMap(mapCols []string, colNameBinCount string) (*table.Table, error)

TableMap is used to generate a table using map keys.

func (*Histogram) TableSetMap added in v2.16.2

func (hist *Histogram) TableSetMap(cfgs []HistogramMapTableConfig) (*table.TableSet, error)

func (*Histogram) TransformBinNames

func (hist *Histogram) TransformBinNames(xfFunc func(input string) string) *Histogram

TransformBinNames modifies bin names and returns a new histogram.

func (*Histogram) TransformBinNamesMap

func (hist *Histogram) TransformBinNamesMap(xfMap map[string]string, matchType string) *Histogram

TransformBinNamesMap modifies bin names and returns a new histogram. `matchType` can be set to `prefix` to match name prefixes instead of exact match.

func (*Histogram) WriteTableASCII

func (hist *Histogram) WriteTableASCII(w io.Writer, header []string, sortBy string, inclTotal bool)

WriteTable writes an ASCII Table. For CLI apps, pass `os.Stdout` for `io.Writer`.

func (*Histogram) WriteXLSX

func (hist *Histogram) WriteXLSX(filename, sheetname, colNameBinName, colNameBinCount string) error

type HistogramAny added in v2.11.0

type HistogramAny interface {
	BinNames() []string
	ItemCount() uint
	ItemNames() []string
	Sum() int
}

type HistogramMapTableConfig added in v2.16.2

type HistogramMapTableConfig struct {
	TableName          string
	TableNamePrefix    string
	SplitKey           string
	SplitValFilterIncl []string // if present, only include these split values
	ColumnKeys         []string // doesn't include count column
	ColNameCount       string
	// contains filtered or unexported fields
}

func (*HistogramMapTableConfig) Inflate added in v2.16.2

func (cfg *HistogramMapTableConfig) Inflate()

func (*HistogramMapTableConfig) SplitValFilterInclExists added in v2.16.2

func (cfg *HistogramMapTableConfig) SplitValFilterInclExists(v string) bool

type HistogramMapTableSetConfig added in v2.16.2

type HistogramMapTableSetConfig struct {
	Configs []HistogramMapTableConfig
}

type HistogramSet

type HistogramSet struct {
	Name         string
	HistogramMap map[string]*Histogram
	KeyIsTime    bool
}

func NewHistogramSet

func NewHistogramSet(name string) *HistogramSet

func NewHistogramSetWithData

func NewHistogramSetWithData(name string, data map[string]map[string]int) *HistogramSet

func (*HistogramSet) Add

func (hset *HistogramSet) Add(histName, binName string, binCount int)

Add provides an easy method to add a histogram bin name and count for an existing or new histogram in the set.

func (*HistogramSet) AddDateUIDCount

func (hset *HistogramSet) AddDateUIDCount(dt time.Time, uid string, count int)

func (*HistogramSet) BinNameExists

func (hset *HistogramSet) BinNameExists(binName string) bool

BinNameExists returns a boolean indicating if a bin name exists in any histogram.

func (*HistogramSet) BinNames

func (hset *HistogramSet) BinNames() []string

BinNames returns all the bin names used across all the histograms.

func (*HistogramSet) BinParentCounts added in v2.16.0

func (hset *HistogramSet) BinParentCounts() map[uint]map[string]uint

BinSetCounts returns a ap where the key is the count of bins and the string is the set name.

func (*HistogramSet) DatetimeKeyCount

func (hset *HistogramSet) DatetimeKeyCount() (timeseries.TimeSeries, error)

DatetimeKeyCount returns a TimeSeries when the first key is a RFC3339 time and a sum of items is desired per time.

func (*HistogramSet) DatetimeKeyCountTable

func (hset *HistogramSet) DatetimeKeyCountTable(interval timeutil.Interval, countColName string) (table.Table, error)

func (*HistogramSet) DatetimeKeyToQuarter

func (hset *HistogramSet) DatetimeKeyToQuarter(name string) (*HistogramSet, error)

DatetimeKeyToQuarter converts a HistogramSet by date to one by quarters.

func (*HistogramSet) FilterHistogramNames added in v2.17.0

func (hset *HistogramSet) FilterHistogramNames(inFunc, exFunc func(histname string) bool) *HistogramSet

FilterHistogramNames returns a new `HistogramSet` with only the matching histogram names included.

func (*HistogramSet) HistogramBinNames

func (hset *HistogramSet) HistogramBinNames(setName string) []string

HistogramBinNames returns the bin names for a single histogram whose name is provided as a function parameter.

func (*HistogramSet) HistogramNameExists

func (hset *HistogramSet) HistogramNameExists(histName string) bool

HistogramNameExists returns a boolean indicating if the supplied histogram name exists.

func (*HistogramSet) HistogramSetTimeKeyCountWriteXLSX

func (hset *HistogramSet) HistogramSetTimeKeyCountWriteXLSX(filename string, interval timeutil.Interval, countColName string) error

func (*HistogramSet) ItemCount

func (hset *HistogramSet) ItemCount() uint

ItemCount returns the number of histograms.

func (*HistogramSet) ItemCounts

func (hset *HistogramSet) ItemCounts() *Histogram

ItemCounts returns the number of histograms.

func (*HistogramSet) ItemNames

func (hset *HistogramSet) ItemNames() []string

ItemNames returns the number of histograms.

func (*HistogramSet) LeafStats

func (hset *HistogramSet) LeafStats(name string) *Histogram

LeafStats returns a histogram by combining the histogram bins across histograms, removing the histogram distinction.

func (*HistogramSet) Map added in v2.16.0

func (hset *HistogramSet) Map() map[string]map[string]int

func (*HistogramSet) MapAdd added in v2.16.0

func (hset *HistogramSet) MapAdd(m map[string]map[string]int)

func (*HistogramSet) Sum added in v2.11.0

func (hset *HistogramSet) Sum() int

Sum returns the sum of all the histogram bin values.

func (*HistogramSet) Table added in v2.15.1

func (hset *HistogramSet) Table(colNameHist, colNameBin, colNameCount string) table.Table

func (*HistogramSet) TablePivot added in v2.17.0

func (hset *HistogramSet) TablePivot(tableName, histColName string, addColumnTotalLeft, addColumnTotalRight, addRowTotalTop, addRowTotalBottom bool) (*table.Table, error)

TablePivot returns a `*table.Table` where the first column is the histogram name and the other columns are the bin names. This is useful for easy visualization of a table and also creating charts such as grouped bar charts.

func (*HistogramSet) ToTimeSeriesDistinct

func (hset *HistogramSet) ToTimeSeriesDistinct() (timeseries.TimeSeries, error)

func (*HistogramSet) TransformBinNamesMap added in v2.17.0

func (hset *HistogramSet) TransformBinNamesMap(xfMap map[string]string) *HistogramSet

TransformBinNamesMap modifies bin names and returns a new `HistogramSet`.

func (*HistogramSet) TransformHistogramNamesMap

func (hset *HistogramSet) TransformHistogramNamesMap(xfMap map[string]string, matchType string) *HistogramSet

TransformHistogramNamesMap modifies bin names and returns a new `HistogramSet`. `matchType` can be set to `prefix` to match name prefixes instead of exact match.

func (*HistogramSet) TransformNames added in v2.17.0

func (hset *HistogramSet) TransformNames(xfFuncHist, xfFuncBin func(input string) string) *HistogramSet

func (*HistogramSet) WriteXLSX

func (hset *HistogramSet) WriteXLSX(filename, sheetName, colName1, colName2, colNameCount string) error

WriteXLSX creates an XLSX file where the first column is the histogram name, the second column is the bin name and the third column is the bin count.

func (*HistogramSet) WriteXLSXPivot added in v2.17.0

func (hset *HistogramSet) WriteXLSXPivot(filename, sheetName, histColName string, addColumnTotalLeft, addColumnTotalRight, addRowTotalTop, addRowTotalBottom bool) error

WriteXLSXPivot creates an XLSX file where the first column is the histogram name and the other columns are the bin names. This is useful for easy visualization of a table and also creating charts such as grouped bar charts.

type HistogramSetMetadata

type HistogramSetMetadata struct {
	Names          []string `json:"names,omitempty"`
	NameCount      int      `json:"nameCount,omitempty"`
	UniqueBinCount int      `json:"uniqueBinCount,omitempty"`
}

func NewHistogramSetMetadata

func NewHistogramSetMetadata(histSet *HistogramSet) *HistogramSetMetadata

type HistogramSets

type HistogramSets struct {
	Name            string
	HistogramSetMap map[string]*HistogramSet
}

func NewHistogramSets

func NewHistogramSets(name string) *HistogramSets

func NewHistogramSetsCSVs

func NewHistogramSetsCSVs(filenames []string, key1ColIdx, key2ColIdx, uidColIdx uint) (*HistogramSets, table.Table, error)

NewHistogramSetsCSVs expects multiple files to have same columns.

func NewHistogramSetsTable

func NewHistogramSetsTable(tbl table.Table, key1ColIdx, key2ColIdx, uidColIdx uint) (*HistogramSets, error)

func (*HistogramSets) Add

func (hsets *HistogramSets) Add(hsetName, histName, binName string, binCount int, trimSpace bool)

func (*HistogramSets) BinNames

func (hsets *HistogramSets) BinNames() []string

func (*HistogramSets) BinSumsByHset added in v2.10.0

func (hsets *HistogramSets) BinSumsByHset() *Histogram

func (*HistogramSets) Counts

func (hsets *HistogramSets) Counts() *HistogramSetsCounts

func (*HistogramSets) FilterHsetNames added in v2.17.0

func (hsets *HistogramSets) FilterHsetNames(inFunc, exFunc func(name string) bool) *HistogramSets

func (*HistogramSets) Flatten

func (hsets *HistogramSets) Flatten(name string) *HistogramSet

func (*HistogramSets) ItemCount

func (hsets *HistogramSets) ItemCount() uint

ItemCount returns the number of histogram sets.

func (*HistogramSets) ItemNames added in v2.12.0

func (hsets *HistogramSets) ItemNames() []string

func (*HistogramSets) Map added in v2.16.0

func (hsets *HistogramSets) Map() map[string]map[string]map[string]int

func (*HistogramSets) MapAdd added in v2.16.0

func (hsets *HistogramSets) MapAdd(m map[string]map[string]map[string]int, trimSpace bool)

func (*HistogramSets) Sum added in v2.11.0

func (hsets *HistogramSets) Sum() int

func (*HistogramSets) Table

func (hsets *HistogramSets) Table(tableName, colNameHSet, colNameHist, colNameBinName, colNameBinCount string) table.Table

func (*HistogramSets) TablePivot added in v2.17.0

func (hsets *HistogramSets) TablePivot(opts TablePivotOpts) table.Table

TablePivot returns a `*table.Table` where the first column is the histogram set name, the second column is the histogram name and the other columns are the bin names.

func (*HistogramSets) TransformBinNamesMap added in v2.17.0

func (hsets *HistogramSets) TransformBinNamesMap(xfBinNames map[string]string) *HistogramSets

func (*HistogramSets) TransformNames added in v2.17.0

func (hsets *HistogramSets) TransformNames(xfHsetName, xfFuncHistName, xfFuncBinName func(name string) string) *HistogramSets

func (*HistogramSets) Visit

func (hsets *HistogramSets) Visit(visit func(hsetName, histName, binName string, binCount int))

func (*HistogramSets) WriteXLSX

func (hsets *HistogramSets) WriteXLSX(filename, sheetname, colNameHSet, colNameHist, colNameBinName, colNameBinCount string) error

func (*HistogramSets) WriteXLSXPivot added in v2.17.0

func (hsets *HistogramSets) WriteXLSXPivot(filename string, opts TablePivotOpts) error

type HistogramSetsCounts

type HistogramSetsCounts struct {
	UIDCounts     map[string]map[string]uint
	UIDCountsKey1 map[string]uint
	UIDCountsKey2 map[string]uint
	Key1Names     []string
	Key2Names     []string
}

HistogramSetsCounts returns UID counts. When used with NewHistogramSetsCSV(), it can provide a sanity check for raw record counts against aggregate query values, e.g. compare counts of raw records to GROUP BY counts.

func NewHistogramSetsCounts

func NewHistogramSetsCounts(hsets HistogramSets) *HistogramSetsCounts

func (*HistogramSetsCounts) Inflate

func (hcounts *HistogramSetsCounts) Inflate()

type TablePivotOpts added in v2.18.1

type TablePivotOpts struct {
	TableName           string
	ColNameHistogramSet string
	ColNameHistogram    string
	ColNameBinPrefix    string
	ColNameBinSuffix    string
	ColNameBinCountsSum string
	BinNamesOrder       []string
	InclBinsUnordered   bool
	InclBinCounts       bool
	InclBinCountsSum    bool
	InclBinPercentages  bool
}

func (TablePivotOpts) ColNameBinCountsSumOrDefault added in v2.18.1

func (opts TablePivotOpts) ColNameBinCountsSumOrDefault() string

func (TablePivotOpts) ColNameHistogramOrDefault added in v2.18.1

func (opts TablePivotOpts) ColNameHistogramOrDefault() string

func (TablePivotOpts) ColNameHistogramSetOrDefault added in v2.18.1

func (opts TablePivotOpts) ColNameHistogramSetOrDefault() string

func (TablePivotOpts) InflateBinName added in v2.18.1

func (opts TablePivotOpts) InflateBinName(binName string, binNumber int, isPct bool) string

func (TablePivotOpts) TableColumns added in v2.18.1

func (opts TablePivotOpts) TableColumns(binNames []string) ([]string, map[int]string)

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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