## Visualize Station Parameters Over Time

## Jeff Hebert
## 9/9/2016


library(data.table)

max_rows <- 100000

# Load just the data we need for time based visualization
cat("Reading just the data we need \n")
dt_numeric <- fread("../input/train_numeric.csv", nrows = max_rows, showProgress = FALSE, data.table = FALSE)
dt_date <- fread("../input/train_date.csv", nrows = max_rows, showProgress = FALSE, data.table = FALSE)
response <- dt_numeric$Response

station_list <- unique(substr(setdiff(names(dt_date), "Id"), 1, 5))


plot_station <- function(station_id, num_idx = 1){
  station_date <- dt_date[, grep(station_id, names(dt_date))[1]]
  station_parms <- names(dt_numeric)[grep(station_id, names(dt_numeric))]
  parameter <- station_parms[num_idx]
  plot(station_date, dt_numeric[,parameter], col = response + 1,
       main = paste("Station ", station_id, " parameter ", parameter, " variation over time"),
       xlab = "Station timestamp",
       ylab = parameter,
       pch = ifelse(response == 0, ".", "*"))
  legend("bottomright", c("Pass", "Fail"), pch = c(".","*"), col = c(1,2))
}



## Plot all parameters for L0_S0

for(i in 1:12){
  plot_station(station_list[1], num_idx = i)
}



## Plot one random parameter for each station

set.seed(111)
for(i in station_list){
  parm_count <- length(grep(i, names(dt_numeric)))
  parm <- sample(parm_count, 1)
  plot_station(i, num_idx = parm)
}

