Group By Time (Javascript/NODEJS)
I have been trying to find a way to group data together according to time without expensive algorithms and after a very long search decided to do it. The Problem addressed is that a set of data with a unix time stamp on each record is to be grouped by years, months, days, hours, minutes or seconds.
The main use of this was to be able to group times together after filtering from certian Databases and also keep the latency low. To be able to do so, data is set into an array and is processed really fast using only mathmatical operations and methods to generate timestamp hashes. You can take a look at the code and understand it more as an algorithm.
Usage
First install the module using npm
$ npm install groupbytime
Next you will need to require the module
var gb = ;
Finally you will need to use the function groupBy(dataArray, startingDateUnixTimeStamp, endDateUnixTimeStamp, groupByTime)
- dataArray; should always contain a ts field with the records Unix Time Stamp
- startingDateUnixTimeStamp; should be the start of the timestamp sequence where the data with be grouped by into it
- endDateUnixTimeStamp; should be the when this set of data ends in unix time stamp format
- groupByTime; is by how much time do you want to group by in seconds, example group By 3 Minutes (360) or group by 1.5 days (1.5246060)
Note: That the group by will generate a list of all times within the timeframe and will have data in it, if there is no data for a certain time then it will be empty.
var groupby = ;//TS field added to all records, start and time date added, and asked to group by 5 minutes. console;