2.0.1 • Published 8 years ago
@mapbox/speed-percentile v2.0.1
speed-percentile
A JavaScript utility to compute percentile speed from speed histogram.
Install
npm install @mapbox/speed-percentileTest
cd to speed-percentile folder then run
npm testUse
v1.x
var o1 = percentile(P1, P2, P3)
Computes the p-th precentile speed from a sparse hash speed histogram.
Inputs:
| param | data type | description | 
|---|---|---|
P1 | associative array with integer keys | speed histogram hash {<speed>:<count>} | 
P2 | number or array | one or more percentiles in decimal | 
P3 | string | algorithm flag (optional): 'R4', 'R5' (default) | 
Algorithms:
R4– R's sample quantile Type 4, but with linearly interpolated lower tailR5– R's sample quantile Type 5, but with both tails linearly interpolated
Outputs:
| output | data type | description | 
|---|---|---|
o1 | number or array | corresponding speed(s) sorted in descending order | 
v2.x
v2.x only has R5 algorithm.
var PercentileInterpolator = require('@mapbox/speed-percentile');
var hist = {10: 2, 30: 3, 40: 4};
var pi = new PercentileInterpolator(hist);  
// find speed from percentile
var speed = pi.getSpeed(0.7);
var speeds = pi.getSpeed([0.1, 0.7]);  // irrespective of input order, output is always in descending order
// find percentile from speed
var p = pi.getPercentile(30);
var ps = pi.getPercentile([20, 30]);   // irrespective of input order, output is always in descending order