DT.isrc_candidates <- sfQry("SELECT isrc, date, streams_accel_score_scaled, new_users_accel_score_scaled FROM prod.spot_user_counts.by_isrc where new_users_accel_score_scaled > .90 and date > '2015-12-01' limit 5800")

isrcs <- DT.isrc_candidates[, .N, keyby=isrc][N>1, isrc]
isrcs %<>% c("USMEI1300005")

DT.isrc_metadata <- getISRCMeta(isrcs, drop_parent=FALSE)

DT.isrc_streams <- sfQry(makeQry(schema="SPOT_STREAM_COUNTS", tbl="BY_ISRC", isrc=isrcs, limit=NULL, colsToPull="*", expandStar=FALSE))
DT.isrc_users <- sfQry(makeQry(schema="SPOT_USER_COUNTS", tbl="BY_ISRC", isrc=isrcs, limit=NULL, colsToPull="*", expandStar=FALSE)) %>% setnames("date", "weekof")

try(setnames(DT.isrc_streams, "streams_diff_in_streams", "streams_increase"))
try(setnames(DT.isrc_users, "new_users_diff_in_streams", "new_users_increase"))
try(setnames(DT.isrc_streams, "t2_streams", "cumulative_streams"))
try(setnames(DT.isrc_users, "t2_new_users", "cumulative_new_users"))


## clean column names so that we can stack them 
DT.isrc_streams[, what := "streams"]
DT.isrc_users[, what := "new_users"]
tmp.streams <- copy(DT.isrc_streams) %>% setnames(., removeText("_?streams_?", names(.))) %>% setnames("", "count")
tmp.users <- copy(DT.isrc_users[, names(DT.isrc_streams) %>% gsub("streams", "new_users", .), with=FALSE]) %>% setnames(., removeText("_?new_users_?", names(.))) %>% setnames("", "count")
DT.isrc_streams_and_users <- rbind(tmp.streams, tmp.users)

setkeyIfNot(DT.isrc_metadata, isrc)
setkeyIfNot(DT.isrc_streams_and_users, isrc, weekof)

DT.isrc_streams_and_users[unique(DT.isrc_metadata, by="isrc"), c("artist_name", "track_name", "label_name", "CM") := list(artist_name, track_name, label_name, client_manager)]

jesusForData("DT.isrc_metadata")
jesusForData("DT.isrc_streams_and_users")

## ON LOCAL COMPUTER
"~rsaporta/git/orch/data/Discover_Weekly/DT.isrc_streams_and_users-20160127_0339-196x9.RDS"
"~rsaporta/git/orch/data/Discover_Weekly/DT.isrc_streams_and_users-20160127_0350-27797x9.RDS"
.ljo()

