setScience("MissingData2015", load=FALSE, subl=FALSE, create=TRUE)

dateCol    <- "download_activity_date"
colsToPull <- c(dateCol, "storeid", "transactiontypeid")

## Query and Execute
Q.missing <- makeQry(tbl="fact_analytics", where=list(storeid=c(1, 286)), aggFunc="count", colsToPull=colsToPull, minDate="2014-12-01", key="colsToPull", dateCol=dateCol)
DT.missing <- runQry(Q.missing)


## Add in NAs for missing rows
DT.missing <- DT.missing[CJ_allDatesByCols(DT.missing, dateCol=dateCol, universal=TRUE, interval="day")]

## Metadata
addStoreName.storeid_(DT.missing)
addTransacInfo_(DT.missing)

## save it
if (.Pfm == "Linux") jesusForData(DT.missing) else {.g(); loadFromJesus("DT.missing", over=TRUE)}

for (store in names(PLOTS.missingdata_by_store)) {
   PLOTS.missingdata_by_store[[store]] <-
    ggLinegraph(DT=DT.missing[store_name == store], x=dateCol, y="rows"
      , color="transac_type_abbr"
      , title=store, title_append="rows of data by transaction type"
      , ylab_append = "Please Note the different scale in each facet"
      , legend="bottom"
      , facet_formula=if (store == "Spotify") NULL else "transac_type_abbr ~ ."
      , facet_scales="free"
      # , vline="2014-12-24"
      )
}

P.Spotify <- PLOTS.missingdata_by_store[["Spotify"]]
P.iTunes <- PLOTS.missingdata_by_store[["iTunes"]]
.o(ggsave.out(P.Spotify))
.o(ggsave.out(P.iTunes))
