Skip to content

Instantly share code, notes, and snippets.

View abmathewks's full-sized avatar

Abraham Mathew abmathewks

View GitHub Profile
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")
}
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")
}
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")
}
GetSqlQuery <- function(SQL_QUERY_FILEPATH,
DEBUG = TRUE){
if(DEBUG) message("GetSqlQuery: Script Initialized \n")
FUNCTION_OUTPUT <- list()
con = file(SQL_QUERY_FILEPATH, "r")
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
/*
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,