A small utility for storing and working with a fixed-length history of (ususally numeric) values.
A simple fixed-size array/history for node.js with some light statistical methods. Intended for use with numeric values, e.g. what were the response times for the last 100 requests processed, and what were their min, max, and mean.
var FixedArray = require"fixed-array";var request_log = FixedArray100;// ... in your http server after processing your requests:request_logpushrequest_time;// ... later, when you're interested in looking at stats:var min = request_logmin;var max = request_logmax;var mean = request_logmean;
Another example use it to easily track the min and max values of a series:
var ts_range = FixedArray2;var db_results = ;for var i = 0; i < db_resultslength; i++// do something with the results...ts_rangepushdb_resultsitimestamp;some_functionts_rangemin ts_rangemax;
var min max;var db_results = ;for var i = 0; i < db_resultslength; i++// do something with the results...if isNaNmin || db_resultsitimestamp < minif !isNaNdb_resultsitimestampmin = db_resultsitimestamp;if isNaNmax || db_resultsitimestamp > maxif !isNaNdb_resultsitimestampmax = db_resultsitimestamp;some_functionmin max;
Create a new fixed-length value history of length
length with optional
Push the specified value(s) onto the fixed array, removing any older values (in order) required to maintain the fixed-length.
Return the smallest value in the current data. If any NaN entries are present, returns NaN.
Return the largest value in the current data. If any NaN entries are present, returns NaN.
Calculate and return the mean of the current data. Any non-numeric items will be considered NULL during sum, affecting the mean.
Calculate and return the variance of the current data. Any non-numeric items will be considered NULL during sum, affecting the variance.
Return the current length of the dataset.
Return the sum of the current data. Any non-numeric items will be skipped in the sum.
Returns a copy of the values currently stored.