# Manuel Dahnert
# User study: Looking beyond the horizon: Evaluation of four compact visualization techniques for time series in a spatial context
# Evaluation of post-tasks
# Generate boxplots
# Generate summary statistics

source("eval-functions.R")

# Load necessary librarys
loadLibrary("RColorBrewer")
loadLibrary("data.table")
loadLibrary("ggplot2")

# Load raw study data and perform general filtering
data.csv <- read.csv("rawdata_study.csv", header = TRUE, sep =";")
data <- filterData(data.csv, max.skips = 10, min.time = 30)

data <- data[data$questionId %in% c("confidence", "seq"), ]
data <- data[, c(1, 8, 13, 16, 18)] # Exclude unnecessary columns
data$givenAnswer <- as.numeric(factor(data$givenAnswer))
data <- data[data$givenAnswer < 8,]
data$questionId <- factor(data$questionId)


data <- data.table(data)
data[questionId == "seq", ]$questionId <- "ease-of-use"

# Define output directory
export.root <- "export/posttasks/"
dir.create(export.root, showWarnings = FALSE) # Create directory


output.dir <- paste(export.root, "boxplots/", sep = "") # Assume folder exists
dir.create(output.dir, showWarnings = FALSE) # Create directory
output.width <- 350
output.height <- 400
fac <- factor(data$technique, c("boxplots", "horizongraphs", 
                                     "colhorgraphs", "braidedgraphs"))

boxplot.cols <- c("#66C2A3", "#E78AC3", "#8DA0CB", "#FC8D62")
bp <- ggplot(aes(y = givenAnswer, x = factor(questionId), 
                 fill = fac), data = data) + 
  labs(x = "Confidence / Ease-of-use", y="Rating") + 
  geom_boxplot(outlier.shape = NA) +
  coord_cartesian(ylim = c(0, 7))

bp <- bp + scale_fill_manual(values = boxplot.cols, name ="",
                             labels = c("CBP", "HG", "CHG", "BHG"),
                             breaks = c("boxplots", "horizongraphs", "colhorgraphs",
                                        "braidedgraphs"))
bp <- bp + theme(legend.background = element_rect(fill=alpha('gray', 0.0)),
                 legend.direction = "horizontal", legend.position = c(0.5,0), 
                 legend.justification=c(0.5,0), panel.background = element_blank() ,
                 panel.border = element_rect(fill = NA, colour = "black"))
ggsave(paste(output.dir, "posttask.png", sep = ""), device = "png", 
       w = 3.125, h = 4.17, units = "in", plot = bp)
