Skip to content

Commit

Permalink
polish new added plots
Browse files Browse the repository at this point in the history
  • Loading branch information
simonliao98 committed Jan 10, 2025
1 parent 616f927 commit 4e288d2
Show file tree
Hide file tree
Showing 4 changed files with 162 additions and 40 deletions.
94 changes: 64 additions & 30 deletions plotting/durationSecPlot.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,15 @@ get_duration_data <- function(data_list) {
distinct() %>%
filter(!is.na(fontNominalSizePx))
}
if (is.character(df$targetMeasuredDurationSec)) {
df <- df %>% separate_rows(targetMeasuredDurationSec,sep=',')
df$targetMeasuredDurationSec <- as.numeric(df$targetMeasuredDurationSec)
}
return(df)
}

get_duration_corr <- function(data_list) {
print('inside get_duration_corr')
params <- foreach(i=1:length(data_list), .combine='rbind') %do% {
t <- data_list[[i]] %>%
filter(!is.na(staircaseName)) %>%
Expand All @@ -45,27 +50,48 @@ get_duration_corr <- function(data_list) {
trialGivenToQuest) %>%
rename(hardwareConcurrency = cores) %>%
filter(trialGivenToQuestChecks != '', !is.na(trialGivenToQuestChecks)) %>%
separate_rows(trialGivenToQuestErrorCheckLabels, trialGivenToQuestChecks, sep = ",") %>%
mutate(trialGivenToQuestChecks = as.logical(trialGivenToQuestChecks)) %>%
mutate(deltaHeapUsedMB = as.numeric(`heapUsedAfterDrawing (MB)`) - as.numeric(`heapUsedBeforeDrawing (MB)`),
deltaHeapTotalMB = as.numeric(`heapTotalAfterDrawing (MB)`) - as.numeric(`heapTotalBeforeDrawing (MB)`),
deltaHeapLatenessMB = as.numeric(`heapTotalPostLateness (MB)`) - as.numeric(`heapTotalPreLateness (MB)`))

t <- t %>%
pivot_wider(names_from = trialGivenToQuestErrorCheckLabels,
values_from = trialGivenToQuestChecks)
# t <- t %>%
# pivot_wider(names_from = trialGivenToQuestErrorCheckLabels,
# values_from = trialGivenToQuestChecks)
}

params <- params %>%
select(-c(block,
participant,
trialGivenToQuest,
`heapTotalPostLateness (MB)`,
`heapTotalPreLateness (MB)`))
`heapTotalPreLateness (MB)`)) %>%
mutate(order = row_number())
trialGivenToQuest <- params %>%
select(order,trialGivenToQuestErrorCheckLabels,trialGivenToQuestChecks) %>%
separate_rows(trialGivenToQuestErrorCheckLabels, trialGivenToQuestChecks, sep = ',') %>%
mutate(trialGivenToQuestChecks = as.logical(trialGivenToQuestChecks)) %>%
pivot_wider(names_from = trialGivenToQuestErrorCheckLabels,
values_from = trialGivenToQuestChecks)
params <- params %>% select(-c(trialGivenToQuestErrorCheckLabels, trialGivenToQuestChecks)) %>%
left_join(trialGivenToQuest, by = 'order') %>%
select(-order)

if (is.character(params$targetMeasuredDurationSec)) {
params <- params %>% separate_rows(targetMeasuredDurationSec,sep=',')
params$targetMeasuredDurationSec <- as.numeric(params$targetMeasuredDurationSec)
}
params %>% select_if(is.numeric) %>%
select(where(~sum(!is.na(.)) > 0))
print(summary(params))

params <- params[complete.cases(params),]
print(params)
c <- colnames(params)
t <- data.frame(cor(params))