top_isrcs <- c(
## Blew up in October, then dropped
## Bliss bluew up three times, but then dropped
Gavin="GBBET0801440", Bliss="GBPCP1200690"
## RED: blew up in September, dropping since, but might be back on the rise
,"Lights | Banner (Acoustic)" = "CA5DG1300001"
## Had a big blow up in December
,"DR Big Band | Rudolph The Red Nosed Reindeer (feat. Sinne Eeg & Bobo Moreno)" = "DKABA0900797"

,"Marcus Marr & Chet Faker | Birthday Card" = "AUFF01500736"
,"Jewel | Let It Snow! Let It Snow! Let It Snow!" = "CASD11300326"
,"Various Artists | Jingle Bells" = "ES5831301665"
,"Villancicos Populares Vol.2 (Popular Songs) | Alepum" = "ES6100676601"
,"Villancicos Populares Vol.2 (Popular Songs) | Campanas de Belén" = "ES6100676602"
,"Villancicos Populares Vol.2 (Popular Songs) | Catatumba" = "ES6100676604"
, "Villancicos Populares Vol.2 (Popular Songs) | Noche De Paz" = "ES6100676607"
,"Villancicos Populares Vol.2 (Popular Songs) | Dime Niño ¿De Quién Eres?" = "ES6100676613"
,"Villancicos Populares Vol.2 (Popular Songs) | Los Campanilleros" = "ES6100676618"
,"Various Artists | Midnight City" = "GB55H1100002"
,"Jona Lewie | Stop The Cavalry" = "GBAHW0500394"
,"Frankie Goes To Hollywood | The Power of Love" = "GBAHW9900034"
,"Various Artists | Christmastime All Over The World" = "GBJWE1105553"
,"James Rhodes | Piano Sonata in D Major, Op. 28 - 'Pastoral': I. Allegro" = "GBLLH1437107"
,"James Rhodes | Orfeo ed Euridice: Mélodie (arr. Sgambati)" = "GBLLH1437113"
,"Fiona Bevan | They Sang Silent Night" = "GBN7D1400023"
,"Banda Sinaloense MS de Sergio Lizarraga | Solo Con Verte" = "MXB951500003"
,"Nelly | The Fix (feat. Jeremih)" = "QM33K1500003"
,"Catey Shaw | Cuddle Up" = "QM6MZ1408195"
,"Universal Orchestra | Santa Claus Is Coming to Town" = "QM6MZ1414421"
,"Phoria | Saving Us a Riot" = "QM6MZ1479063"
,"WrongONyou | Killer" = "QM6P41451044"
,"This Will Destroy You | Their Celebrations" = "QMDA61346604"
,"Chase Rice | Carolina Can" = "QMDR71400006"
,"Josh Ritter | Getting Ready to Get Down" = "QMFBM1530003"
,"JOHNNYSWIM | Christmas Day" = "QMHPC1300071"
,"JOHNNYSWIM | I'll Be Home for Christmas" = "QMHPC1300074"
,"Holiday Rappers | Christmas in Harlem" = "QMHTL1300135"
,"Kina Grannis | Chandelier" = "QMJW51400073"
,"Adventure Club | Limitless (feat. Delaney Jane)" = "QMRSZ1501488"
,"Kuduro Workout Crew | Danza Kuduro" = "QMVRR1230060"
,"Manotett | Faces" = "SE3T61500301"
,"U137 | Varberg" = "US4KH1355205"
,"Lights & Motion | Fireflies" = "US4KH1556001"
,"Various Artists | Twist and Shout" = "US6R21367200"
,"This Will Destroy You | They Move On Tracks Of Never-Ending Light" = "US76L0710411"
,"Singer's Edge Karaoke | Don't Worry (Originally Performed by Madcon & Ray Dalton) [Karaoke Version]" = "US8K20129557"
,"Bruce Brubaker | Opening" = "USA220710014"
,"Jingle Bells | Jingle Bell Rock" = "USA561411145"
,"Banda La Misma Tierra | Ya Me Cansé" = "USASN1502404"
,"Kermit Ruffins | A Saints Christmas" = "USBAS0900306"
,"Marcus Marr & Chet Faker | The Trouble with Us" = "USCJ81501360"
,"Cross Record | High Rise" = "USCPT1510151"
,"Willie Colón & Héctor Lavoe | Aires De Navidad" = "USDBB0601693"
,"Willie Colón & Héctor Lavoe | Potpourri Navideño: Estrella De Oriente (De Tierras Lejanas) / Noche De Paz / La Virgen María / La Tierra Mia" = "USDBB0606159"
,"Mimicking Birds | Walking in the Air" = "USFP71554901"
,"El Gran Combo De Puerto Rico | La Fiesta de Pilito" = "USMRE0891028"
,"Sleigh Bells | Rill Rill" = "USQE91000035"
,"Kelsea Ballerini | Peter Pan" = "USS9T1500010"
,"Marama | Nena" = "UYM121501378"
,"Marama | Loquita" = "UYM121501379"
,"Marama | No Te Vayas" = "UYM121501380"
,"Marama | Todo Comenzó Bailando" = "UYM121501381"
,"Marama | Bronceado" = "UYM121501382"
,"Marama | Una Noche Contigo" = "UYM121501383"
,"Marama | Tal Vez" = "UYM121501384"
,"Marama | Te Amo y Odio" = "UYM121501385"
,"Marama | Volverte a Ver" = "UYM121501386"
,"Marama | Te Conozco" = "UYM121501387"
,"Marama | Noche Loca" = "UYM121501388"
  )


## BLOWING UP -- all of these
,"Simone e Simaria | Não Vou Mais Atrás de Você (feat. Wesley Safadão)" = "BR8H81400021"
,"Tiago Iorc | Alexandria" = "BRRGE1501674"
,"Zé Neto & Cristiano | Eu Ligo Pra Você" = "BRWNV1500029"
,"Wesley Safadão | Tim Tim" = "BRWRT1500098"

## ALSO BLOWING UP
,"Diego Herrera | Si Te Enamoras de Mí" = "MXB711500540"


DT.isrc_metadata[isrc %in% top_isrcs]

artist_NOT_using <- c("The Turtles", "Turtles", "Nicky Jam", "Nelly", "Daya", "Cold War Kids")
isrcs_plotting <- DT.isrc_streams_and_users[(count>50000) & isrc %ni% top_isrcs, unique(isrc)]
isrcs_plotting <- DT.isrc_metadata[isrc %in% isrcs_plotting & artist_name %ni% artist_NOT_using, unique(isrc)]
top_isrcs <- DT.isrc_streams_and_users[isrc %in% isrcs_plotting & accel_score_scaled > .90, .N, keyby=list(isrc, artist_name, track_name)][, setNames(nm=paste0(artist_name, " | ", track_name), isrc)]
# top_isrcs %<>% head(8)
L <- length(top_isrcs)
i <- 0;

j <- i+1; i <- i+4; print(j:i); ggLinegraph(DT.isrc_streams_and_users[isrc %in% top_isrcs[j:i] & weekof >= '2015-08-01'], x="weekof", y="count", color="what", facet_y=rev(c("artist_name", "track_name", "isrc")), title="Tracks blowing up as of late")
sprintf("\"%s\" = \"%s\"", names(top_isrcs), top_isrcs) %>% pasteC("\n,") %>% catn
sprintf("\"%s\" = \"%s\"", names(top_isrcs), top_isrcs) %>% pasteC("\n,") %>% catn

DT.isrc_metadata["QM4ZV1500057"]

Answer the following : 
  - What playlists did it appear on during the two weeks following its acceleration
  - What countries did that stream in


ggLinegraph(DT.isrc_streams_and_users[isrc %in% top_isrcs[j:i]], x="weekof", y="count", color="what", dotsize.scale=2, facet_y=rev(c("artist_name", "track_name", "isrc")), x_angledtext=85, x_relativetext=.9, title="Tracks blowing up as of late") + scale_x_date(breaks = date_breaks("week"))

