Worked on variants in user navigation

This commit is contained in:
Nora Wickelmaier 2024-02-07 13:26:35 +01:00
parent 358d962f1e
commit f9f8086486

View File

@ -1,14 +1,15 @@
# 09_case-clustering.R
# 09_user_navigation.R
#
# content: (1) Read data
# (1.1) Read log event data
# (1.2) Extract additional infos for clustering
# (2) Clustering
# (3) Investigate variants
#
# input: results/haum/event_logfiles_2024-01-18_09-58-52.csv
# output: results/haum/event_logfiles_pre-corona_with-clusters_cases.csv
#
# last mod: 2024-02-04
# last mod: 2024-02-07
# setwd("C:/Users/nwickelmaier/Nextcloud/Documents/MDS/2023ss/60100_master_thesis/analysis/code")
@ -58,7 +59,7 @@ datcase$npaths <- aggregate(path ~ case, dat, function(x)
# datcase$ntopics <- aggregate(topic ~ case, dat,
# function(x) ifelse(all(is.na(x)), NA, length(unique(na.omit(x)))),
# na.action = NULL)$topic
#
#
datcase$vacation <- aggregate(vacation ~ case, dat,
function(x) ifelse(all(is.na(x)), 0, 1),
na.action = NULL)$vacation
@ -79,20 +80,16 @@ datcase <- na.omit(datcase)
df <- datcase[, c("duration", "distance", "scaleSize", "rotationDegree",
"length", "nitems", "npaths")] |>
scale()
df <- cbind(df, datcase[, c("vacation", "holiday", "weekend", "morning")])
#df <- cbind(df, datcase[, c("vacation", "holiday", "weekend", "morning")])
mat <- dist(df)
hc <- hclust(mat, method = "ward.D2")
hc <- hclust(mat)
grp <- cutree(hc, k = 3)
grp <- cutree(hc, k = 6)
datcase$grp <- grp
table(grp)
# k1 <- kmeans(mat, 4)
# datcase$kcluster <- k1$cluster
fviz_cluster(list(data = df, cluster = grp),
palette = c("#78004B", "#000000", "#3CB4DC", "#91C86E",
"#FF6900", "#434F4F"),
@ -123,7 +120,8 @@ write.table(res,
quote = FALSE,
row.names = FALSE)
# Look at variants
#--------------- (2) Investigate variants ---------------
res$start <- res$date.start
res$complete <- res$date.stop
@ -133,7 +131,7 @@ alog <- activitylog(res,
resource_id = "path",
timestamps = c("start", "complete"))
trace_explorer(alog, n_traces = 30)
trace_explorer(alog, n_traces = 25)
# --> sequences of artworks are just too rare
tr <- traces(alog)
@ -145,22 +143,19 @@ tr[trace_varied > 1, ]
table(tr[trace_varied > 2, "absolute_frequency"])
table(tr[trace_varied > 3, "absolute_frequency"])
longest_case <- datcase[datcase$length == max(datcase$length), "case"]
alog_often <- activitylog(res[res$case == longest_case, ],
case_id = "case",
activity_id = "item",
resource_id = "path",
timestamps = c("start", "complete"))
process_map(alog_often)
summary(tr$absolute_frequency)
vioplot::vioplot(tr$absolute_frequency)
# Power law for frequencies of traces
tab <- table(tr$absolute_frequency)
x <- as.numeric(tab)
y <- as.numeric(names(tab))
plot(log(y) ~ log(x))
abline(lm(log(y) ~ log(x)))
plot(x, y, log = "xy")
p1 <- lm(log(y) ~ log(x))
pre <- exp(coef(p1)[1]) * x^coef(p1)[2]
lines(x, pre)
# Look at individual traces as examples
tr[trace_varied == 5 & trace_length > 50, ]
@ -169,17 +164,32 @@ datcase[datcase$nitems == 5 & datcase$length > 50,]
sapply(datcase[, -c(1, 9)], median)
ex <- datcase[datcase$nitems == 10 & datcase$length == 30,]
#ex <- datcase[datcase$nitems == 4 & datcase$length == 15,]
ex <- datcase[datcase$nitems == 5,]
ex <- ex[sample(1:nrow(ex), 20), ]
# --> pretty randomly chosen... TODO:
case_ids <- NULL
for (case in ex$case) {
if ("080" %in% res$item[res$case == case] | "503" %in% res$item[res$case == case]) {
case_ids <- c(case_ids, TRUE)
} else {
case_ids <- c(case_ids, FALSE)
}
}
cases <- ex$case[case_ids]
for (case in cases) {
alog <- activitylog(res[res$case == case, ],
case_id = "case",
activity_id = "item",
resource_id = "path",
timestamps = c("start", "complete"))
dfg <- process_map(alog,
type_nodes = frequency("absolute", color_scale = "Greys"),
type_edges = frequency("absolute", color_edges = "#FF6900"),
@ -193,29 +203,3 @@ for (case in ex$case) {
}
## --> not interesting!
# Just "flipCard"
res_case <- res[!duplicated(res[, c("case", "path")]), ]
for (case in ex$case) {
alog <- activitylog(res_case[res_case$case == case, ],
case_id = "case",
activity_id = "item",
resource_id = "path",
timestamps = c("start", "complete"))
dfg <- process_map(alog,
type_nodes = frequency("absolute", color_scale = "Greys"),
type_edges = frequency("absolute", color_edges = "#FF6900"),
rankdir = "LR",
render = FALSE)
export_map(dfg,
file_name = paste0("results/processmaps/dfg_example_cases_", case, "_fc_R.pdf"),
file_type = "pdf",
title = paste("Single case", case))
}