Skip to content

Commit

Permalink
Add means to pull data from data warehouse via package.
Browse files Browse the repository at this point in the history
  • Loading branch information
csalvato committed May 18, 2016
1 parent 4883985 commit 2901925
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 9 deletions.
1 change: 1 addition & 0 deletions PowerSupplyUtilities/NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Generated by roxygen2: do not edit by hand

export(get_referrals_data)
export(get_transactions_data)
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
get_referrals_data <- function(from=Sys.Date(),
to=Sys.Date(),
database_driver="database_drivers/postgresql-9.4.1208.jre6.jar",
jdbc_config_file="jdbc_data_warehouse_database_config.txt",
jdbc_config_file="jdbc_datawarehouse_string.txt",
transactions_query_file="referrals_query.sql"){
if(file.exists(database_driver)) {
require(RJDBC)
Expand All @@ -28,8 +28,10 @@ get_referrals_data <- function(from=Sys.Date(),
require(SalvatoUtilities)
referrals_query <- string_from_file(transactions_query_file)
referrals_data <- dbGetQuery(db, referrals_query)
dbDisconnect(db)
return(referrals_data)
} else {
dbDisconnect(db)
stop("Can't find referrals_query.sql (or the file provided) in your working directory.\n\tDownload the file from the git repo (https://github.com/powersupplyhq/adwords-analysis), put it in your working directory and try again.")
}
} else {
Expand Down
2 changes: 2 additions & 0 deletions PowerSupplyUtilities/R/get_transactions_data.r
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ get_transactions_data <- function(from=Sys.Date(),
require(SalvatoUtilities)
transactions_query <- string_from_file(transactions_query_file)
transactions <- dbGetQuery(db, transactions_query)
dbDisconnect(db)
return(transactions)
} else {
dbDisconnect(db)
stop("Can't find transactions_query.sql (or the file provided) in your working directory.\n\tDownload the file from the git repo (https://github.com/powersupplyhq/adwords-analysis), put it in your working directory and try again.")
}
} else {
Expand Down
33 changes: 33 additions & 0 deletions PowerSupplyUtilities/man/get_referrals_data.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions PowerSupplyUtilities/man/get_transactions_data.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 1 addition & 8 deletions adwords.r
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,8 @@ adwords_keywords_data <- keyword_performance_data(from=as.Date(start_date), to=a
adwords_campaigns_data <- campaign_performance_data(from=as.Date(start_date), to=as.Date(end_date))

# Retrieve revenue data
pgsql <- JDBC("org.postgresql.Driver", "database_drivers/postgresql-9.4.1208.jre6.jar", "`")
datawarehouse_db <- dbConnect(pgsql, string_from_file("jdbc_datawarehouse_string.txt"))
influencer_metrics_query <- string_from_file("influencer_metrics_query.sql")
db_influencer_metrics <- dbGetQuery(datawarehouse_db, influencer_metrics_query)

db_transactions <- get_transactions_data(from=start_date, to=end_date)
db_influencer_metrics_new <- get_referrals_data(from=start_date, to=end_date)

# Join Mixpanel Conversion Data with Data Warehouse transaction data
mixpanel_adwords_conversions <- data.frame(mixpanel_adwords_conversions)
Expand Down Expand Up @@ -81,9 +77,6 @@ db_first_transactions <- dbGetQuery(heroku_db, GetoptLong::qq(paste("SELECT
WHERE
first_transaction between '@{start_date}' and '@{end_date}'")))

dbDisconnect(datawarehouse_db)
dbDisconnect(heroku_db)

#Filter out people where their first order was not in the specified start_date and end_date
db_transactions <- db_transactions %>% filter(is.element(app_user_id, db_first_transactions$id))

Expand Down
File renamed without changes.

0 comments on commit 2901925

Please sign in to comment.