Skip to content

Instantly share code, notes, and snippets.

@rex-lin
rex-lin / Featured Creators
Last active August 13, 2018 17:23
Featured Creators
@rex-lin
rex-lin / First Open Due to Push iOS
Created April 26, 2017 19:12
First Open Due to Push iOS
-- adjuststed for daylights savings
drop table analysts.push_sent_appboy_ios;
drop table analysts.push_open_appboy_ios;
drop table analysts.push_open_amplitude_ios;
SELECT external_user_id, (time + (0*INTERVAL '1 hour'))::date as date, min((time + (0*INTERVAL '1 hour'))) as event_time
into analysts.push_sent_appboy_ios
FROM appboy."event"
where (time + (0*INTERVAL '1 hour'))::date between '2017-03-15' and '2017-04-25'
@rex-lin
rex-lin / Branch Dashboard
Last active March 30, 2017 19:56
Branch Dashboard
-- Install and Referred Sessions Events
with user_mapping as (
SELECT branch_identity_id, developer_identity as user_id
FROM branchio.event a
where developer_identity is not null
and developer_identity != ''
group by 1,2
)
select event_date, device_os as os, event_name, session_referring_link_channel as channel, session_referring_link_feature as feature, session_referring_link_campaign as campaign, session_referring_link_tags as tags, branch_identity_id
@rex-lin
rex-lin / AWS Session Duration
Last active March 27, 2017 22:09
AWS Session Duration
select date, sum(elapsed_time) as duration, count(distinct client_id) as user_count
from (
select event_timestamp::date as date, EXTRACT(SECOND FROM session_stop_timestamp-session_start_timestamp) as elapsed_time, client_id
from awsma.v_event
where event_timestamp between '2017-03-10' and '2017-03-13'
and event_type = '_session.stop'
and application_sdk_name = 'aws-sdk-iOS'
)
where elapsed_time <= 7200
@rex-lin
rex-lin / Moderation Performance
Created March 3, 2017 22:00
Moderation Performance
select date_created, moderator, sum(case when action_taken = 'FLIPAGRAM_MODERATION_APPROVED' then 1 else 0 end) as approved_count,
sum(case when action_taken = 'FLIPAGRAM_MODERATION_NOT_APPROVED' then 1 else 0 end) as not_approved_count
from pa.vw_interim_moderator_action
group by 1,2
order by 1,2 asc
@rex-lin
rex-lin / User Profiles v2
Last active April 12, 2017 23:37
User Profiles v2
- Big Query ---
-- export csv of this data and import into redshift
select user_id, source, campaign, date
from (
select user_id, source, campaign,date, ROW_NUMBER() OVER (PARTITION BY user_id ORDER BY date ASC) row_num
from (
SELECT
ud.value.value.string_value AS user_id,
@rex-lin
rex-lin / First Open Due to Push Analysis - Android
Last active April 26, 2017 18:39
First Open Due to Push Analysis - Android
-- adjuststed for daylights savings
drop table analysts.push_sent_appboy;
drop table analysts.push_open_appboy;
drop table analysts.push_open_amplitude;
SELECT external_user_id, (time + (0*INTERVAL '1 hour'))::date as date, min((time + (0*INTERVAL '1 hour'))) as event_time
into analysts.push_sent_appboy
FROM appboy."event"
where (time + (0*INTERVAL '1 hour'))::date between '2017-03-15' and '2017-04-25'
@rex-lin
rex-lin / Historical Flipagrams with Engagement
Created February 16, 2017 23:00
Historical Flipagrams with Engagement
----------historical flip check with engagement--------------
with flipagram_check as (
select a.flipagram_id
from (
SELECT id as flipagram_id, created_by as user_id
FROM pf.dim_flipagram
where date_created between '2013-01-01' and '2016-12-31'
and duration between 3000 and 30000
and status = 'PUBLIC') a
join
@rex-lin
rex-lin / SUL Flipagram Check
Created February 16, 2017 23:00
SUL Flipagram Check
----------SUL flip check--------------
drop table analysts.sul_flips_filtered;
with flipagram_check as (
SELECT id as flipagram_id
FROM pf.dim_flipagram
where date_created between '2013-01-01' and '2017-12-31'
and duration between 3000 and 30000
and status = 'PUBLIC'
),
@rex-lin
rex-lin / Recent Flipagram Music Usage
Created February 16, 2017 22:51
Recent Flipagram Music Usage
----------recent flip check--------------
with flipagram_check as (
select a.flipagram_id, music_title, music_artist
from (
SELECT id as flipagram_id, created_by as user_id, coalesced_music_track_title as music_title, coalesced_music_artist_name as music_artist
FROM pf.dim_flipagram
where date_created between '2016-11-01' and '2017-02-07'
and duration between 3000 and 60000
and status = 'PUBLIC') a
join