Socket
Socket
Sign inDemoInstall

streaming-percentiles

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

streaming-percentiles

Implementations of various streaming percentile algorithms


Version published
Weekly downloads
444
increased by0.45%
Maintainers
1
Weekly downloads
 
Created
Source

Streaming Percentiles

This is a reusable JavaScript library with implementations of various percentile algorithms on streams of data. These algorithms all calculate only approximate percentiles, not exact percentiles.

For more on streaming percentiles, see Calculating Percentiles on Streaming Data.

Installing

If you use NPM, npm install streaming-percentiles. Otherwise, download the latest release binaries or the latest release source code. You can also load directly from unpkg.com.

For convenience, you can also use the latest release binaries directly from a web browser:

<script src="//sengelha.github.io/streaming-percentiles-js/streamingPercentiles.v1.min.js"></script>
<script>
var gk = new streamingPercentiles.GK(0.1);
...
</script>

Example

Here's a simple example on how to use the Greenwald-Khanna streaming percentile algorithm:

var sp = require('streaming-percentiles');

// epsilon is allowable error.  As epsilon becomes smaller, the
// accuracy of the approximations improves, but the class consumes
// more memory.
var epsilon = 0.1;
var gk = new sp.GK(epsilon);
for (var i = 0; i < 1000; ++i)
    gk.insert(Math.random());
var p50 = gk.quantile(0.5); // Approx. median
var p95 = gk.quantile(0.95); // Approx. 95th percentile

API Reference

class GK(epsilon)

Construct an object which implements the Greenwald-Khanna streaming percentile algorithm with allowable error epsilon.

Example:

var sp = require('streaming-percentiles');
var gk = new sp.GK(0.1);

gk.insert(value)

Logs the observation of a value.

Example:

gk.insert(Math.random());

gk.quantile(phi)

Compute the approximate quantile at phi. For example, the 95th percentile corresponds to phi = 0.95.

Example:

var p50 = gk.quantile(0.5);

License

This project is licensed under the MIT License.

Keywords

FAQs

Package last updated on 08 Mar 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc