Fix bug in iOS battery (different status compared to Android)

replace/8cdbd7cd9c67135625a00c2fc861797c561191c1
JulioV 2019-12-05 16:24:05 -05:00
parent a4e39ad451
commit 6a79fbe1e8
2 changed files with 15 additions and 5 deletions

View File

@ -24,7 +24,7 @@ rule call_metrics:
rule battery_deltas:
input:
"data/raw/{pid}/battery_with_datetime.csv"
"data/raw/{pid}/battery_with_datetime_unified.csv"
output:
"data/processed/{pid}/battery_deltas.csv"
script:

View File

@ -2,6 +2,12 @@ source("packrat/init.R")
library(dplyr)
unify_ios_battery <- function(ios_battery){
ios_battery <- ios_battery %>%
mutate(battery_status = replace(battery_status, battery_status == 3, 5),
battery_status = replace(battery_status, battery_status == 1, 3))
}
unify_ios_calls <- function(ios_calls){
# Androids call types 1=incoming, 2=outgoing, 3=missed
# iOS' call status 1=incoming, 2=connected, 3=dialing, 4=disconnected
@ -61,10 +67,14 @@ sensor <- snakemake@params[["sensor"]]
platform <- readLines(participant_info, n=2)[[2]]
if(sensor == "calls"){
if(platform == "android"){
write.csv(sensor_data, snakemake@output[[1]], row.names = FALSE)
} else if(platform == "ios"){
if(platform == "ios"){
sensor_data = unify_ios_calls(sensor_data)
write.csv(sensor_data, snakemake@output[[1]], row.names = FALSE)
}
# android calls remain unchanged
} else if(sensor == "battery"){
if(platform == "ios"){
sensor_data = unify_ios_battery(sensor_data)
}
# android battery remains unchanged
}
write.csv(sensor_data, snakemake@output[[1]], row.names = FALSE)