Add label and dates for external files
parent
edcd3da8f9
commit
76888b412d
|
@ -1,7 +1,8 @@
|
||||||
rule download_participants:
|
rule download_participants:
|
||||||
params:
|
params:
|
||||||
group = config["DOWNLOAD_PARTICIPANTS"]["GROUP"],
|
group = config["DOWNLOAD_PARTICIPANTS"]["GROUP"],
|
||||||
ignored_device_ids = config["DOWNLOAD_PARTICIPANTS"]["IGNORED_DEVICE_IDS"]
|
ignored_device_ids = config["DOWNLOAD_PARTICIPANTS"]["IGNORED_DEVICE_IDS"],
|
||||||
|
timezone = config["TIMEZONE"]
|
||||||
script:
|
script:
|
||||||
"../src/data/download_participants.R"
|
"../src/data/download_participants.R"
|
||||||
|
|
||||||
|
|
|
@ -4,21 +4,26 @@ library(RMySQL)
|
||||||
|
|
||||||
group <- snakemake@params[["group"]]
|
group <- snakemake@params[["group"]]
|
||||||
ignored_device_ids <- snakemake@params[["ignored_device_ids"]]
|
ignored_device_ids <- snakemake@params[["ignored_device_ids"]]
|
||||||
|
timezone <- snakemake@params[["timezone"]]
|
||||||
rmysql.settingsfile <- "./.env"
|
rmysql.settingsfile <- "./.env"
|
||||||
|
|
||||||
stopDB <- dbConnect(MySQL(), default.file = rmysql.settingsfile, group = group)
|
stopDB <- dbConnect(MySQL(), default.file = rmysql.settingsfile, group = group)
|
||||||
query <- paste0("SELECT device_id, brand FROM aware_device order by timestamp asc")
|
query <- "SELECT device_id, brand, label, timestamp FROM aware_device order by timestamp asc"
|
||||||
participants <- dbGetQuery(stopDB, query)
|
participants <- dbGetQuery(stopDB, query)
|
||||||
pids <- c()
|
pids <- c()
|
||||||
|
|
||||||
|
end_date <- format(Sys.Date(), "%Y/%m/%d")
|
||||||
|
|
||||||
for(id in 1:nrow(participants)){
|
for(id in 1:nrow(participants)){
|
||||||
device_id <- participants$device_id[[id]]
|
device_id <- participants$device_id[[id]]
|
||||||
brand <- ifelse(participants$brand[[id]] == "iPhone", "ios", "android")
|
brand <- ifelse(participants$brand[[id]] == "iPhone", "ios", "android")
|
||||||
|
label <- ifelse(participants$label[[id]] == "", "EMPTY_LABEL", participants$label[[id]])
|
||||||
|
start_date <- format(as.POSIXct(participants$timestamp[[id]] / 1000, origin = "1970-01-01", tz = timezone), "%Y/%m/%d")
|
||||||
if(!(device_id %in% ignored_device_ids)){
|
if(!(device_id %in% ignored_device_ids)){
|
||||||
pid <- paste0("p", ifelse(id < 10, paste0("0", id), id))
|
pid <- paste0("p", ifelse(id < 10, paste0("0", id), id))
|
||||||
pids <- append(pids, pid)
|
pids <- append(pids, pid)
|
||||||
file_connection <- file(paste0("./data/external/", pid))
|
file_connection <- file(paste0("./data/external/", pid))
|
||||||
writeLines(c(device_id, brand), file_connection)
|
writeLines(c(device_id, brand, label, paste0(start_date, ",", end_date)), file_connection)
|
||||||
close(file_connection)
|
close(file_connection)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue