mtt/R/create_eventlogs.R

80 lines
3.0 KiB
R
Raw Normal View History

2023-09-20 16:16:47 +02:00
#' Creating log events from raw log files.
#'
#' Creating event logs from a data frame of raw log files from a
#' Multi-Touch-Table at the IWM.
#'
#' @param data Data frame of raw log files created with `parse_logfiles()`.
#' See `?parse_logfiles` for more details.
#' @return Data frame.
#' @export
#' @examples
#' # tbd
create_eventlogs <- function(data) {
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")))
# Add trace variable #####################################################
cat("########## Adding trace variable... ##########", "\n")
dat1 <- add_trace(dat)
# Close events
cat("########## Closing events... ##########", "\n")
c1 <- close_events(dat1, "move")
cat("## --> move events closed.", "\n")
c2 <- close_events(dat1, "flipCard")
cat("## --> flipCard events closed.", "\n")
c3 <- close_events(dat1, "openTopic")
cat("## --> openTopic events closed.", "\n")
c4 <- close_events(dat1, "openPopup")
cat("## --> openPopup events closed.", "\n")
dat2 <- rbind(c1, c2, c3, c4)
dat2 <- dat2[order(dat2$fileId, dat2$date.start, dat2$timeMs.start), ]
2023-09-20 16:16:47 +02:00
# Remove all events that do not have a `date.start`
d1 <- nrow(dat2)
dat2 <- dat2[!is.na(dat2$date.start), ]
d2 <- nrow(dat2)
if(d1 > d2) {
warning(paste0(d1-d2, " lines that do not contain a start event have been removed. This can happen when events span over more than one log file.\n"))
}
rownames(dat2) <- NULL
# Add case variable ######################################################
cat("########## Adding case and eventId variables... ##########", "\n")
dat3 <- add_case(dat2)
# Add event ID ###########################################################
dat3$eventId <- seq_len(nrow(dat3))
dat3 <- dat3[, c("fileId", "eventId", "case",
2023-09-20 16:16:47 +02:00
"trace", "glossar", "event", "artwork",
"date.start", "date.stop", "timeMs.start",
"timeMs.stop", "duration", "topicNumber", "popup",
"x.start", "y.start", "x.stop", "y.stop",
"distance", "scale.start", "scale.stop",
"scaleSize", "rotation.start", "rotation.stop",
"rotationDegree")]
# Add trace for move events ##############################################
cat("\n########## Adding trace variable for move events... ##########", "\n")
dat4 <- add_trace_moves(dat3)
# Add topics: file names and topics ######################################
cat("########## Adding information about topics... ##########", "\n")
artworks <- unique(dat4$artwork)
# remove artworks without XML information
artworks <- artworks[!artworks %in% c("504", "505")]
topics <- extract_topics(artworks, pattern = paste0(artworks, ".xml"),
path = "../data/ContentEyevisit/eyevisit_cards_light/")
dat5 <- add_topic(dat4, topics = topics)
dat5
}