setWidth(251)
setGitBranchToSystem(); .g();
setScience("misc", subProj="Lee_Music_Spotify")

# cluster <- 7
# 
# setDBall(cluster=cluster)
# DT.labels <- get_dim_label()

sfShowWarehouses()
# wh <- "SCIENCE"
wh <- "LOOKER_WH_LARGE"
setSnowflake(wh=wh, dbname="prod", schema="production")


{
whereIn <- list(storeid = c(1, 286))
tbl <- "fact_analytics"
dateCol <- "download_activity_date"
colsToPull <- c(dateCol, "labelid", upc="releaseid", "trackid", "storeid", "transactiontypeid") # "countryid", 
colsToAgg <- c("units" = "paidunits")
minDate <- as.Date('2015-05-01')
Q.fact_analytics <- makeQry(tbl=tbl, colsToPull=colsToPull, colsToAgg=colsToAgg, minDate=minDate, dateCol=dateCol, whereIn=whereIn, key=NULL)

# DT.anal <- runQry(Q.fact_analytics, cluster=cluster)
DT.daily_units_apple_spotify__fact_analytics <- sfQry(Q.fact_analytics)
jesusForData(DT.daily_units_apple_spotify__fact_analytics, info="NoCountry")
}

{
  setDBall(7)
  DT.monthly_units_apple_spotify__fact_analytics <- aggregateMonthly(DT.daily_units_apple_spotify__fact_analytics, dateCol=dateCol, newCol.nm="month", byCols=colNamesFromVector(colsToPull))
  .myf(addMeta)
  addAllMeta_(DT.monthly_units_apple_spotify__fact_analytics, track.info=TRUE, abbr.transacs=TRUE, description.transacs=TRUE, artist.info=TRUE, genre.info=TRUE, label.info=TRUE, label_is_red=TRUE, label_sc_group=FALSE, upc_by_track=FALSE)
  jesusForData(DT.monthly_units_apple_spotify__fact_analytics)

  locate(addAllMeta_)

}
