I don't know even how to name my problem - I have a list of tuples in python:
(int, str, datetime, float)
There is a bunch of rows in that list, they are sorted by datetime and I'd like to count how much rows in a 5 minute time span, which have floats in given range, i.e. from 0 to 2, from 2 to 5, from 5 to 10 and so on. I mean, by given such data (date is not string, but datetime.datetime):
(1, 'abc', '2014-09-10 17:50:34', 5.5)
(2, 'abc', '2014-09-10 17:51:34', 1.5)
(3, 'abc', '2014-09-10 17:52:14', 7.1)
(4, 'abc', '2014-09-10 17:59:34', 9.5)
(5, 'abc', '2014-09-10 17:59:54', 9.2)
I'd like to receive some kind of dictionary:
{ the_end_of_time_interval1: {'0to2': int, '2to5': int, '5to10': int, ... },
the_end_of_time_interval2: {'0to2': int, '2to5': int, '5to10': int, ... },
...}
for example:
{ '2014-09-10 17:52:34': { '0to2': 1, '2to5': 0, '5to10': 2, '10to15': 0 },
'2014-09-10 17:59:54': { '0to2': 0, '2to5': 0, '5to10': 2, '10to15' : 0 } }
My question is - is there some elegant way to do that? I'd like to save it to the file and send it to some database for purpose of monitoring.