A data set of time series data needs to be turned from one with irregular time intervals to a regular time series, probably using interpolation and and resampling.
Python's pandas.Dataframe.resample
is a function that will do this. Can Javascript do the same? The time series data set is stored in Mongodb.
It is kind of possible. Keep in mind that Pandas is a library built explicitly for those kind of tasks, and a beast at it, while MongoDB is meant to be a database. But chances are high that the following will suit your needs, if one ignores your probable need for using interpolation:
Assuming that you have the following data stored in a MongoDB collection named
devices
which, in this case, is sampled at around every 15 seconds, but it could as well be irregularly. If you want to resample it to a 5 minute boundary for a certain day, then you should do the following:
This will result in something like this
If you want to discard the total incoming, then just leave the line out in the $project stage. The incoming_average is just an example of how to compute the average, in case your stored data is something like what rrdtool names a gauge (temperature, cpu, sensor data). If you're only after the sum aggregated in that time inverval, that is the incoming and outgoing field, then you can leave the entire $project stage out. It is only there to compute the average of the time interval.
See Mongo aggregation of ISODate into 45 minute chunks