

# -------------------------------------------------------------------------------------- #                                                                                                                                
#  THIS IMAGE:                                                                           #
#                                                                                        #
#  "/mnt/data/rstudiohome//gitData/ImageSaves/SpotifyAdds_ImageSave_20131108_0128.Rda"   #
#                                                                                        #
#  IS AFTER RUNNING ALL OF "# 01", but before "# 02"                                     #
#  (there are some screaps of "# 02" from a previous run)                                #
#                                                                                        #
#                                                                                        #
#                    Name      Size       Type     Rows Columns Key                      #
#  1:              DB.raw  20.81 GB data.table 56658091      55 upc                      #
#  2:    DB.all.countmeta   2.74 GB data.table 22285244      16 upc                      #
#  3:             DB.Meta 205.68 KB data.table      251      28 upc                      #
#  4:      DB.SpotifyMeta 201.74 KB data.table      254      42 upc                      #
#  5: DB.SpotifyMeta.Long 146.88 KB data.table      303      40 upc                      #
#  6:         SpotifyAdds  99.76 KB data.table      257      26 upc                      #
# -------------------------------------------------------------------------------------- #                                                                                                                                


## TO RUN THIS
#  srcDir <- "~/git/orch/src/SpotifyAdds/"
#  source(paste0(srcDir, "/! GO.r"))


# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #
#                     00  PRELIMS
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #

	.g()
	utilSource()
	fresh()
	utilSource()
	utilSource()
	refresh <- FALSE


	srcDir <- "~/git/orch/src/SpotifyAdds/"
	runBySourcingFolders(foldersList="00_Setup", parentFolder=srcDir) 
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #





##  01 DATA INGESTION  ##
tbls01 <- c("SpotifyAdds", "DB.Meta", "DB.raw", "DB.all.meta", "DB.all.count")
for (tbl in tbls01) {
	if (is.na(nameCheck(tbl, pulldata)))
		stop("\nInvalid input for tbl= '", tbl, "'\n")
}
for (tbl in tbls01) {
	tbl <- nameCheck(tbl, pulldata)
	if (pulldata[[tbl]]) 
		runBySourcingFolders(foldersList=tbl, parentFolder=as.path(srcDir, "01_DATA_INGESTION")) 
	else {
		if (tbl=="DB.raw" && isTRUE(pulldata[["DB.SpotifyMeta"]])) {
			loadFromJesus("DB.raw.RAW", assignTo="DB.raw", overwrite.ifexists=TRUE)
		}
		else 
			loadFromJesus(tbl, overwrite.ifexists=TRUE)
	} 

}


##  02 DT FROM MERGES  ##
tbls02 <- c("DB.all.countmeta", "DB.SpotifyMeta")

for (tbl in tbls02) {
	if (is.na(nameCheck(tbl, pulldata)))
		stop("\nInvalid input for tbl= '", tbl, "'\n")
}
for (tbl in tbls02) {
	tbl <- nameCheck(tbl, pulldata)
	if (pulldata[[tbl]]) 
		runBySourcingFolders(foldersList=tbl, parentFolder=as.path(srcDir, "02_DT_from_Merges")) 
	else 
		loadFromJesus(tbl, overwrite.ifexists=TRUE)
}

##  03 DT FROM RESHAPES  ##
tbls03 <- c("DT.SpotifyMeta.Long")
for (tbl in tbls03) {
	if (is.na(nameCheck(tbl, pulldata)))
		stop("\nInvalid input for tbl= '", tbl, "'\n")
}
for (tbl in tbls03) {
	tbl <- nameCheck(tbl, pulldata)
	if (pulldata[[tbl]]) 
		runBySourcingFolders(foldersList=tbl, parentFolder=as.path(srcDir, "03_DT_from_Reshapes")) 
	else 
		loadFromJesus(tbl, overwrite.ifexists=TRUE)
}


##  04 AGGREGATIONS & MODIFICATIONS  ##
runBySourcingFolders(foldersList="04_Aggregations & Modifications", parentFolder=srcDir) 

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #

##   SAVE YOUR WORK 
reproduce(fileBackUps)
saveImageTo(projName="SpotifyAdds", subProj="COMPLETED.01.02.03.04", verbose=TRUE)




