I have query (for a MongoDB database) which returns objects which have been mapreduced, the objects are reported every 15 minutes, but the issue is that if say we have a critical error in one of servers that period of time will be unaccounted for.
Take this array as an example:
[
{:timestamp=>2011-09-26 19:00:00 UTC, :count=>318},
{:timestamp=>2011-09-26 19:15:00 UTC, :count=>308},
{:timestamp=>2011-09-26 19:30:00 UTC, :count=>222},
{:timestamp=>2011-09-26 19:45:00 UTC, :count=>215},
{:timestamp=>2011-09-26 20:00:00 UTC, :count=>166},
{:timestamp=>2011-09-26 21:15:00 UTC, :count=>149},
{:timestamp=>2011-09-26 21:30:00 UTC, :count=>145},
{:timestamp=>2011-09-26 21:45:00 UTC, :count=>107},
{:timestamp=>2011-09-26 22:00:00 UTC, :count=>137},
{:timestamp=>2011-09-26 22:15:00 UTC, :count=>135},
{:timestamp=>2011-09-26 22:30:00 UTC, :count=>191},
{:timestamp=>2011-09-26 22:45:00 UTC, :count=>235}
]
You’ll notice that the times are missing for the time range:
{:timestamp=>2011-09-26 20:15:00 UTC},
{:timestamp=>2011-09-26 20:30:00 UTC},
{:timestamp=>2011-09-26 20:45:00 UTC},
{:timestamp=>2011-09-26 21:00:00 UTC}
How can I take the top as the input and deduce that those would be the missing rows? The time increments will always be 15 minutes, and its actually a real date object not a string like that.
I just can’t picture how to iterate over this.
Any help would be very appreciated.
The easiest way I can think of is to order the array by the time stamp, and then do something like the following:
I had previously written similar code to find half hour gaps in a series of appointments
Although it may look like my solution will loop multiple times over the 15 minute increments between reports.first and reports.last, it will actually loop only once over all available increments between reports.first and reports.last