histogram

package
v0.1.13 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2021 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Cmd = &cobra.Command{
	Use:   "histogram",
	Short: "summarize data with a histogram",
	Long: `Summarize data with a histogram.

NOTE: This will read all data into memory. Histograms for large sets of data
can be approximated with the t-digest sub-command.

https://en.wikipedia.org/wiki/Histogram`,
	RunE: func(command *cobra.Command, args []string) (err error) {
		vs := []float64{}
		scanner := bufio.NewScanner(os.Stdin)

		var v float64
		for scanner.Scan() {
			v, err = strconv.ParseFloat(scanner.Text(), 64)
			if err != nil {
				return
			}

			vs = append(vs, v)
		}
		err = scanner.Err()
		if err != nil {
			return
		}

		if len(vs) == 0 {
			return errors.New("No input values found.")
		}

		sort.Float64s(vs)
		dividers := Fence(vs)
		hist := stat.Histogram(nil, dividers, vs, nil)

		for i := 0; i < len(hist); i++ {
			fmt.Printf("%g %g\n", dividers[i], hist[i])
		}

		return
	},
}
View Source
var (
	N int = 10
)

Functions

func Fence

func Fence(vs []float64) []float64

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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