time-series-buffer

1.1.0 • Public • Published

Time Series Buffer

Simple library that takes into account data points and calculates minimums, maximums and averages.

The buffer is limited in age. Expired entries are removed.

Example

const TimeSeriesBuffer = require('time-series-buffer')
 
// entries older than 1 second will be ignored
const timeSeriesBuffer = new TimeSeriesBuffer(1000)
 
timeSeriesBuffer.enqueue({ x: 1 })
timeSeriesBuffer.enqueue({ x: 2, y: 10 })
timeSeriesBuffer.enqueue({ x: 3, y: 20 })
 
timeSeriesBuffer.average('x') // 2
timeSeriesBuffer.minimum('x') // 1
timeSeriesBuffer.maximum('y') // 20
timeSeriesBuffer.maximum('z') // undefined
timeSeriesBuffer.sum('x') // 6
timeSeriesBuffer.last('y') // 20
 
 
// wait 2 seconds for the data points to expire
setTimeout(() => {
    timeSeriesBuffer.average('x') // undefined
}, 2000)

Package Sidebar

Install

npm i time-series-buffer

Weekly Downloads

0

Version

1.1.0

License

ISC

Unpacked Size

6.21 kB

Total Files

5

Last publish

Collaborators

  • adaxi