Compare commits
No commits in common. "8bedadd18e75ff7d991b31cf5d1e6b788130f011" and "c41ba718e91c346004d58741b73e7919356cb6d6" have entirely different histories.
8bedadd18e
...
c41ba718e9
@ -1,55 +1,37 @@
|
||||
###########################################################################
|
||||
add_path_items <- function(subdata) {
|
||||
subdata_glossar <- subdata[subdata$item == "glossar", ]
|
||||
subdata_glossar$path <- NA
|
||||
|
||||
last_event <- subdata$event[1]
|
||||
items <- unique(subdata$item)[unique(subdata$item) != "glossar"]
|
||||
n <- 1 # count items for progress
|
||||
|
||||
path_per_item <- function(subdata, item) {
|
||||
pb <- utils::txtProgressBar(min = 0, max = nrow(subdata), initial = NA,
|
||||
style = 3)
|
||||
|
||||
subsubdata <- subdata[subdata$item == item, ]
|
||||
last_event <- subsubdata$event[1]
|
||||
subsubdata$path <- NA
|
||||
for (i in 1:nrow(subsubdata)) {
|
||||
if (last_event == "Show Info") {
|
||||
subsubdata$path[i] <- i
|
||||
for (item in items) {
|
||||
|
||||
cat("\n\nAdding path variable for item", item,
|
||||
paste0("(", n, "/", length(items), ")"), "\n")
|
||||
|
||||
for (i in 1:nrow(subdata)) {
|
||||
if (last_event == "Show Info" & subdata$item[i] == item) {
|
||||
subdata$path[i] <- i
|
||||
j <- i
|
||||
status <- "path_started"
|
||||
} else if (last_event == "Show Front") {
|
||||
subsubdata$path[i] <- j
|
||||
status <- "path_ended"
|
||||
} else if (last_event == "Show Front" & subdata$item[i] == item) {
|
||||
subdata$path[i] <- j
|
||||
} else if (!(last_event %in% c("Show Info", "Show Front")) &
|
||||
status == "path_started") {
|
||||
subsubdata$path[i] <- j
|
||||
subdata$item[i] == item) {
|
||||
subdata$path[i] <- j
|
||||
}
|
||||
if (i <= nrow(subsubdata)) {
|
||||
last_event <- subsubdata$event[i + 1]
|
||||
if (i <= nrow(subdata)) {
|
||||
last_event <- subdata$event[i + 1]
|
||||
}
|
||||
utils::setTxtProgressBar(pb, i)
|
||||
}
|
||||
subsubdata$path <- ifelse(is.na(subsubdata$path), NA,
|
||||
paste0(item, "_", subsubdata$path))
|
||||
subsubdata
|
||||
n <- n + 1
|
||||
}
|
||||
|
||||
subdata_list <- pbapply::pblapply(items, path_per_item, subdata = subdata)
|
||||
subdata <- dplyr::bind_rows(subdata_list)
|
||||
|
||||
# Remove popup events that occur after item has been closed
|
||||
subdata <- subdata[!is.na(subdata$path), ]
|
||||
|
||||
# Add glossar events back in
|
||||
subdata <- rbind(subdata, subdata_glossar)
|
||||
|
||||
# Bring back in time order
|
||||
subdata <- subdata[order(subdata$fileId, subdata$date), ]
|
||||
|
||||
# Make path a consecutive number
|
||||
subdata$path <- as.numeric(factor(subdata$path, levels = unique(subdata$path)))
|
||||
rownames(subdata) <- NULL
|
||||
subdata
|
||||
}
|
||||
|
||||
|
||||
###########################################################################
|
||||
add_path_glossar <- function(subdata, xmlpath) {
|
||||
|
||||
@ -57,7 +39,7 @@ add_path_glossar <- function(subdata, xmlpath) {
|
||||
style = 3)
|
||||
|
||||
cat("\n\n########## Creating glossar dictionary ##########", "\n")
|
||||
items <- unique(subdata$item[subdata$item != "glossar"])
|
||||
items <- unique(subdata$item[subdata$item != "glossar"])
|
||||
glossar_files <- unique(subdata[subdata$item == "glossar", "popup"])
|
||||
lut <- create_glossardict(items, glossar_files, xmlpath = xmlpath)
|
||||
inside <- glossar_files[glossar_files %in%
|
||||
@ -156,6 +138,8 @@ add_path_moves <- function(data) {
|
||||
out <- out[order(out$fileId.start, out$date.start, out$timeMs.start), ]
|
||||
rownames(out) <- NULL
|
||||
|
||||
# Make path a consecutive number
|
||||
out$path <- as.numeric(factor(out$path, levels = unique(out$path)))
|
||||
out
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user