Time aware rolling mean storage for Node.js
JavaScript
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
examples
test
.gitignore
.travis.yml
README.md
package.json
time-buffer.js

README.md

time-buffer Build Status

Storing per-second granularity data in a standard circular buffer leaves old values in place if there is nothing collected. This can lead to the illusion of newly arrived data when in fact there has simply been nothing to overwrite the buffer. The possible solutions are a 'reaper' thread/interval that clears out old buffers or a queue of values from which old values are removed. This library takes the latter approach through it may eventually support both. Here is an example:

var TimeBuffer = require('time-buffer');

// Create 3 buffers of different durations
var bufferFiveSec = new TimeBuffer(5);
var bufferOneMin = new TimeBuffer(60);
var bufferTwoMin = new TimeBuffer(120);

var interval = setInterval(function() {
	var rand = Math.floor(Math.random() * 10);
	bufferFiveSec.add(rand);
	bufferOneMin.add(rand);
	bufferTwoMin.add(rand);
	console.log(bufferFiveSec);
	console.log(bufferOneMin);
	console.log(bufferTwoMin);
}, 2000); // Even at 2 seconds this works because time-buffer handles the gaps correctly.