2020-02-10 22:45:34 +01:00
|
|
|
source("packrat/init.R")
|
|
|
|
|
|
|
|
library(RMySQL)
|
|
|
|
|
|
|
|
group <- snakemake@params[["group"]]
|
|
|
|
ignored_device_ids <- snakemake@params[["ignored_device_ids"]]
|
2020-02-18 22:41:10 +01:00
|
|
|
timezone <- snakemake@params[["timezone"]]
|
2020-02-10 22:45:34 +01:00
|
|
|
rmysql.settingsfile <- "./.env"
|
|
|
|
|
|
|
|
stopDB <- dbConnect(MySQL(), default.file = rmysql.settingsfile, group = group)
|
2020-02-18 22:41:10 +01:00
|
|
|
query <- "SELECT device_id, brand, label, timestamp FROM aware_device order by timestamp asc"
|
2020-02-10 22:45:34 +01:00
|
|
|
participants <- dbGetQuery(stopDB, query)
|
|
|
|
pids <- c()
|
|
|
|
|
2020-02-18 22:41:10 +01:00
|
|
|
end_date <- format(Sys.Date(), "%Y/%m/%d")
|
|
|
|
|
2020-02-10 22:45:34 +01:00
|
|
|
for(id in 1:nrow(participants)){
|
|
|
|
device_id <- participants$device_id[[id]]
|
|
|
|
brand <- ifelse(participants$brand[[id]] == "iPhone", "ios", "android")
|
2020-02-18 22:41:10 +01:00
|
|
|
label <- ifelse(participants$label[[id]] == "", "EMPTY_LABEL", participants$label[[id]])
|
2020-03-03 17:08:57 +01:00
|
|
|
label <- iconv(label, from = "UTF-8", to = "UTF-8", sub='')
|
2020-02-18 22:41:10 +01:00
|
|
|
start_date <- format(as.POSIXct(participants$timestamp[[id]] / 1000, origin = "1970-01-01", tz = timezone), "%Y/%m/%d")
|
2020-02-10 22:45:34 +01:00
|
|
|
if(!(device_id %in% ignored_device_ids)){
|
|
|
|
pid <- paste0("p", ifelse(id < 10, paste0("0", id), id))
|
|
|
|
pids <- append(pids, pid)
|
|
|
|
file_connection <- file(paste0("./data/external/", pid))
|
2020-02-18 22:41:10 +01:00
|
|
|
writeLines(c(device_id, brand, label, paste0(start_date, ",", end_date)), file_connection)
|
2020-02-10 22:45:34 +01:00
|
|
|
close(file_connection)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
file_lines <-readLines("./config.yaml")
|
|
|
|
for (i in 1:length(file_lines)){
|
|
|
|
if(startsWith(file_lines[i], "PIDS:")){
|
|
|
|
file_lines[i] <- paste0("PIDS: [", paste(pids, collapse = ", "), "]")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
writeLines(file_lines, con = "./config.yaml")
|