1.1.0 • Published 6 years ago

time-series-buffer v1.1.0

Weekly downloads
1
License
ISC
Repository
-
Last release
6 years ago

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)