Changed add_case; now based on min and max of paths
This commit is contained in:
parent
8233b151d9
commit
b595c261c5
32
R/add_case.R
32
R/add_case.R
@ -5,14 +5,34 @@
|
|||||||
add_case <- function(data, cutoff = 20) {
|
add_case <- function(data, cutoff = 20) {
|
||||||
# TODO: What is the best choice for the cutoff here?
|
# TODO: What is the best choice for the cutoff here?
|
||||||
|
|
||||||
data$timediff <- -c(utils::head(data$date.stop, nrow(data) - 1) - data$date.start[-1], 0)
|
pbapply::pboptions(style = 3, char = "=")
|
||||||
data$timeindex <- ifelse(data$timediff <= cutoff, 0, 1)
|
|
||||||
case_change <- diff(c(0, c(which(data$timeindex == 1), nrow(data))))
|
|
||||||
data$case <- rep(seq_along(case_change), case_change)
|
|
||||||
|
|
||||||
data$timediff <- NULL
|
dat_split <- split(data, ~ path)
|
||||||
data$timeindex <- NULL
|
|
||||||
|
|
||||||
|
time_minmax <- function(subdata) {
|
||||||
|
subdata$min_time <- min(subdata$date.start)
|
||||||
|
subdata$max_time <- ifelse(all(is.na(subdata$date.stop)), NA,
|
||||||
|
max(subdata$date.stop, na.rm = TRUE))
|
||||||
|
subdata
|
||||||
|
}
|
||||||
|
|
||||||
|
dat_list <- pbapply::pblapply(dat_split, time_minmax)
|
||||||
|
dat_minmax <- dplyr::bind_rows(dat_list)
|
||||||
|
|
||||||
|
dat_case <- dat_minmax[!duplicated(dat_minmax$path), ]
|
||||||
|
|
||||||
|
dat_case$timediff <- -c(difftime(utils::head(dat_case$max_time, nrow(dat_case) - 1),
|
||||||
|
dat_case$min_time[-1], units = "secs"), 0)
|
||||||
|
|
||||||
|
dat_case$timeindex <- ifelse(dat_case$timediff <= cutoff, 0, 1)
|
||||||
|
case_change <- diff(c(0, c(which(dat_case$timeindex == 1), nrow(dat_case))))
|
||||||
|
dat_case$case <- rep(seq_along(case_change), case_change)
|
||||||
|
|
||||||
|
npath <- table(data$path)
|
||||||
|
data <- data[order(data$path), ]
|
||||||
|
data$case <- rep(dat_case$case, npath)
|
||||||
|
|
||||||
|
data <- data[order(data$fileId.start, data$date.start, data$timeMs.start), ]
|
||||||
data
|
data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ create_eventlogs <- function(data, xmlpath = NULL, case_cutoff = 20,
|
|||||||
|
|
||||||
# Add path for move events ##############################################
|
# Add path for move events ##############################################
|
||||||
cat("\n\n########## Adding path variable for move events... ##########", "\n")
|
cat("\n\n########## Adding path variable for move events... ##########", "\n")
|
||||||
dat3 <- add_path_moves(dat2)
|
dat3 <- add_path_moves(dat2, cutoff = case_cutoff)
|
||||||
|
|
||||||
# Add case variable ######################################################
|
# Add case variable ######################################################
|
||||||
cat("\n########## Adding case variable... ##########", "\n\n")
|
cat("\n########## Adding case variable... ##########", "\n\n")
|
||||||
|
Loading…
Reference in New Issue
Block a user