mtt_haum/code/check_traces.R

102 lines
3.5 KiB
R

# setwd("C:/Users/nwickelmaier/Nextcloud/Documents/MDS/2023ss/60100_master_thesis/code")
# Read data
dat <- read.table("../data/haum/event_logfiles_metadata_2023-09-23_01-31-30.csv",
sep = ";", header = TRUE)
# dat <- read.table("../data/haum/event_logfiles_small_metadata_2023-09-25_09-56-34.csv",
# sep = ";", header = TRUE)
dat$date <- as.Date(dat$date)
dat$date.start <- as.POSIXct(dat$date.start)
dat$date.stop <- as.POSIXct(dat$date.stop)
dat$artwork <- sprintf("%03d", dat$artwork)
library(bupaverse)
names(dat)[names(dat) %in% c("date.start", "date.stop")] <- c("start", "complete")
create_pdf <- function(trace, folder = "../figures/processmaps/") {
alog <- activitylog(dat[which(dat$trace == trace), ],
case_id = "trace",
activity_id = "event",
resource_id = "artwork",
timestamps = c("start", "complete"))
map <- process_map(alog)
g <- DiagrammeR::grViz(map$x$diagram) |> DiagrammeRsvg::export_svg() |> charToRaw()
rsvg::rsvg_pdf(g, paste0(folder, trace, ".pdf"))
}
find_trace <- function(trace) {
alog <- activitylog(dat[which(dat$trace == trace), ],
case_id = "trace",
activity_id = "event",
resource_id = "artwork",
timestamps = c("start", "complete"))
map <- process_map(alog)
d <- strsplit(map$x$diagram, "\n")[[1]]
o <- grep("^.{6}[[]label", d, value = TRUE)
p <- grep("^.{1}[1-6].->", d, value = TRUE)
num_ot <- gsub("^.{3}([1-6]).*", "\\1", grep("openTopic", o, value = TRUE))
num_op <- gsub("^.{3}([1-6]).*", "\\1", grep("openPopup", o, value = TRUE))
rel_path <- grep("^.{1}[2].->.[1-6]", p, value = TRUE)
rel_num <- gsub("^.{1}[2].->.([1-6]).*" , "\\1", rel_path)
num_fc <- gsub("^.{3}([1-6]).*", "\\1", grep("flipCard", o, value = TRUE))
if (length(num_fc) > 0) {
rel_path_fc <- grep(paste0("^.{1}[", num_fc, "].->.[1-6]"), p, value = TRUE)
rel_num_fc <- gsub(paste0("^.{1}[", num_fc, "].->.([1-6]).*"), "\\1", rel_path_fc)
if (any(c(num_ot, num_op) %in% rel_num) | any(num_op == rel_num_fc)) {
trace
}
} else {
if (any(c(num_ot, num_op) %in% rel_num)) {
trace
}
}
}
ctrace <- pbapply::pbsapply(unique(dat$trace), find_trace)
unlist(ctrace)
length(unlist(ctrace))
# create plots
for (trace in unlist(ctrace)) {
create_pdf(trace)
}
alog <- activitylog(dat,
case_id = "trace",
activity_id = "event",
resource_id = "artwork",
timestamps = c("start", "complete"))
map <- process_map(alog)
g <- DiagrammeR::grViz(map$x$diagram) |> DiagrammeRsvg::export_svg() |> charToRaw()
rsvg::rsvg_pdf(g, "../figures/processmap_haum.pdf", width = 10, height = 5)
# adjusted colors
writeLines(map$x$diagram, "process_map_haum.gv")
g <- DiagrammeR::grViz("process_map_haum.gv") |> DiagrammeRsvg::export_svg() |> charToRaw()
rsvg::rsvg_pdf(g, "../figures/processmap_haum_adjusted.pdf", width = 10, height = 5)
alog <- activitylog(dat[!dat$trace %in% unlist(ctrace), ],
case_id = "trace",
activity_id = "event",
resource_id = "artwork",
timestamps = c("start", "complete"))
map <- process_map(alog)
g <- DiagrammeR::grViz(map$x$diagram) |> DiagrammeRsvg::export_svg() |> charToRaw()
rsvg::rsvg_pdf(g, "../figures/processmap_haum_cleaned.pdf", width = 12, height = 5)