Hello,
Our aim is to build timelines saying about periods of time when user was online. (It really doesn't matter what user we are talking about and where he was online) To get information about onliners we can call API method, someservice.com/api/?call=whoIsOnline
whoIsOnline method will give us a list of users currently online. But there is no API method to get information about who IS NOT online.
So, we should build our timelines using information we got from whoIsOnline. Of course there will be a measurement error (we can't track information in realtime). Let's suppose that we will call whoIsOnline method every 2 minutes (yes, we will run our script by cron every 2 minutes).
For example, calling whoIsOnline at 08:00 will return
Peter_id
Michal_id
Andy_id
calling whoIsOnline at 08:02 will return
Michael_id
Andy_id
George_id
As you can see, Peter has gone offline, but we have new onliner - George.
Available instruments are Db(MySQL) / text files / key-value storage (Redis/memcache); feel free to choose any of them (or even all of them).
So, we have to get information like this
George_id was online...
12 May: 08:02-08:30, 12:40-12:46, 20:14-22:36
11 May: 09:10-12:30, 21:45-23:00
10 May: was not online
And now question...
How would you store information to implement such timelines?
How would you query/calculate information about periods of time when user was online?
Additional information..
You cannot update information about offline users, only users who are "currently" online.
Solution should be flexible: timeline information could be represented relating to any timezone.
We should keep information only for last 7 days.
Every user seen online is automatically getting his own identifier in our database.
Uff.. it was really hard for me to write it because my English is pretty bad, but I hope my question will be clear for you.
Thank you.