rm(list=ls())
library(data.table)
library(pbapply)
library(stringi)
#../input/train_1/event000001000*.csv
muet<-invisible(pblapply(list.files(path = "../input/",pattern = "*.csv"),function(xXx) assign(gsub(x = xXx,pattern=".csv",replacement = ""),fread(file = paste0("../input/",xXx)),envir = .GlobalEnv)));rm(muet)
SeekNLoadEvents<-function(seekpath=NULL){
  tempo_env<-environment()
  seekpath<-paste0(seekpath,.Platform$file.sep)
  all_files<-list.files(path = seekpath,pattern = ".csv")
  event_numbers<-unique(gsub(x=all_files,pattern = "[aA-zZ]|[[:punct:]]",replacement = "",perl = TRUE))
  #now loop for each event loop and import the datasets :)
  seek_list<-pblapply(event_numbers[seq_along(event_numbers)],function(kKk){  
    seekme<-grep(x=all_files,pattern = paste0("event",kKk,"-"),value = TRUE)
    tempo_names<-gsub(x=seekme,pattern = "[0-9]|event|csv|[[:punct:]]","")#"cells" "hits" et.c ...
    tempo<-list()
    for(idx in 1:length(seekme)){
      assign(tempo_names[idx],fread(file = paste0(seekpath,seekme[idx])),envir = tempo_env)
    }
    dyn_list<-lapply(tempo_names,function(ddd) get(ddd,envir = tempo_env))
    names(dyn_list)<-tempo_names
    return(dyn_list)#<- seems dynamic
  })
  names(seek_list)<-paste0("event",event_numbers)
  return(seek_list)
}
#Create list of the test events
test_list<-SeekNLoadEvents(seekpath = "../input/test/")
#idem for the train_100
train_100_events_list<-SeekNLoadEvents(seekpath = "../input/train_100_events/")
