Add google activity recognition deltas
parent
037420457d
commit
e6d418cd14
|
@ -9,6 +9,7 @@ rule all:
|
|||
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}/screen_deltas.csv", pid=config["PIDS"]),
|
||||
expand("data/processed/{pid}/google_activity_recognition_deltas.csv", pid=config["PIDS"]),
|
||||
expand("data/interim/{pid}/phone_valid_sensed_days.csv", pid=config["PIDS"]),
|
||||
expand("data/processed/{pid}/sms_{sms_type}_{day_segment}.csv",
|
||||
pid=config["PIDS"],
|
||||
|
|
|
@ -38,6 +38,14 @@ rule screen_deltas:
|
|||
script:
|
||||
"../src/features/screen_deltas.R"
|
||||
|
||||
rule google_activity_recognition_deltas:
|
||||
input:
|
||||
"data/raw/{pid}/plugin_google_activity_recognition_with_datetime.csv"
|
||||
output:
|
||||
"data/processed/{pid}/google_activity_recognition_deltas.csv"
|
||||
script:
|
||||
"../src/features/google_activity_recognition_deltas.R"
|
||||
|
||||
rule location_barnett_metrics:
|
||||
input:
|
||||
"data/raw/{pid}/locations_with_datetime.csv"
|
||||
|
@ -62,7 +70,8 @@ rule bluetooth_metrics:
|
|||
|
||||
rule activity_metrics:
|
||||
input:
|
||||
"data/raw/{pid}/plugin_google_activity_recognition_with_datetime.csv"
|
||||
"data/raw/{pid}/plugin_google_activity_recognition_with_datetime.csv",
|
||||
"data/raw/{pid}/plugin_google_activity_recognition_deltas.csv"
|
||||
params:
|
||||
segment = "{day_segment}",
|
||||
metrics = config["GOOGLE_ACTIVITY_RECOGNITION"]["METRICS"]
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
source("packrat/init.R")
|
||||
|
||||
library("tidyverse")
|
||||
|
||||
gar <- read.csv(snakemake@input[[1]])
|
||||
|
||||
if(nrow(gar) > 0){
|
||||
activity_episodes <-
|
||||
gar %>%
|
||||
mutate(activity_episode = cumsum(c(1, head(activity_type, -1) != tail(activity_type, -1)))) %>%
|
||||
group_by(activity_episode) %>%
|
||||
filter(n() > 1) %>%
|
||||
summarize(episode = first(activity_name),
|
||||
time_diff = (last(timestamp) - first(timestamp)) / (1000 * 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),
|
||||
local_start_day_segment = first(local_day_segment),
|
||||
local_end_day_segment = last(local_day_segment)) %>%
|
||||
select(-activity_episode)
|
||||
} else {
|
||||
activity_episodes <- data.frame(episode = character(),
|
||||
time_diff = numeric(),
|
||||
local_start_date_time = character(),
|
||||
local_end_date_time = character(),
|
||||
local_start_date = character(),
|
||||
local_end_date = character(),
|
||||
local_start_day_segment = character(),
|
||||
local_end_day_segment = character())
|
||||
}
|
||||
|
||||
write.csv(activity_episodes, snakemake@output[[1]], row.names = FALSE)
|
Loading…
Reference in New Issue