ROUGH ANALYSIS


----

# For a few UPCs, lets start by looking just at the raw daily numbers.  No breakdown. 
# That is, no specific user information.  
# No "who downloaded what, when or where"
# Just aggregate: "This was downloaded <this many> times per day"
#
# Collect whatever useful info we have from the DB.SpotifyMeta dt 

metcols   <- c("t.DailyCount.byupc", "u.DailyCount.byupc")
idCols    <- c("upc", "download_date")
colsUsing <- c(idCols, metcols)

# DT.using is a subset of DB.raw, with ajust a few metric columns
DT.using  <- setkey(unique(DB.raw[, colsUsing, with=FALSE], by=colsUsing), upc, download_date)

DB.SpotifyMeta.Long

## These should be identical
stopifnot(DB.SpotifyMeta[, identical(XLS.releaseDate, startDate)])

colsUsing <- 
c("upc", "artist", "artist_country", "release"
  , "audio.ads", "commentary", "ctr"
  , "formatOfAddProd", "genre", "impressions"
  , "label_priority", "mkt_priority"
  , "releaseDate", "sale_start_date", "startDate"
  , "streamsW1", "totalStreamsW1"
  , "streamsW2", "totalStreamsW2"
)

c("artistId", "deletions", "display_upc", "heat", "imprint", 
"label", "label_country", "labelId", "manufacturer_upc", "notes", 
"notes2", "original_release_date", "product_type_id", "RqstdImpressions", 
"soundrop.room", "subaccountId", "Top200", 

"total", "adSuppStreams", 
"streams", "totalStreams", "Week", "PercOfStreamsAdSupptd")



S.colsUsing <- c("upc", "format", "streamsW1", "streamsW2", 
                  "adSuppStreamsW1", "adSuppStreamsW2", "totalStreamsW1", "totalStreamsW2", 
                  "total", "impressionsRqstd", "impressionsDelivd", "ctr", 
                  "wk1", "wk2", "startDate")   #  startDate should be XLS.releaseDate

DB.SpotifyMeta <- DB.SpotifyMeta[!is.na(upc) & !is.na(impressionsDelivd)]
DB.SpotifyMeta[, upc := as.idcol(upc)]
Spot.using <- setkey(DB.SpotifyMeta[, S.colsUsing, with=FALSE], "upc", "startDate")


setkeyIfNot(DT.using,   "upc")
setkeyIfNot(Spot.using, "upc")

DT.using[Spot.using]

Z1 <- Spot.using[DT.using, nomatch=0]
Z2 <- DT.using[Spot.using, nomatch=0]
compareDTs(Z1, Z2)




