On a small test-site i'd like to log the approximately period of time a user actively spends on certain link groups per day. Thereofore on any user click i save a document like this:
Example document:
{
"routeGroup": "a",
"time": new Date()
}
The idea is to filter all documents of a certain day, sort these by time and return the continuous period of time a user has spend on a routeGroup.
Example:
Given the following Documents (already sorted by day and filtered by time):
{"routegroup": "a", "time": 11:30:00},
{"routegroup": "a", "time": 11:31:00},
{"routegroup": "a", "time": 11:32:00},
{"routegroup": "b", "time": 11:33:00},
{"routegroup": "b", "time": 11:34:00},
{"routegroup": "a", "time": 11:35:00},
{"routegroup": "b", "time": 11:36:00},
{"routegroup": "a", "time": 11:37:00},
{"routegroup": "a", "time": 11:38:00},
{"routegroup": "a", "time": 11:39:00}
So the user has first spend 3 minutes in group "a" followed by 2 minutes in group "b", 1 minute in group "a" and so on.
These periods of time are sensitive up to seconds and i'd then like to sum and return something like:
// total time spend in routeGroups on day x
{"routegroup": "a", "timeTotal": "7:00"},
{"routegroup": "b", "timeTotal": "3:00"}
Question: Is this possible and if, how?
Thanks in advance for your help!
Muff