Add switch to barnet_locations.R to use all, all except fused or resample fused locations

replace/a30e001b6f59f6d288a1724833159e7955d30c44
JulioV 2019-12-09 19:15:10 -05:00
parent 0ba88203f4
commit cb2ee1ec82
3 changed files with 18 additions and 3 deletions

View File

@ -52,7 +52,8 @@ RESAMPLE_FUSED_LOCATION:
TIMEZONE: *timezone TIMEZONE: *timezone
BARNETT_LOCATION: BARNETT_LOCATION:
ACCURACY_LIMIT: 51 # filters location coordinates with an accuracy higher than this LOCATIONS_TO_USE: ALL # ALL_EXCEPT_FUSED, RESAMPLE_FUSED
ACCURACY_LIMIT: 51 # meters, drops location coordinates with an accuracy higher than this. This number means there's a 68% probability the true location is within this radius
TIMEZONE: *timezone TIMEZONE: *timezone
BLUETOOTH: BLUETOOTH:

View File

@ -48,8 +48,10 @@ rule google_activity_recognition_deltas:
rule location_barnett_metrics: rule location_barnett_metrics:
input: input:
"data/raw/{pid}/locations_with_datetime.csv" raw = "data/raw/{pid}/locations_raw.csv",
fused = rules.resample_fused_location.output
params: params:
locations_to_use = config["BARNETT_LOCATION"]["LOCATIONS_TO_USE"],
accuracy_limit = config["BARNETT_LOCATION"]["ACCURACY_LIMIT"], accuracy_limit = config["BARNETT_LOCATION"]["ACCURACY_LIMIT"],
timezone = config["BARNETT_LOCATION"]["TIMEZONE"] timezone = config["BARNETT_LOCATION"]["TIMEZONE"]
output: output:

View File

@ -26,12 +26,24 @@ write_empty_file <- function(file_path){
file.sources = list.files(c("src/features/location_barnett"), pattern="*.R$", full.names=TRUE, ignore.case=TRUE) file.sources = list.files(c("src/features/location_barnett"), pattern="*.R$", full.names=TRUE, ignore.case=TRUE)
sapply(file.sources,source,.GlobalEnv) sapply(file.sources,source,.GlobalEnv)
locations_to_use <- snakemake@params[["locations_to_use"]]
accuracy_limit <- snakemake@params[["accuracy_limit"]] accuracy_limit <- snakemake@params[["accuracy_limit"]]
timezone <- snakemake@params[["timezone"]] timezone <- snakemake@params[["timezone"]]
location <- read.csv(snakemake@input[[1]], stringsAsFactors = F) %>% # By deafult we use all raw locations: fused without resampling and not fused (gps, network)
location <- read.csv(snakemake@input[["raw"]], stringsAsFactors = F) %>%
select(timestamp, latitude = double_latitude, longitude = double_longitude, altitude = double_altitude, accuracy) select(timestamp, latitude = double_latitude, longitude = double_longitude, altitude = double_altitude, accuracy)
if(locations_to_use == "ALL_EXCEPT_FUSED"){
location <- location %>% filter(provider != "fused")
} else if (locations_to_use == "RESAMPLE_FUSED"){
location <- read.csv(snakemake@input[["fused"]], stringsAsFactors = F) %>%
select(timestamp, latitude = double_latitude, longitude = double_longitude, altitude = double_altitude, accuracy)
} else if (locations_to_use != "ALL"){
print("Unkown filter, provide one of the following three: ALL, ALL_EXCEPT_FUSED, or RESAMPLE_FUSED")
quit(save = "no", status = 1, runLast = FALSE)
}
if (nrow(location) > 1){ if (nrow(location) > 1){
features <- MobilityFeatures(location, ACCURACY_LIM = accuracy_limit, tz = timezone) features <- MobilityFeatures(location, ACCURACY_LIM = accuracy_limit, tz = timezone)
if(is.null(features)){ if(is.null(features)){