Skip to content

Instantly share code, notes, and snippets.

View foundinblank's full-sized avatar
🤓

Adam Stone foundinblank

🤓
View GitHub Profile
@foundinblank
foundinblank / summary_metrics.sql
Last active November 4, 2022 13:12
Calculate Summary Metrics From User Level Table
select
cohort,
count(user_id) as cnt_users,
sum(cnt_sundae_orders) as total_sundae_orders,
sum(cnt_orders) as total_orders,
sum(total_order_value) as total_order_value,
sum(is_user_converted::int) as cnt_converted_users,
total_sundae_orders / cnt_users as avg_sundae_orders,
total_orders / cnt_users as avg_orders,
total_order_value / total_orders as avg_order_value,
@foundinblank
foundinblank / create_user_level_table.sql
Last active November 14, 2022 16:54
Create User Level Table
create table experiments.sundae_wizard_users as
-- Get all users exposed to the experiment
with exposed_users as (
select
experiment_name,
user_id,
feature_flag_evaluation,
evaluated_at
@foundinblank
foundinblank / cte_or_subquery.sql
Last active January 10, 2019 09:31
Which SQL Do You Prefer?
/*
Suppose tb1 contains 31 rows:
day (Jan 1 to Jan 31)
mins (mins generated that day)
And I want to know the percent distribution of mins for each day in January (i.e., (mins / total_Jan_mins) ).
*/
-- Query 1 (CTE)
@foundinblank
foundinblank / prophet_intro.R
Last active January 10, 2019 09:46
Prophet introduction
library(prophet)
df # A data frame with columns ds & y (datetimes & metrics)
# Create a prophet object
m <- prophet(df)
# Extend dataframe 100 days into the future
future <- make_future_dataframe(m, periods = 100)