stat

package module
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2025 License: MIT Imports: 10 Imported by: 0

README

Stat

Go Reference Go Report Card Coverage Status

Purpose

Library that provides to collect and display the quantity of occurrences of values ​​in given spans

Usage

Example:

package main

import (
    "fmt"
    "os"

    "github.com/akramarenkov/stat"
)

func main() {
    sts, err := stat.NewLinear(1, 100, 20)
    if err != nil {
        panic(err)
    }

    sts.Inc(0)

    sts.Inc(1)
    sts.Inc(20)

    sts.Inc(21)
    sts.Inc(22)
    sts.Inc(40)

    sts.Inc(41)
    sts.Inc(42)
    sts.Inc(59)
    sts.Inc(60)

    sts.Inc(61)
    sts.Inc(62)
    sts.Inc(80)

    sts.Inc(81)
    sts.Inc(100)

    sts.Inc(101)

    fmt.Println(sts.Graph(os.Stderr))
    // Output:
    // <nil>
}

Documentation

Overview

Library that provides to collect and display the quantity of occurrences of values ​​in given spans.

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	ErrItemsQuantityNegative = errors.New("items quantity is negative")
	ErrItemsQuantityZero     = errors.New("items quantity is zero")
	ErrLowerGreaterUpper     = errors.New("lower value is greater than upper")
	ErrSpansListEmpty        = errors.New("an empty list of spans was specified")
	ErrSpansSequenceUnsorted = errors.New("spans sequence is not sorted")
)

Functions

This section is empty.

Types

type Item

type Item[Type constraints.Integer] struct {
	// Kind (purpose) of item
	Kind ItemKind

	// Quantity of occurrences of a value belonging to a Span
	Quantity uint64

	// Span of values ​​for which the Quantity of occurrences is collected
	Span span.Span[Type]
}

Item of statistics.

type ItemKind added in v0.3.0

type ItemKind int

Kind (purpose) of item.

const (
	ItemKindRegular ItemKind = iota + 1
	ItemKindNegInf
	ItemKindPosInf
	ItemKindMissed
)

func (ItemKind) String added in v0.3.0

func (ik ItemKind) String() string

type Predictor added in v0.1.0

type Predictor[Type constraints.Integer] func(value Type) uint64

A function used to determine (at least approximately) the index of a span in a list of spans to which a value belongs.

type Stat

type Stat[Type constraints.Integer] struct {
	// contains filtered or unexported fields
}

Statistics.

Example
package main

import (
	"fmt"
	"os"

	"github.com/akramarenkov/stat"
)

func main() {
	sts, err := stat.NewLinear(1, 100, 20)
	if err != nil {
		panic(err)
	}

	sts.Inc(0)

	sts.Inc(1)
	sts.Inc(20)

	sts.Inc(21)
	sts.Inc(22)
	sts.Inc(40)

	sts.Inc(41)
	sts.Inc(42)
	sts.Inc(59)
	sts.Inc(60)

	sts.Inc(61)
	sts.Inc(62)
	sts.Inc(80)

	sts.Inc(81)
	sts.Inc(100)

	sts.Inc(101)

	fmt.Println(sts.Graph(os.Stderr))
}
Output:

<nil>

func New

func New[Type constraints.Integer](spans []span.Span[Type], predictor Predictor[Type]) (*Stat[Type], error)

Creates an instance of statistics for the specified spans of values.

Spans sequence must be increasing and sorted. Spans must not intersect.

Prediction function may not be specified, but then the value's correspondence to the span will be determined by searching the list of spans, which is slower.

func NewLinear

func NewLinear[Type constraints.Integer](lower, upper, width Type) (*Stat[Type], error)

Creates a linear statistics whose items have the specified width.

func NewLinearQ added in v0.2.0

func NewLinearQ[Type constraints.Integer](lower, upper, quantity Type) (*Stat[Type], error)

Creates a linear statistics with the specified quantity of items.

func (*Stat[Type]) Graph

func (st *Stat[Type]) Graph(writers ...io.Writer) error

Writes statistics as a bar chart to the specified writers.

If no writer is specified, the bar chart will be written to standard output.

func (*Stat[Type]) Inc

func (st *Stat[Type]) Inc(value Type)

Increases the quantity of occurrences of the specified value.

func (*Stat[Type]) Items

func (st *Stat[Type]) Items() []Item[Type]

Returns a list of statistics items.

Jump to

Keyboard shortcuts

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