Added removing of fragmented traces; needs more testing

This commit is contained in:
Nora Wickelmaier 2023-10-22 16:52:46 +02:00
parent daadb7a691
commit 8bfa694cc9
1 changed files with 21 additions and 4 deletions

View File

@ -22,7 +22,7 @@ create_eventlogs <- function(data, xmlpath, case_cutoff = 20, rm_nochange_moves
data$date <- as.POSIXct(data$date)
}
data$glossar <- ifelse(data$artwork == "glossar", 1, 0)
# Remove irrelevant events
dat <- subset(data, !(data$event %in% c("Start Application",
"Show Application")))
@ -54,7 +54,7 @@ create_eventlogs <- function(data, xmlpath, case_cutoff = 20, rm_nochange_moves
c4 <- close_events(dat1, "openPopup", rm_nochange_moves = rm_nochange_moves)
cat("## --> openPopup events closed.", "\n")
dat2 <- rbind(c1, c2, c3, c4)
dat2 <- dat2[order(dat2$fileId.start, dat2$date.start, dat2$timeMs.start), ]
# Remove all events that do not have a `date.start`
@ -70,7 +70,7 @@ create_eventlogs <- function(data, xmlpath, case_cutoff = 20, rm_nochange_moves
# Add case variable ######################################################
cat("\n########## Adding case and eventId variables... ##########", "\n\n")
dat3 <- add_case(dat2, cutoff = case_cutoff)
# Add event ID ###########################################################
dat3$eventId <- seq_len(nrow(dat3))
dat3 <- dat3[, c("folder", "eventId", "case", "trace", "glossar",
@ -85,6 +85,23 @@ create_eventlogs <- function(data, xmlpath, case_cutoff = 20, rm_nochange_moves
cat("\n\n########## Adding trace variable for move events... ##########", "\n")
dat4 <- add_trace_moves(dat3)
dat4
# Remove fragmented traces ###############################################
tab <- xtabs( ~ trace + event, dat4)
fragments <- NULL
for (i in seq_len(nrow(tab))) {
if (tab[i, "openPopup"] != 0 & tab[i, "flipCard"] == 0) {
fragments <- c(fragments, rownames(tab)[i])
} else if (tab[i, "openTopic"] != 0 & tab[i, "flipCard"] == 0) {
fragments <- c(fragments, rownames(tab)[i])
} else if (tab[i, "openPopup"] != 0 & tab[i, "openTopic"] == 0) {
fragments <- c(fragments, rownames(tab)[i])
}
}
dat5 <- dat4[!dat4$trace %in% fragments, ]
# TODO: Should be tested more thouroughly on complete data set
dat5
}