This file contains 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 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, |
This file contains 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 | |
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 |
This file contains 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
GetSqlQuery <- function(SQL_QUERY_FILEPATH, | |
DEBUG = TRUE){ | |
if(DEBUG) message("GetSqlQuery: Script Initialized \n") | |
FUNCTION_OUTPUT <- list() | |
con = file(SQL_QUERY_FILEPATH, "r") | |
This file contains 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
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") | |
} |
This file contains 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
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") | |
} |
This file contains 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
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") | |
} |
This file contains 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
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)){ |
This file contains 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
import datetime | |
import calendar | |
def AddMonths(DATE_VAL, | |
ADD_N, | |
DATE_FORMAT = "%Y-%m-%d"): | |
print("AddMonths: Function initalized") |
This file contains 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
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"] |
This file contains 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
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") |
NewerOlder