colnames(t) <- c
t <- t %>% mutate(across(everything(), round, 3))
print(t)
corplot <- ggcorrplot(t,
show.legend = FALSE,
show.diag = T,
Expand Down Expand Up @@ -263,12 +289,13 @@ append_hist_list <- function(data_list, plot_list, fileNames){
deltaHeapTotalMB = as.numeric(`heapTotalAfterDrawing (MB)`) - as.numeric(`heapTotalBeforeDrawing (MB)`),
deltaHeapLatenessMB = as.numeric(`heapTotalPostLateness (MB)`) - as.numeric(`heapTotalPreLateness (MB)`))
}
print('params')
print(params)
if (is.character(params$targetMeasuredDurationSec)) {
params <- params %>% separate_rows(targetMeasuredDurationSec,sep=',')
params$targetMeasuredDurationSec <- as.numeric(params$targetMeasuredDurationSec)
}
webGL <- tibble()
for (i in 1:length(data_list)) {
if ('WebGL_Report' %in% names(data_list[[i]])) {
print(data_list[[i]]$WebGL_Report)
t <- fromJSON(data_list[[i]]$WebGL_Report[1])
df <- data.frame(WebGL_Version = t$WebGL_Version,
Max_Texture_Size = t$Max_Texture_Size,
Expand Down Expand Up @@ -389,6 +416,7 @@ append_scatter_list <- function(data_list, plot_list, fileNames) {
computeRandomMHz,
deviceMemoryGB,
cores,
font,
fontNominalSizePx,
screenWidthPx,
trialGivenToQuest,
Expand All @@ -398,11 +426,14 @@ append_scatter_list <- function(data_list, plot_list, fileNames) {
deltaHeapTotalMB = as.numeric(`heapTotalAfterDrawing (MB)`) - as.numeric(`heapTotalBeforeDrawing (MB)`),
deltaHeapLatenessMB = as.numeric(`heapTotalPostLateness (MB)`) - as.numeric(`heapTotalPreLateness (MB)`))
}

if (is.character(params$targetMeasuredDurationSec)) {
params <- params %>% separate_rows(targetMeasuredDurationSec,sep=',')
params$targetMeasuredDurationSec <- as.numeric(params$targetMeasuredDurationSec)
}
j = length(plot_list) + 1
if (n_distinct(params$deltaHeapLatenessMB) > 1) {
plot_list[[j]] <- ggplot(data=params, aes(x=deltaHeapLatenessMB,y=targetMeasuredLatenessSec, color = participant)) +
geom_point() +
geom_jitter() +
guides(color=guide_legend(ncol=2, title = '')) +
labs(title = 'targetMeasuredLatenessSec vs. deltaHeapLatenessMB, \ncolored by participant')
fileNames[[j]] <- 'targetMeasuredLatenessSec-vs-deltaHeapLatenessMB-by-participant'
Expand All @@ -411,7 +442,7 @@ append_scatter_list <- function(data_list, plot_list, fileNames) {

if (n_distinct(params$deltaHeapLatenessMB) > 1) {
plot_list[[j]] <- ggplot(data=params, aes(x=deltaHeapLatenessMB,y=targetMeasuredDurationSec, color = participant)) +
geom_point() +
geom_jitter() +
guides(color=guide_legend(ncol=2, title = '')) +
labs(title = 'targetMeasuredDurationSec vs. deltaHeapLatenessMB \ncolored by participant')
fileNames[[j]] <- 'targetMeasuredDurationSec-vs-deltaHeapLatenessMB-by-participant'
Expand All @@ -420,47 +451,50 @@ append_scatter_list <- function(data_list, plot_list, fileNames) {

if (n_distinct(params$deltaHeapTotalMB) > 1) {
plot_list[[j]] <- ggplot(data=params, aes(x=deltaHeapTotalMB,y=targetMeasuredLatenessSec, color = participant)) +
geom_point() +
geom_jitter() +
guides(color=guide_legend(ncol=2, title = '')) +
labs(title = 'targetMeasuredLatenessSec vs. deltaHeapTotalMB \ncolored by participant')
fileNames[[j]] <- 'targetMeasuredLatenessSec-vs-deltaHeapTotalMB-by-participant'
j = j + 1
}
if (n_distinct(params$longTaskDurationSec) > 1 & n_distinct(params$targetMeasuredLatenessSec) > 1) {
plot_list[[j]] <- ggplot(data=params, aes(x=longTaskDurationSec,y=targetMeasuredLatenessSec, color = participant)) +
geom_point() +
geom_jitter() +
guides(color=guide_legend(ncol=2, title = '')) +
labs(title = 'targetMeasuredLatenessSec vs. longTaskDurationSec \ncolored by participant')
fileNames[[j]] <- 'targetMeasuredLatenessSec-vs-longTaskDurationSec-by-participant'
j = j + 1
}
if (n_distinct(params$longTaskDurationSec) > 1 & n_distinct(params$targetMeasuredDurationSec) > 1) {
plot_list[[j]] <- ggplot(data=params, aes(x=longTaskDurationSec,y=targetMeasuredDurationSec, color = participant)) +
geom_point() +
geom_jitter() +
guides(color=guide_legend(ncol=2, title = '')) +
labs(title = 'targetMeasuredDurationSec vs. longTaskDurationSec \ncolored by participant')
fileNames[[j]] <- 'longTaskDurationSec-vs-longTaskDurationSec-by-participant'
j = j + 1
}
if (n_distinct(params$fontNominalSizePx) > 1 & n_distinct(params$deltaHeapUsedMB) > 1) {
plot_list[[j]] <- ggplot(data=params, aes(x=fontNominalSizePx,y=deltaHeapUsedMB, color = participant)) +
geom_point() +
plot_list[[j]] <- ggplot(data=params, aes(x=fontNominalSizePx,y=deltaHeapUsedMB, color = font)) +
geom_jitter() +
guides(color=guide_legend(ncol=2, title = '')) +
labs(title = 'deltaHeapUsedMB vs. fontNominalSizePx \ncolored by participant')
fileNames[[j]] <- 'deltaHeapUsedMB-vs-fontNominalSizePx-by-participant'
scale_x_log10() +
scale_y_log10() +
coord_fixed() +
labs(title = 'deltaHeapUsedMB vs. fontNominalSizePx \ncolored by font')
fileNames[[j]] <- 'deltaHeapUsedMB-vs-fontNominalSizePx-by-font'
j = j + 1
}
if (n_distinct(params$fontNominalSizePx) > 1 & n_distinct(params$longTaskDurationSec) > 1) {
plot_list[[j]] <- ggplot(data=params, aes(x=fontNominalSizePx,y=longTaskDurationSec, color = participant)) +
geom_point() +
geom_jitter() +
guides(color=guide_legend(ncol=2, title = '')) +
labs(title = 'longTaskDurationSec vs. fontNominalSizePx \ncolored by participant')
fileNames[[j]] <- 'longTaskDurationSec-vs-fontNominalSizePx-by-participant'
j = j + 1
}
if (n_distinct(params$longTaskDurationSec) > 1 & n_distinct(params$deltaHeapUsedMB) > 1) {
plot_list[[j]] <- ggplot(data=params, aes(x=longTaskDurationSec,y=deltaHeapUsedMB, color = participant)) +
geom_point() +
geom_jitter() +
guides(color=guide_legend(ncol=2, title = '')) +
labs(title = 'deltaHeapUsedMB vs. longTaskDurationSec \ncolored by participant')
fileNames[[j]] <- 'deltaHeapUsedMB-vs-longTaskDurationSec-by-participant'
Expand All @@ -469,7 +503,7 @@ append_scatter_list <- function(data_list, plot_list, fileNames) {

if (n_distinct(params$`heapLimitAfterDrawing (MB)`) > 1 & n_distinct(params$deltaHeapTotalMB) > 1) {
plot_list[[j]] <- ggplot(data=params, aes(x=`heapLimitAfterDrawing (MB)`,y=deltaHeapTotalMB, color = participant)) +
geom_point() +
geom_jitter() +
guides(color=guide_legend(ncol=2, title = '')) +
labs(title = 'deltaHeapTotalMB vs. heapLimitAfterDrawing \ncolored by participant')
fileNames[[j]] <- 'deltaHeapTotalMB-vs-heapLimitAfterDrawing-by-participant'
Expand All @@ -478,7 +512,7 @@ append_scatter_list <- function(data_list, plot_list, fileNames) {

if (n_distinct(params$`heapUsedBeforeDrawing (MB)`) > 1 & n_distinct(params$deltaHeapTotalMB) > 1) {
plot_list[[j]] <- ggplot(data=params, aes(x=`heapUsedBeforeDrawing (MB)`,y=deltaHeapTotalMB, color = participant)) +
geom_point() +
geom_jitter() +
guides(color=guide_legend(ncol=2, title = '')) +
labs(title = 'deltaHeapTotalMB vs. heapUsedBeforeDrawing \ncolored by participant')
fileNames[[j]] <- 'deltaHeapTotalMB-vs-heapUsedBeforeDrawing-by-participant'
Expand All @@ -487,7 +521,7 @@ append_scatter_list <- function(data_list, plot_list, fileNames) {

if (n_distinct(params$targetMeasuredLatenessSec) > 1 & n_distinct(params$targetMeasuredDurationSec) > 1) {
plot_list[[j]] <- ggplot(data=params, aes(x=targetMeasuredLatenessSec,y=targetMeasuredDurationSec, color = participant)) +
geom_point() +
geom_jitter() +
guides(color=guide_legend(ncol=2, title = '')) +
labs(title = 'targetMeasuredDurationSec vs. targetMeasuredLatenessSec \ncolored by participant')
fileNames[[j]] <- 'targetMeasuredDurationSec-vs-targetMeasuredLatenessSec-by-participant'
Expand All @@ -496,7 +530,7 @@ append_scatter_list <- function(data_list, plot_list, fileNames) {

if (n_distinct(params$deltaHeapTotalMB) > 1 & n_distinct(params$deltaHeapUsedMB) > 1) {
plot_list[[j]] <- ggplot(data=params, aes(x=deltaHeapTotalMB,y=deltaHeapUsedMB, color = participant)) +
geom_point() +
geom_jitter() +
guides(color=guide_legend(ncol=2, title = '')) +
labs(title = 'deltaHeapUsedMB vs. deltaHeapTotalMB \ncolored by participant')
fileNames[[j]] <- 'deltaHeapUsedMB-vs-deltaHeapTotalMB-by-participant'
Expand All @@ -514,7 +548,7 @@ append_scatter_list <- function(data_list, plot_list, fileNames) {

if (n_distinct(params$badLatenessTrials) > 1 & n_distinct(params$badDurationTrials) > 1) {
plot_list[[j]] <- ggplot(data=params, aes(x=badLatenessTrials,y=badDurationTrials, color = participant)) +
geom_point() +
geom_jitter() +
guides(color=guide_legend(ncol=2, title = '')) +
labs(title = 'badDurationTrials vs. badLatenessTrials \ncolored by participant')
fileNames[[j]] <- 'badDurationTrials-vs-badLatenessTrials-by-participant'
Expand All @@ -523,7 +557,7 @@ append_scatter_list <- function(data_list, plot_list, fileNames) {

if (n_distinct(params$`heapLimitAfterDrawing (MB)`) > 1 & n_distinct(params$badLatenessTrials) > 1) {
plot_list[[j]] <- ggplot(data=params, aes(x=`heapLimitAfterDrawing (MB)`,y=badLatenessTrials, color = participant)) +
geom_point() +
geom_jitter() +
guides(color=guide_legend(ncol=2, title = '')) +
labs(title = 'badLatenessTrials vs. heapLimitAfterDrawing \ncolored by participant')
fileNames[[j]] <- 'badLatenessTrials-vs-heapLimitAfterDrawing-by-participant'
Expand All @@ -532,7 +566,7 @@ append_scatter_list <- function(data_list, plot_list, fileNames) {

if (n_distinct(params$heapUsedAfterDrawingAvg) > 1 & n_distinct(params$badLatenessTrials) > 1) {
plot_list[[j]] <- ggplot(data=params, aes(x=heapUsedAfterDrawingAvg,y=badLatenessTrials, color = participant)) +
geom_point() +
geom_jitter() +
guides(color=guide_legend(ncol=2, title = '')) +
labs(title = 'badLatenessTrials vs. heapUsedAfterDrawingAvg \ncolored by participant')
fileNames[[j]] <- 'badLatenessTrials-vs-heapUsedAfterDrawingAvg-by-participant'
Expand All @@ -541,7 +575,7 @@ append_scatter_list <- function(data_list, plot_list, fileNames) {

if (n_distinct(params$heapTotalAfterDrawingAvg) > 1 & n_distinct(params$badLatenessTrials) > 1) {
plot_list[[j]] <- ggplot(data=params, aes(x=heapTotalAfterDrawingAvg,y=badLatenessTrials, color = participant)) +
geom_point() +
geom_jitter() +
guides(color=guide_legend(ncol=2, title = '')) +
labs(title = 'badLatenessTrials vs. heapTotalAfterDrawingAvg \ncolored by participant')
fileNames[[j]] <- 'badLatenessTrials-vs-heapTotalAfterDrawingAvg-by-participant'
Expand All @@ -551,7 +585,7 @@ append_scatter_list <- function(data_list, plot_list, fileNames) {
if (n_distinct(params$deviceMemoryGB) > 1 & n_distinct(params$badLatenessTrials) > 1) {

plot_list[[j]] <- ggplot(data=params, aes(x=deviceMemoryGB,y=badLatenessTrials, color = participant)) +
geom_point() +
geom_jitter() +
guides(color=guide_legend(ncol=2, title = '')) +
labs(title = 'badLatenessTrials vs. deviceMemoryGB \ncolored by participant')
fileNames[[j]] <- 'badLatenessTrials-vs-deviceMemoryGB-by-participant'
Expand Down
33 changes: 24 additions & 9 deletions preprocess.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ read_files <- function(file){
if(is.null(file)) return(list())
file_list <- file$data
file_names <- file$name
file_list <- file_list[!grepl("cursor", basename(file_names))]
file_list <- file_list[!grepl("^~", basename(file_names))]
file_list <- file_list[!grepl("cursor", basename(file_names)) & !grepl("^~", basename(file_names))]
file_names <- file_names[!grepl("cursor", basename(file_names)) & !grepl("^~", basename(file_names))]
data_list <- list()
stair_list <- list()
summary_list <- list()
Expand All @@ -19,8 +19,16 @@ read_files <- function(file){
pretest <- tibble()
for (i in 1 : n) {
t <- tibble()
if (grepl(".xlsx", file_list[i])) {
pretest <- readxl::read_xlsx(file_list[i])
print(file_names[i])
print(grepl("pretest.xlsx", file_names[i]))
print(grepl("pretest.csv", file_names[i]))
if (grepl("pretest.xlsx", file_names[i])) {
if (grepl("pretest.xlsx", file_list[i])) {
pretest <- readxl::read_xlsx(file_list[i])
} else {
pretest <- read_csv(file_list[i])
}

if ('PavloviaSessionID' %in% names(pretest)) {
pretest <- pretest %>%
rename('participant' = 'PavloviaSessionID') %>%
Expand All @@ -41,7 +49,7 @@ read_files <- function(file){
mutate(Grade = ifelse(is.na(Grade), -1, Grade))
}
}
if (grepl(".csv", file_list[i])){
if (grepl(".csv", file_names[i]) & !grepl("pretest.csv", file_names[i])){
try({t <- readr::read_csv(file_list[i],show_col_types = FALSE)}, silent = TRUE)


Expand Down Expand Up @@ -353,8 +361,9 @@ read_files <- function(file){
all_csv <- file_names[grepl(".csv", file_names)]
all_csv <- all_csv[!grepl("__MACOSX", all_csv)]
all_csv <- all_csv[!grepl("cursor", all_csv)]
all_xlsx <- file_names[grepl(".xlsx", file_names)]
all_xlsx <- all_xlsx[!grepl("__MACOSX", all_xlsx)]
all_csv <- all_csv[!grepl("pretest", all_csv)]
all_pretest <- file_names[grepl("pretest", file_names)]
all_pretest <- all_pretest[!grepl("__MACOSX", all_pretest)]
m <- length(all_csv)
for (k in 1 : m) {
t <- tibble()
Expand Down Expand Up @@ -665,8 +674,14 @@ read_files <- function(file){
}
}
}
if (length(all_xlsx) > 0) {
pretest <- readxl::read_xlsx(unzip(file_list[i], all_xlsx[1]))
if (length(all_pretest) > 0) {
if (grepl("pretest.xlsx", all_pretest[1])) {
pretest <- readxl::read_xlsx(unzip(file_list[i], all_pretest[1]))
}
# else {
# pretest <- readr::read_csv(unzip(file_list[i], all_pretest[1]),show_col_types = FALSE)
# }

if ('PavloviaSessionID' %in% names(pretest)) {
pretest <- pretest %>%
rename('participant' = 'PavloviaSessionID') %>%
Expand Down
Loading

0 comments on commit 4e288d2

Please sign in to comment.