global variables
Define your global variables:
create raw data files
# sets the directory of location of this script as the current directory
# setwd(dirname(rstudioapi::getSourceEditorContext()$path))
### load packages
# devtools::install_github('jdwilson4/multilayer_extraction')
require (pacman)
p_load ('tidyverse' , 'jsonlite' , 'magrittr' , 'xlsx' ,
'stargazer' , 'psych' , 'jtools' , 'DT' , 'ggstatsplot' ,
'ggplot2' ,
'base64enc' )
### list data files
setwd ("data" )
dir ()
[1] "jatos_results_data_20240430143549.txt"
[2] "jatos_results_data_20240514064500.txt"
[3] "jatos_results_data_20240718150114.txt"
suppressMessages (read_file ('jatos_results_data_20240718150114.txt' ) %>%
# ... split it into lines ...
str_split (' \n ' ) %>% first () %>%
# ... filter empty rows ...
discard (function (x) x == '' ) %>%
# ... parse JSON into a data.frame
map_dfr (fromJSON, flatten= TRUE )) -> dat
### load functions
setwd ("../functions" )
for (i in 1 : length (dir ())){
# print(dir()[i])
source (dir ()[i], encoding = "utf-8" )
}
rm (i)
prepare data
set up data.frame
########################################
# create counter variable for data set
########################################
dat$ ID <- NA
tmp_IDcounter <- 0
for (i in 1 : nrow (dat)){
if (! is.na (dat$ sender[i]) && dat$ sender[i] == "Report" ){
# tmp <- dat$prolific_pid[i]
tmp_IDcounter = tmp_IDcounter + 1
}
dat$ ID[i] <- tmp_IDcounter
}
########################################
# keep only complete data sets
########################################
sum (table (dat$ ID) != max (table (dat$ ID)))
sum (table (dat$ ID) == max (table (dat$ ID)))
dat <- dat[dat$ ID %in% names (table (dat$ ID))[table (dat$ ID) == max (table (dat$ ID))],]
########################################
# json (from JATOS) to 2D data.frame
########################################
tmp_notNumeric <- str_subset (string = colnames (dat), pattern = "^meta" )
tmp_notNumeric <- str_subset (string = tmp_notNumeric, pattern = "labjs|location" , negate = TRUE )
# "bug_browser_used_additional"
# tmp_notNumeric
vec_ques <- c ("dummy_type" ,
"bug_tool" ,
"bug_CAMEL_element" ,
"bug_CAMApp_part" ,
"bug_Webpage_part" ,
"bug_browser_used" ,
"automatic_browser" , "automatic_browser2" ,
"automatic_browserVersion" , "automatic_operatingSystem" ,
"bug_text" ,
"Base64Image" ,
"bug_code" ,
"improvement_tool" ,
"improvement_CAMEL_element" ,
"improvement_CAMEL_text" ,
"improvement_CAMEL_importance" ,
"improvement_CAMApp_part" ,
"improvement_CAMApp_text" ,
"improvement_CAMApp_importance" ,
"improvement_Webpage_part" ,
"improvement_Webpage_text" ,
"improvement_Webpage_importance" ,
"feedback_critic" )
vec_notNumeric = vec_ques
questionnaire <- questionnairetype (dataset = dat,
listvars = vec_ques,
notNumeric = vec_notNumeric)
questionnaire$ bug_browser_used_additional <- NA
for (i in 1 : nrow (questionnaire)){
tmp_dat <- dat[dat$ ID == unique (questionnaire$ ID)[i], ]
questionnaire$ bug_browser_used_additional[i] <- paste0 (unlist (tmp_dat$ bug_browser_used_additional), collapse = " \\ " )
}
questionnaire$ bug_browser_used_additional[questionnaire$ bug_browser_used_additional == "" ] <- NA
dat_pictures <- questionnaire[, c ("ID" , "Base64Image" )]
questionnaire$ Base64Image <- NULL
overview
table (questionnaire$ dummy_type)
table (questionnaire$ bug_tool)
CAMApp CAMEL Webpage
3 5 9 9
table (questionnaire$ bug_tool, questionnaire$ bug_CAMEL_element)
concept connection other
3 0 0 0
CAMApp 5 0 0 0
CAMEL 0 5 2 2
Webpage 9 0 0 0
table (questionnaire$ bug_tool, questionnaire$ bug_CAMApp_part)
analysis preprocessing upload
3 0 0 0
CAMApp 0 3 1 1
CAMEL 9 0 0 0
Webpage 9 0 0 0
table (questionnaire$ bug_tool, questionnaire$ bug_Webpage_part)
afterLogIn beforeLogIn other
3 0 0 0
CAMApp 5 0 0 0
CAMEL 9 0 0 0
Webpage 0 4 3 2
reported bugs
for CAMEL
setwd ("outputs" )
## dynamic table for CAMEL
tmp_dat <- questionnaire[questionnaire$ bug_tool == "CAMEL" ,]
tmp_dat <- tmp_dat[, str_detect (string = colnames (tmp_dat), pattern = "improvement" , negate = TRUE )]
tmp_dat <- tmp_dat[, ! colnames (tmp_dat) %in% c ("bug_CAMApp_part" , "bug_Webpage_part" )]
nrow (tmp_dat)
DT:: datatable (tmp_dat, options = list (pageLength = 5 ))
#> save as .xlsx
xlsx:: write.xlsx2 (x = tmp_dat, file = "bugs_CAMEL.xlsx" )
for CAMApp
setwd ("outputs" )
## dynamic table for CAMApp
tmp_dat <- questionnaire[questionnaire$ bug_tool == "CAMApp" ,]
tmp_dat <- tmp_dat[, str_detect (string = colnames (tmp_dat), pattern = "improvement" , negate = TRUE )]
tmp_dat <- tmp_dat[, ! colnames (tmp_dat) %in% c ("bug_CAMEL_element" , "bug_Webpage_part" )]
nrow (tmp_dat)
DT:: datatable (tmp_dat, options = list (pageLength = 5 ))
#> save as .xlsx
xlsx:: write.xlsx2 (x = tmp_dat, file = "bugs_CAMApp.xlsx" )
for Webpage
setwd ("outputs" )
## dynamic table for Webpage
tmp_dat <- questionnaire[questionnaire$ bug_tool == "Webpage" ,]
tmp_dat <- tmp_dat[, str_detect (string = colnames (tmp_dat), pattern = "improvement" , negate = TRUE )]
tmp_dat <- tmp_dat[, ! colnames (tmp_dat) %in% c ("bug_CAMEL_element" , "bug_CAMApp_part" )]
nrow (tmp_dat)
DT:: datatable (tmp_dat, options = list (pageLength = 5 ))
#> save as .xlsx
xlsx:: write.xlsx2 (x = tmp_dat, file = "bugs_Webpage.xlsx" )
save screenshots
setwd ("outputs/screenshots" )
for (i in 1 : nrow (dat_pictures)){
if (! is.na (dat_pictures$ Base64Image[i])){
if (str_detect (string = dat_pictures$ Base64Image[i], pattern = "data:application/pdf;base64," )){
dat_pictures$ Base64Image[i] <- str_remove_all (string = dat_pictures$ Base64Image[i], pattern = "data:application/pdf;base64," )
tmp_name <- "pdf"
}else if (str_detect (string = dat_pictures$ Base64Image[i], pattern = "data:image/png;base64," )){
dat_pictures$ Base64Image[i] <- str_remove_all (string = dat_pictures$ Base64Image[i], pattern = "data:image/png;base64," )
tmp_name <- "png"
}else if (str_detect (string = dat_pictures$ Base64Image[i], pattern = "data:image/jpeg;base64," )){
dat_pictures$ Base64Image[i] <- str_remove_all (string = dat_pictures$ Base64Image[i], pattern = "data:image/jpeg;base64," )
tmp_name <- "jpeg"
}else {
print (i)
}
binary_data <- base64enc:: base64decode (what = dat_pictures$ Base64Image[i])
writeBin (binary_data, paste0 (dat_pictures$ ID[i], "_screenshot." , tmp_name))
}
}
reported possible improvements
setwd ("outputs" )
## dynamic table for suggested improvements
tmp_dat <- questionnaire[questionnaire$ dummy_type == "improvement" ,]
tmp_dat <- tmp_dat[, str_detect (string = colnames (tmp_dat), pattern = "bug" , negate = TRUE )]
tmp_dat <- tmp_dat[, ! colnames (tmp_dat) %in% c ("bug" )]
nrow (tmp_dat)
DT:: datatable (tmp_dat, options = list (pageLength = 5 ))
#> save as .xlsx
xlsx:: write.xlsx2 (x = tmp_dat, file = "improvements.xlsx" )