rapids/src/data/phone_valid_sensed_days.R

21 lines
858 B
R
Raw Normal View History

2020-05-02 01:46:04 +02:00
source("renv/activate.R")
2020-07-09 19:01:50 +02:00
library("dplyr")
library("tidyr")
2019-11-05 18:34:22 +01:00
2020-07-09 19:01:50 +02:00
phone_sensed_bins <- read.csv(snakemake@input[["phone_sensed_bins"]])
min_valid_hours_per_day <- as.integer(snakemake@params[["min_valid_hours_per_day"]])
min_valid_bins_per_hour <- as.integer(snakemake@params[["min_valid_bins_per_hour"]])
2019-11-05 18:34:22 +01:00
output_file <- snakemake@output[[1]]
2020-07-09 19:01:50 +02:00
phone_valid_sensed_days <- phone_sensed_bins %>%
pivot_longer(cols = -local_date, names_to = c("hour", "bin"), names_sep = "_") %>%
filter(value > 0) %>%
group_by(local_date, hour) %>%
summarise(valid_bins = n()) %>%
filter(valid_bins >= min_valid_bins_per_hour) %>%
group_by(local_date) %>%
summarise(valid_sensed_hours = n()) %>%
mutate(is_valid_sensed_day = ifelse(valid_sensed_hours >= min_valid_hours_per_day, TRUE, FALSE))
2019-11-05 18:34:22 +01:00
write.csv(phone_valid_sensed_days, output_file, row.names = FALSE)