项目作者: simple-statistics

项目描述 :
streaming statistical calculations for node
高级语言: JavaScript
项目地址: git://github.com/simple-statistics/stream-statistics.git
创建时间: 2012-06-27T16:43:40Z
项目社区:https://github.com/simple-statistics/stream-statistics

开源协议:BSD 3-Clause "New" or "Revised" License

下载


Build Status

stream-statistics

Install

  1. 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

  1. var streamStatistics = require('stream-statistics'),
  2. assert = require('assert');
  3. function rangeStream(a, b) {
  4. var rs = new Readable({ objectMode: true });
  5. for (var i = 10; i < 1000; i++) { rs.push(i); }
  6. rs.push(null);
  7. return rs;
  8. }
  9. rangeStream(10, 1000).pipe(streamStatistics())
  10. .on('data', function(d) {
  11. assert.equal(d.min, 10);
  12. });

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
  • streaming-k-means implements k-means clustering in an online fashion