streaming-percentiles
Advanced tools
Comparing version 1.0.0 to 2.1.0
{ | ||
"name": "streaming-percentiles", | ||
"version": "1.0.0", | ||
"version": "2.1.0", | ||
"description": "Implementations of various streaming percentile algorithms", | ||
@@ -15,24 +15,19 @@ "keywords": [ | ||
"license": "MIT", | ||
"main": "build/streamingPercentiles.v1.js", | ||
"main": "streamingPercentiles.v1.js", | ||
"module": "index", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/sengelha/streaming-percentiles-js.git" | ||
"url": "git+https://github.com/sengelha/streaming-percentiles-cpp.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/sengelha/streaming-percentiles-js/issues" | ||
"url": "https://github.com/sengelha/streaming-percentiles-cpp/issues" | ||
}, | ||
"scripts": { | ||
"pretest": "rm -rf build && mkdir build && rollup --banner \"$(preamble)\" -f umd -n streamingPercentiles -o build/streamingPercentiles.v1.js -- index.js", | ||
"test": "tape 'test/**/*-test.js' && eslint index.js src", | ||
"prepare": "npm run test && uglifyjs -b beautify=false,preamble=\"'$(preamble)'\" build/streamingPercentiles.v1.js -c -m -o build/streamingPercentiles.v1.min.js", | ||
"postpublish": "git push && git push --tags && zip -j build/streamingPercentiles.v1.zip -- LICENSE README.md build/streamingPercentiles.v1.js build/streamingPercentiles.v1.min.js && echo \"Don't forget to publish to sengelha.github.io\"" | ||
"test": "exit 0", | ||
"prepare": "npm run test", | ||
"postpublish": "echo \"Don't forget to push, push tags, and publish to sengelha.github.io\"" | ||
}, | ||
"devDependencies": { | ||
"eslint": "4", | ||
"package-preamble": "0.1.0", | ||
"rollup": "0.43", | ||
"tape": "4", | ||
"uglify-es": "3" | ||
"package-preamble": "0.1.0" | ||
} | ||
} |
113
README.md
@@ -1,6 +0,8 @@ | ||
# Streaming Percentiles | ||
# streaming-percentiles-cpp | ||
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. | ||
This is a C++ library with implementations of various | ||
percentile algorithms on streams of data. Using the | ||
magic of [emscripten](https://github.com/kripken/emscripten), | ||
this package also cross-compiles a JavaScript version of | ||
the streaming percentiles library as well. | ||
@@ -10,77 +12,68 @@ For more on streaming percentiles, see [Calculating Percentiles on | ||
## Installing | ||
## Obtaining the Library | ||
If you use NPM, `npm install streaming-percentiles`. Otherwise, | ||
download the [latest release | ||
binaries](https://sengelha.github.io/streaming-percentiles-js/streamingPercentiles.v1.zip) | ||
or the [latest release source | ||
code](https://github.com/sengelha/streaming-percentiles-js/releases/latest). | ||
You can also load directly from | ||
[unpkg.com](https://unpkg.com/streaming-percentiles/). | ||
You can download pre-built versions of the library from the | ||
[streaming-percentiles-cpp releases | ||
page](https://github.com/sengelha/streaming-percentiles-cpp/releases). | ||
Otherwise see [CONTRIBUTING.md](CONTRIBUTING.md) for instructions on how | ||
to compile the library from source. | ||
For convenience, you can also use the [latest release | ||
binaries](https://sengelha.github.io/streaming-percentiles-js/streamingPercentiles.v1.zip) | ||
directly from a web browser: | ||
## Usage Example | ||
```html | ||
<script src="//sengelha.github.io/streaming-percentiles-js/streamingPercentiles.v1.min.js"></script> | ||
<script> | ||
var gk = new streamingPercentiles.GK(0.1); | ||
... | ||
</script> | ||
``` | ||
### C++ | ||
## Example | ||
Here's a simple example on how to use the Greenwald-Khanna streaming | ||
percentile algorithm: | ||
percentile algorithm from C++: | ||
```javascript | ||
var sp = require('streaming-percentiles'); | ||
```cpp | ||
#include <stmpct/gk.hpp> | ||
// 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 | ||
using namespace stmpct; | ||
double epsilon = 0.1; | ||
gk g(epsilon); | ||
for (int i = 0; i < 1000; ++i) | ||
g.insert(rand()); | ||
double p50 = g.quantile(0.5); // Approx. median | ||
double p95 = g.quantile(0.95); // Approx. 95th percentile | ||
``` | ||
## API Reference | ||
### JavaScript | ||
### class GK(*epsilon*) | ||
#### Node.JS | ||
Construct an object which implements the Greenwald-Khanna streaming | ||
percentile algorithm with allowable error *epsilon*. | ||
Here's how to use the library from Node.JS: | ||
```javascript | ||
var sp = require('./streamingPercentiles.v1.min.js'); | ||
Example: | ||
```javascript | ||
var sp = require('streaming-percentiles'); | ||
var gk = new sp.GK(0.1); | ||
var epsilon = 0.1; | ||
var g = new sp.GK(epsilon); | ||
for (var i = 0; i < 1000; ++i) | ||
g.insert(Math.random()); | ||
var p50 = g.quantile(0.5); // Approx. median | ||
var p95 = g.quantile(0.95); // Approx. 95th percentile | ||
``` | ||
### *gk*.insert(*value*) | ||
#### Browser | ||
Logs the observation of a value. | ||
Example: | ||
```javascript | ||
gk.insert(Math.random()); | ||
Here's how to use the library from a browser. Note that the | ||
default module name is streamingPercentiles: | ||
```html | ||
<script src="streamingPercentiles.v1.min.js"></script> | ||
<script> | ||
var epsilon = 0.1; | ||
var gk = new streamingPercentiles.GK(epsilon); | ||
for (var i = 0; i < 1000; ++i) | ||
g.insert(Math.random()); | ||
var p50 = g.quantile(0.5); | ||
</script> | ||
``` | ||
### *gk*.quantile(*phi*) | ||
## API Reference | ||
Compute the approximate quantile at *phi*. For example, the 95th | ||
percentile corresponds to *phi* = 0.95. | ||
Coming soon! | ||
Example: | ||
```javascript | ||
var p50 = gk.quantile(0.5); | ||
``` | ||
## Contributing | ||
## License | ||
This project is licensed under the MIT License. | ||
If you are interested in contributing to the library, please see | ||
[CONTRIBUTING.md](CONTRIBUTING.md). |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
820637
1
24911
1
5
79
2
3