This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "Vega Visualization", | |
"height": 20, | |
"padding": "auto", | |
"marks": [ | |
{ | |
"name": "cell", | |
"marks": [ | |
{ | |
"properties": { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "Vega Visualization", | |
"height": 450, | |
"padding": "auto", | |
"marks": [ | |
{ | |
"properties": { | |
"enter": { | |
"x": { | |
"offset": 31, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "boxplot", | |
"height": 200, | |
"padding": "auto", | |
"width": 600, | |
"signals": [ | |
{ | |
"name": "boxSize", | |
"init": 40 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
"uid", | |
"event_timestamp", | |
"minutes_since_last_event", | |
"event_boundary", | |
"session_id" | |
FROM ( | |
SELECT | |
"uid", | |
"event_timestamp", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
###Sessionization using dplyr | |
library(dplyr) | |
#Open a localhost connection to Postgres | |
#Use table 'single_col_timestamp' | |
#group by uid and sort by timestamp for window function | |
#Do minutes calculation, working around missing support for extract(epoch from timestamp) | |
#Calculate event boundary and unique id via cumulative sum window function | |
sessions <- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--Query 3: Outer query uses window function with sum to do cumulative sum as the id, concatentate to uid | |
select | |
uid, | |
uid || '-' || cast(sum(new_event_boundary) OVER (PARTITION BY uid ORDER BY event_timestamp) as varchar) as session_id, | |
event_timestamp | |
from | |
--Query 1: Define boundary events | |
(select | |
uid, | |
event_timestamp, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select | |
uid, | |
sum(new_event_boundary) OVER (PARTITION BY uid ORDER BY event_timestamp) as session_id, | |
event_timestamp, | |
minutes_since_last_interval, | |
new_event_boundary | |
from | |
--Query 1: Define boundary events | |
(select | |
uid, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--Create boundaries at 30 minute timeout | |
select | |
uid, | |
event_timestamp, | |
(extract(epoch from event_timestamp) - lag(extract(epoch from event_timestamp)) OVER (PARTITION BY uid ORDER BY event_timestamp))/60 as minutes_since_last_interval, | |
case when extract(epoch from event_timestamp) - lag(extract(epoch from event_timestamp)) OVER (PARTITION BY uid ORDER BY event_timestamp) > 30 * 60 then 1 ELSE 0 END as new_event_boundary | |
from single_col_timestamp; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DataFrame(julia_tweets_100) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
julia_tweets_100 = get_search_tweets("#julialang"; options = {"count" => "100"}) |