Skip to content

Instantly share code, notes, and snippets.

View abmathewks's full-sized avatar

Abraham Mathew abmathewks

View GitHub Profile
/*
Query collects the reader funnel stats from item views, enters & reader mode
tap actions. Counts the number of events and the distinct count of users per day
*/
WITH
--CTE to declare common variables used in the CTE
vars_cte as (
select
'2022-05-01'::DATE AS start_date,
SELECT
ob.lead_id,
DATE(ob.create_date),
TIME(ob.create_date),
ob.affiliate_id,
ob.amount AS 'our_cost',
ob.won_ping,
ob.lead_type
FROM our_bids AS ob
GetSqlQuery <- function(SQL_QUERY_FILEPATH,
DEBUG = TRUE){
if(DEBUG) message("GetSqlQuery: Script Initialized \n")
FUNCTION_OUTPUT <- list()
con = file(SQL_QUERY_FILEPATH, "r")
AddEngineeredDates <- function(AGG_TS_DATA,
DATE_COLUMN = "date",
DEBUG = TRUE){
if(DEBUG) message("AddEngineeredDates: Function Initialized \n")
if(!data.table::is.data.table(AGG_TS_DATA)){
stop("AddEngineeredDates: The input data is not a data table \n")
}
PackageCheck <- function(USE_THESE_PACKAGES,
DEBUG = TRUE){
if(DEBUG) message("PackageCheck: Function initialized \n")
if(any(USE_THESE_PACKAGES == "")){
stop("PackageCheck: An empty string element was passed in USE_THESE_PACKAGES \n")
}
AddMonths <- function(DATE_VAL,
ADD_N = NULL,
DEBUG = TRUE){
if(DEBUG) message("AddMonths: Function initialized \n")
if(!lubridate::is.Date(DATE_VAL)){
stop("AddMonths: DATE_VAL is not a date format \n")
}
CreateProjectFiles <- function(PROJECT_PATH = rstudioapi::getActiveProject(),
FOLDERS_TO_CREATE = c("data", "docs", "figs", "logs",
"output", "queries", "R", "tests"),
OPEN_NEW_SESSION = TRUE,
DEBUG = TRUE){
if(DEBUG) message("CreateProjectFiles: Function initialized \n")
if(!dir.exists(PROJECT_PATH)){
import datetime
import calendar
def AddMonths(DATE_VAL,
ADD_N,
DATE_FORMAT = "%Y-%m-%d"):
print("AddMonths: Function initalized")
def CreateProjectFiles(PROJECT_PATH):
print("CreateProjectFiles: Function initalized")
if os.path.exists(PROJECT_PATH) and any(os.scandir(PROJECT_PATH)):
folders = ["data", "deploy", "docs", "models", "notebooks",
"scripts", "tests", "utils"]
RunAllModels <- function(USE_THESE_FORMULAS = all_formulas,
MODEL_DATA = model_data,
DATA_DIMENSION = dim_name,
DATE_COLUMN = "date_ymd",
TARGET_COLUMN = "visits",
DEBUG = TRUE){
if(DEBUG) message("RunAllModels: Function Initialized \n")