stats-collector

0.0.9 • Public • Published

stats-collector

NPM version Build Status Code Climate Coverage Status Dependency Status devDependency Status

NPM

Donate

Description

Collect stats about numbers. This library provides a few different default collectors, but allows you to add your own "stat collectors" by exposing an API that lets you pass in reducer-like functions that act on numbers passed to it.

stats-collector comes in 2 formats: a node.js library and a command line tool.

For examples and api documentation, continue reading below.

Node.js Library

Getting Started

Install the module with: npm install stats-collector

View Live Demo on Tonic

Usage (Method 1)

import * as lib from 'stats-collector';
const stats = new lib.NumberStats();
stats.processAll([1,2,3,4,5]);
console.log(stats.get());

Usage (Method 2)

import NumberStats from 'stats-collector/lib/NumberStats';
const stats = new StatsCollector();
stats.process(1);
stats.process(2);
stats.process(3);
stats.processAll([4, 5]);
console.log(stats.get());

Usage (Different types of collectors)

import * as lib from 'stats-collector';
const c1 = new lib.BaseStats();            // 0 default collectors
const c2 = new lib.BasicNumberStats();     // 5 default collectors
const c3 = new lib.NumberStats();          // 8 default collectors
const c4 = new lib.AdvancedNumberStats();  // 21 default collectors
const collectors = lib.collectors; // some collector functions
const filters = lib.filters; // some filter functions
console.log(c1.get(), c2.get(), c3.get(), c4.get(), collectors, filters);

Example Output

The following table shows you the results of initializing a stats collector, then running the following statments:

stats.processAll([1, 2, 3, 4, 5]);
const results = stats.get();
Collector Type Results
BaseStats {}
BasicNumberStats {
 "count": 5,
 "max": 5,
 "mean": 3,
 "min": 1,
 "sum": 15
}
NumberStats {
 "count": 5,
 "max": 5,
 "mean": 3,
 "min": 1,
 "powerSumAvgRunning": 11,
 "product": 120,
 "standardDeviationRunning": 1.5811388300841898,
 "sum": 15,
 "varianceRunning": 2.5
}
AdvancedNumberStats {
 "amean": 3,
 "count": 5,
 "count_even": 2,
 "count_float": 0,
 "count_integer": 5,
 "count_negative": 0,
 "count_nonZero": 5,
 "count_odd": 3,
 "count_positive": 5,
 "count_prime": 3,
 "count_zero": 0,
 "gmean": 2.605171084697352,
 "hmean": 2.18978102189781,
 "max": 5,
 "mean": 3,
 "median": 3,
 "midRange": 3,
 "min": 1,
 "powerSumAvgRunning": 11,
 "product": 120,
 "range": 4,
 "standardDeviationRunning": 1.5811388300841898,
 "standardDeviationStable": 1.5811388300841898,
 "sum": 15,
 "sumOfRecipricals": 2.283333333333333,
 "sumOfSquaredDeviationsStable": 10,
 "varianceRunning": 2.5,
 "varianceStable": 2.5
}

API Documentation

Read the API Docs by visiting the project site here:

Command Line Tool

Installation

The command line utility can be install via npm install -g stats-collector.

After doing so, you will have access to stats-collector from the command line.

$ stats-collector -h
 
  Usage: stats-collector [options] <values>
 
  Options:
 
    -h, --help                     output usage information
    -v, --version                  output the version number
    -c, --collectors [collectors]  add collectors
    -f, --filters [filters]        add filters
    -t, --type [type]              type of stats [empty,basic,stats,advanced]
    -p, --pipe                     whether or not to accept piped data from stdin

Examples

Default behavior

Here is the default behavior when passing in 5 numbers.

$ stats-collector 1,2,3,4,5
{
  "count": 5,
  "max": 5,
  "mean": 3,
  "min": 1,
  "powerSumAvgRunning": 11,
  "product": 120,
  "standardDeviationRunning": 1.5811388300841898,
  "sum": 15,
  "varianceRunning": 2.5
}

Get "advanced" stats about 10 random numbers

The example uses the --pipe functionality:

for i in {1..10}; do echo $RANDOM; done | stats-collector -t advanced --pipe
{
  "amean": 15239.3,
  "count": 10,
  "count_even": 7,
  "count_float": 0,
  "count_integer": 10,
  "count_negative": 0,
  "count_nonZero": 10,
  "count_odd": 3,
  "count_positive": 10,
  "count_prime": 1,
  "count_zero": 0,
  "gmean": 9896.019927976335,
  "hmean": 5947.676087129243,
  "max": 30937,
  "mean": 15239.3,
  "median": 26478,
  "midRange": 16430.5,
  "min": 1924,
  "powerSumAvgRunning": 360452286.7,
  "product": 9.007527812504433e+39,
  "range": 29013,
  "standardDeviationRunning": 11935.754978215662,
  "standardDeviationStable": 11935.754978215662,
  "sum": 152393,
  "sumOfRecipricals": 0.0016813289515950568,
  "sumOfSquaredDeviationsStable": 1282160222.1,
  "varianceRunning": 142462246.89999998,
  "varianceStable": 142462246.89999998
}

See Also

License

Copyright (c) 2015 skratchdot
Licensed under the MIT license.

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.0.96latest

Version History

VersionDownloads (Last 7 Days)Published
0.0.96
0.0.80
0.0.70
0.0.60
0.0.50
0.0.40
0.0.30
0.0.20
0.0.10

Package Sidebar

Install

npm i stats-collector

Weekly Downloads

6

Version

0.0.9

License

MIT

Last publish

Collaborators

  • skratchdot