I have a list of web browsing data that I'm attempting to convert into a sessions.
An example dataset from a user:
time_millis Type Result
07/10/2015 08:31 1 0
07/10/2015 08:41 1 0
07/10/2015 08:48 2 0
07/10/2015 08:50 2 0
07/10/2015 09:11 2 1
07/10/2015 09:14 3 0
07/10/2015 09:15 1 0
07/10/2015 09:17 1 0
07/10/2015 10:31 1 0
07/10/2015 10:33 1 0
07/10/2015 10:36 1 0
07/10/2015 18:57 1 1
I am trying to achieve:
time_millis Type Result Session
07/10/2015 08:31 1 0 1
07/10/2015 08:41 1 0 1
07/10/2015 08:48 2 0 2
07/10/2015 08:50 2 0 2
07/10/2015 09:11 2 1 3
07/10/2015 09:14 3 0 4
07/10/2015 09:15 1 0 4
07/10/2015 09:17 1 0 4
07/10/2015 10:31 1 0 5
07/10/2015 10:33 1 0 5
07/10/2015 10:36 1 0 5
07/10/2015 18:57 1 1 6
I'd like to partition the sessions by a 15 minute
window per user and also create a new session if the 'Type'
is changed.
I've tried using the following bit of code, though I don't think it performs as I'd like above:
CONDITIONAL_TRUE_EVENT("time_millis" > coalesce(lag("time_millis"), 1)
+ 900000 OR type != LAG(type,1)) OVER (PARTITION BY user ORDER BY
time_millis) AS session_id