@mapbox/speed-percentile

Utility to compute speed percentile from sparse histogram hash.

Usage no npm install needed!

<script type="module">
  import mapboxSpeedPercentile from 'https://cdn.skypack.dev/@mapbox/speed-percentile';
</script>

README

speed-percentile

Build Status

A JavaScript utility to compute percentile speed from speed histogram.

Install

npm install @mapbox/speed-percentile

Test

cd to speed-percentile folder then run

npm test

Use

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:

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