npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

stats-collector

v0.0.9

Published

collect stats about numbers

Downloads

43

Readme

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.