Skip to content
This repository

streaming statistical calculations for node

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 bin
Octocat-spinner-32 test
Octocat-spinner-32 .travis.yml
Octocat-spinner-32 CHANGELOG.md
Octocat-spinner-32 LICENSE
Octocat-spinner-32 README.md
Octocat-spinner-32 index.js
Octocat-spinner-32 package.json
Octocat-spinner-32 screenshot.png
README.md

Build Status

stream-statistics

Install

npm install stream-statistics

API

This module exposes a single function that creates a stream. The stream reads data, which it parses with parseFloat(), and computes statistics on that data. When the input stream ends, stream-statistics emits the data object.

The statistics object has the following members:

  • min
  • max
  • sum
  • mean
  • mode
  • variance
  • standard_deviation
  • geometric_mean
  • harmonic_mean

mode computation expects the stream to deliver numbers in sorted lowest-first order, and will return undefined if that expectation is not met.

Use

var streamStatistics = require('stream-statistics'),
    assert = require('assert');

function rangeStream(a, b) {
    var rs = new Readable({ objectMode: true });
    for (var i = 10; i < 1000; i++) { rs.push(i); }
    rs.push(null);
    return rs;
}

rangeStream(10, 1000).pipe(streamStatistics())
    .on('data', function(d) {
        assert.equal(d.min, 10);
    });

cli

This also provides a binary, sstatistics, that you can get if you npm install -g the library. Pipe numbers into it and it'll return a basic set of stats about its input.

Documentation

See Also

  • The sister project, simple-statistics, that implements many of the same measures in straightforward and literate fashion
Something went wrong with that request. Please try again.