
  # -------------------------------------------------------------------------------------------------------------------------  #
  #  -----------------------------------------------------------------------------------------------------------------------   #
  #                                                                                                                            #
  #           File Name              :  XLS_out.r                                                                              #
  #           Last Updated Funclist  :  15 Feb 2014,  1:13 AM (Saturday)                                                       #
  #                                                                                                                            #
  #           Author Name            :  Rick Saporta                                                                           #
  #           Author Email           :  RickSaporta@gmail.com                                                                  #
  #           Author URL             :  www.github.com/rsaporta                                                                #
  #                                                                                                                            #
  #           Packages Called        :  XLConnect                                                                              #
  #           Packages Used via NS   :  NA                                                                                     #
  #                                                                                                                            #
  #  -----------------------------------------------------------------------------------------------------------------------   #
  #                                                                                                                            #
  #                                                                                                                            #
  #                                                                                                                            #
  #                                                                                                                            #
  #                                                     <END FUNCS>                                                            #
  #  -----------------------------------------------------------------------------------------------------------------------   #
  # -------------------------------------------------------------------------------------------------------------------------  #

scp root@107.20.201.0:"/mnt/data/home/rsaporta//git/orch/out/SpotifyAdds/Spot*.csv" '/Users/rsaporta/git/orch/out/SpotifyAdds'

AWS2 <- "root@107.20.201.0"

# ============================================================================= #

library(XLConnect)
f.SIM <- as.path(outDir, "SpotImpressionsMissing.xlsx")
wb.SIM <- loadWorkbook(f.SIM, create = TRUE)

createSheet(wb.SIM, name = "MissingImpressions")
writeWorksheet(wb.SIM, data = unique(DB.using[SpotifyAddRan & is.na(impressions)], by=c("upc", "releaseDate"))[order(releaseDate)]
                , sheet = "MissingImpressions", header=TRUE, rownames=FALSE)

createSheet(wb.SIM, name = "HasImpressions")
writeWorksheet(wb.SIM, data = unique(DB.using[SpotifyAddRan & !is.na(impressions)], by=c("upc", "releaseDate"))[order(releaseDate)]
                , sheet = "HasImpressions", header=TRUE, rownames=FALSE)
saveWorkbook(wb.SIM)
rm(wb.SIM)
cat(paste0("scp ", AWS2, ":/", f.SIM, " ", gsub(path.expand("~"), "~", f.SIM)))

# ============================================================================= #

library(XLConnect)
f.AorB <- as.path(outDir, "AorB_MarketPriority.xlsx")
wb.AorB <- loadWorkbook(f.AorB, create = TRUE)

## Data
# unique(DB.all.meta, by="upc")[mkt_priority=="A or B"][releaseDate >= "2013-01-01"]

createSheet(wb.AorB, name = "AorB")
writeWorksheet(wb.AorB, data = unique(DB.all.meta, by="upc")[mkt_priority=="A or B"][releaseDate >= "2013-01-01"]
                , sheet = "AorB", header=TRUE, rownames=FALSE)

saveWorkbook(wb.AorB)

cat("\n", paste0("scp ", AWS2, ":/", f.AorB, " ", gsub(path.expand("~"), "~", f.AorB)), "\n")

# ============================================================================= #
