Add battery deltas

replace/fe4597411b6783071d2d174d66256fff76105244
JulioV 2019-11-05 10:47:55 -05:00
parent c177b393b9
commit 8030624e0a
4 changed files with 32 additions and 2 deletions

View File

@ -7,6 +7,7 @@ rule all:
input:
expand("data/raw/{pid}/{sensor}_raw.csv", pid=config["PIDS"], sensor=config["SENSORS"]),
expand("data/raw/{pid}/{sensor}_with_datetime.csv", pid=config["PIDS"], sensor=config["SENSORS"]),
expand("data/processed/{pid}/battery_deltas.csv", pid=config["PIDS"]),
expand("data/processed/{pid}/com_sms_{sms_type}_{day_segment}_{metric}.csv",
pid=config["PIDS"],
sms_type = config["COM_SMS"]["SMS_TYPES"],

View File

@ -1,5 +1,5 @@
# Valid database table names
SENSORS: [messages, calls]
SENSORS: [messages, calls, battery]
# Participants to include in the analysis
# You must create a file for each participant

View File

@ -20,4 +20,12 @@ rule communication_call_metrics:
output:
"data/processed/{pid}/com_call_{call_type}_{day_segment}_{metric}.csv"
script:
"../src/features/communication_call_metrics.R"
"../src/features/communication_call_metrics.R"
rule battery_deltas:
input:
"data/raw/{pid}/battery_with_datetime.csv"
output:
"data/processed/{pid}/battery_deltas.csv"
script:
"../src/features/battery_deltas.R"

View File

@ -0,0 +1,21 @@
source("packrat/init.R")
library("tidyverse")
battery <- read.csv(snakemake@input[[1]])
consumption <- battery %>%
mutate(group = ifelse(lag(battery_status) != battery_status, 1, 0) %>% coalesce(0),
group_id = cumsum(group) + 1) %>%
filter(battery_status == 3) %>%
group_by(group_id) %>%
summarize(battery_diff = first(battery_level) - last(battery_level),
time_diff = (last(timestamp) - first(timestamp)) / (1000 * 60 * 60),
local_start_date_time = first(local_date_time),
local_end_date_time = last(local_date_time),
local_start_date = first(local_date),
local_end_date = last(local_date)) %>%
select(-group_id) %>%
filter(time_diff > 0.1) # Avoids including quick discharge cycles
write.csv(consumption, snakemake@output[[1]])