summary-collector
Easy summary collector. It collects numbers to named arrays and then computes summary for every array using smry.
Install
npm i summary-collector
Usage
const collect summary = options;
functions:
collect
- saves numbers to named arrays. There is two forms:
// 1. using object // 2. using name and numbers //add single number //add many numbers as separate params //add many numbers as array //add many numbers mixed way // if value is not number - it'll be ignored //nothing happends
summary
- returns object with field for every named array created by collect
. Each field contains summary for array, computed by smry.
;console;/*{ a: { min: 1, max: 5, sum: 15, len: 5, avg: 3, },}*/
options:
store
- initial store (as object with named arrays of numbers).
counters
- array of store keys, for wich only sum
will computed (and stored/returned as number).
quantile
- option for smry. Same syntax.
memory usage tip:
If quantile
option is not set - summaries are computing incrementally without storing full arrays in memory. So, if you expect really big arrays, and if you need quantiles only for certain arrays (not for all), it is good idea to use separate pairs of functions. Something like this:
const collect summary = ; //save memoryconst collectQ summaryQ = quantile: 095;
License
MIT