histogram

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: 18 Imported by: 1

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
	BinCount    uint
	Sum         int
}

Histogram stats is used to count how many times an item appears and how many times number of appearances appear.

func NewHistogram

func NewHistogram(name string) *Histogram

func ParseFileCSV added in v1.4.0

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 added in v1.4.0

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) BinNameExists added in v1.5.0

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

func (*Histogram) BinNames added in v1.5.0

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

func (*Histogram) Inflate

func (hist *Histogram) Inflate()

func (*Histogram) ItemCounts added in v1.5.0

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

ItemCounts returns sorted item names and values.

func (*Histogram) Stats added in v1.5.0

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

func (*Histogram) Table added in v1.11.0

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

func (*Histogram) TransformBinNames added in v1.5.0

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

TransformBinNames modifies bin names and returns a new histogram.

func (*Histogram) TransformBinNamesMap added in v1.9.0

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) ValueSum added in v1.6.4

func (hist *Histogram) ValueSum() int

func (*Histogram) WriteTableASCII added in v1.5.0

func (hist *Histogram) WriteTableASCII(writer 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 added in v1.5.0

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

type HistogramSet

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

func NewHistogramSet

func NewHistogramSet(name string) *HistogramSet

func NewHistogramSetWithData added in v1.5.0

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 added in v1.18.0

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

func (*HistogramSet) BinNameExists added in v1.5.0

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

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

func (*HistogramSet) BinNames added in v1.8.0

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

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

func (*HistogramSet) DatetimeKeyCount added in v1.7.2

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 added in v1.7.2

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

func (*HistogramSet) DatetimeKeyToQuarter added in v1.7.2

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

DatetimeKeyToQuarter converts a HistogramSet by date to one by quarters.

func (*HistogramSet) HistogramBinNames added in v1.5.0

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 added in v1.5.0

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

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

func (*HistogramSet) HistogramNames added in v1.5.0

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

HistogramNames returns the number of histograms.

func (*HistogramSet) HistogramSetTimeKeyCountWriteXLSX added in v1.7.2

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

func (*HistogramSet) ItemCount added in v1.5.0

func (hset *HistogramSet) ItemCount() uint

ItemCount returns the number of histograms.

func (*HistogramSet) ItemCounts added in v1.5.0

func (hset *HistogramSet) ItemCounts() *Histogram

ItemCounts returns the number of histograms.

func (*HistogramSet) ItemNames added in v1.5.0

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

ItemNames returns the number of histograms. Alias for `HistogramNames()`.

func (*HistogramSet) LeafStats added in v1.5.0

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

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

func (*HistogramSet) TableMatrix added in v1.8.0

func (hset *HistogramSet) TableMatrix(tableName, histColName string) (*table.Table, error)

TableMatrix 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 added in v1.7.0

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

func (*HistogramSet) TransformHistogramNames added in v1.5.0

func (hset *HistogramSet) TransformHistogramNames(xfFunc func(input string) string) *HistogramSet

TransformHistogramNames modifies histogram names and returns a new histogram set.

func (*HistogramSet) TransformHistogramNamesMap added in v1.9.0

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) ValueSum added in v1.6.4

func (hset *HistogramSet) ValueSum() int

ValueSum returns the sum of all the histogram bin values.

func (*HistogramSet) WriteXLSX added in v1.5.0

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) WriteXLSXMatrix added in v1.8.0

func (hset *HistogramSet) WriteXLSXMatrix(filename, sheetName, histColName string) error

WriteXLSXMatrix 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 added in v1.5.0

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

func NewHistogramSets added in v1.5.0

func NewHistogramSets(name string) *HistogramSets

func NewHistogramSetsCSVs added in v1.5.0

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

NewHistogramSetsCSVs expects multiple files to have same columns.

func NewHistogramSetsTable added in v1.5.0

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

func (*HistogramSets) Add added in v1.5.0

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

func (*HistogramSets) BinNames added in v1.11.0

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

func (*HistogramSets) Counts added in v1.5.0

func (hsets *HistogramSets) Counts() *HistogramSetsCounts

func (*HistogramSets) Flatten added in v1.5.0

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

func (*HistogramSets) ItemCount added in v1.5.0

func (hsets *HistogramSets) ItemCount() uint

ItemCount returns the number of histogram sets.

func (*HistogramSets) Table added in v1.11.0

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

func (*HistogramSets) TableMatrix added in v1.11.0

func (hsets *HistogramSets) TableMatrix(tableName, colNameHSet, colNameHist, colNameBinNamePrefix, colNameBinNameSuffix string) table.Table

TableMatrix 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) Visit added in v1.12.0

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

func (*HistogramSets) WriteXLSX added in v1.11.0

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

func (*HistogramSets) WriteXLSXMatrix added in v1.11.0

func (hsets *HistogramSets) WriteXLSXMatrix(filename, sheetname, colNameHSet, colNameHist, colNameBinNamePrefix, colNameBinNameSuffix string) error

type HistogramSetsCounts added in v1.5.0

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 added in v1.5.0

func NewHistogramSetsCounts(hsets HistogramSets) *HistogramSetsCounts

func (*HistogramSetsCounts) Inflate added in v1.5.0

func (hcounts *HistogramSetsCounts) Inflate()

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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