Add battery deltas
parent
c177b393b9
commit
8030624e0a
|
@ -7,6 +7,7 @@ rule all:
|
||||||
input:
|
input:
|
||||||
expand("data/raw/{pid}/{sensor}_raw.csv", pid=config["PIDS"], sensor=config["SENSORS"]),
|
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/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",
|
expand("data/processed/{pid}/com_sms_{sms_type}_{day_segment}_{metric}.csv",
|
||||||
pid=config["PIDS"],
|
pid=config["PIDS"],
|
||||||
sms_type = config["COM_SMS"]["SMS_TYPES"],
|
sms_type = config["COM_SMS"]["SMS_TYPES"],
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
# Valid database table names
|
# Valid database table names
|
||||||
SENSORS: [messages, calls]
|
SENSORS: [messages, calls, battery]
|
||||||
|
|
||||||
# Participants to include in the analysis
|
# Participants to include in the analysis
|
||||||
# You must create a file for each participant
|
# You must create a file for each participant
|
||||||
|
|
|
@ -21,3 +21,11 @@ rule communication_call_metrics:
|
||||||
"data/processed/{pid}/com_call_{call_type}_{day_segment}_{metric}.csv"
|
"data/processed/{pid}/com_call_{call_type}_{day_segment}_{metric}.csv"
|
||||||
script:
|
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"
|
|
@ -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]])
|
Loading…
Reference in New Issue