timewindow
collect all records that fill within the time window
Installation
Install module via NPM:
npm install timewindow
Usage
You can just push data with specific format into it then waiting for events for output.
var tw = ; // create time window with time span which is 3 secondsvar timeWindow = tw; timeWindow; timeWindow; // push 10 records into streamtimeWindow;timeWindow;timeWindow;timeWindow;timeWindow;timeWindow;timeWindow;timeWindow;timeWindow;timeWindow;thmeWindow;
results:
[ { ts: 0, v: 1 } ]
[ { ts: 0, v: 1 }, { ts: 1, v: 2 } ]
[ { ts: 0, v: 1 }, { ts: 1, v: 2 }, { ts: 2, v: 3 } ]
[ { ts: 1, v: 2 }, { ts: 2, v: 3 }, { ts: 3, v: 4 } ]
[ { ts: 2, v: 3 }, { ts: 3, v: 4 }, { ts: 4, v: 5 } ]
[ { ts: 3, v: 4 }, { ts: 4, v: 5 }, { ts: 5, v: 6 } ]
[ { ts: 4, v: 5 }, { ts: 5, v: 6 }, { ts: 6, v: 7 } ]
[ { ts: 5, v: 6 }, { ts: 6, v: 7 }, { ts: 7, v: 8 } ]
[ { ts: 6, v: 7 }, { ts: 7, v: 8 }, { ts: 8, v: 9 } ]
[ { ts: 7, v: 8 }, { ts: 8, v: 9 }, { ts: 9, v: 10 } ]
[ { ts: 8, v: 9 }, { ts: 9, v: 10 } ]
[ { ts: 9, v: 10 } ]
Completed
Stream Support
TimeWindow is designed to be a object-mode transform stream.
var tw = ; // create time window with time span which is 3 secondsvar timeWindow = tw; inputStream;
License
Licensed under the MIT License
Authors
Copyright(c) 2017 Fred Chien <cfsghost@gmail.com>