---
title: "AR consent and awareness survey 2021"
output: html_notebook
---
# Authors
Joseph O'Hagan School of Computing Science, University of Glasgow, Glasgow, United Kingdom
Pejman Saeghe School of Computer Science, University of Glasgow, Glasgow, Lanarkshire, United Kingdom, pejman.saeghe@glasgow.ac.uk
Jan Gugenheimer Télécom Paris - LTCI, Institut Polytechnique de Paris, Paris, France
Dr Daniel Medeiros School of Computing Science, University of Glasgow, Glasgow, United Kingdom, daniel.piresdesamedeiros@glasgow.ac.uk
Karola Marky University of Glasgow, Glasgow, Germany, karola.marky@glasgow.ac.uk
Dr. Mohamed Khamis University of Glasgow, Glasgow, United Kingdom
Dr Mark McGill School of Computing Science, University of Glasgow, Glasgow, Lanarkshire, United Kingdom, mark.mcgill@glasgow.ac.uk


# Overview
This data is for our ACM IMWUT 2022 paper "Privacy-Enhancing Technology and Everyday Augmented Reality: Understanding Bystanders' Varying Needs for Awareness and Consent".

This was a rather complex survey, with multiple looping factors. This RMarkdown file contains our breakdown and analysis of the quesitons in the survey. See also the attachment of the survey PDF. 


# MAPPINGS
--------------
For demographics
--------------
3 age
4 gender
5 country
6 have you used AR before
7 do you know what an ar headset is

--------------
Question mappings for looped questions
--------------
capability 11 23
consent by social connection 13 25
automatic consent 14 26
concerning 15 27
more concerning than smartphone 16 28
stranger awareness preference 18 30
your headset awareness preference 20 32

-------------
Ending questions
-------------
34 more or less uncomfortable with AR
35 how comortable are you
---------------

### Behind the scenes
# SETUP
```{r}
library(qualtRics)
library(reshape2)
library(stringr)
library(plyr)
library(dplyr) 
library(ggplot2)
library(ARTool)
library(forcats)
library(statsExpressions)
library(cowplot) 
library(scales)

raw_data <- read_survey("cleaned_data.csv")
raw_data$ParticipantID <- seq.int(nrow(raw_data))
head(raw_data)
raw_data <- subset(raw_data, Progress == 100)
no_complete_responses = nrow(raw_data)
```
# UTILITY FUNCTION / TESTING
```{r}
#data = raw_data
#questions_to_select =  c("Q21", "Q22", "Q42")
#question_factor_levels =  c("21"  = "Age", "22" = "Gender", "42" = "Country")
#id_variables = c("ParticipantID")
#factor_one_levels = loop.factor
#factor_two_levels = NULL

ExportPlot <- function(gplot, filename, width=2, height=1.5, doPNG=TRUE, doPDF=FALSE, doEPS=FALSE) {
  # Export plot in PDF and EPS.
  # Notice that A4: width=11.69, height=8.27
  if (doPDF){
    ggsave(paste(filename, '.pdf', sep=""), gplot, width = width, height = height)
  }
  
  if (doEPS){
    postscript(file = paste(filename, '.eps', sep=""), width = width, height = height, horizontal = FALSE, onefile = FALSE, paper = "special")
  }
  #print(gplot)
  #dev.off()
  if (doPNG){
    #png(file = paste(filename, '_.png', sep=""), width = width * 100, height = height * 100)
    ggsave(paste(filename, '_.png', sep=""), gplot, width = width, height = height)
  }
  #print(gplot)
  #dev.off()
}

# define factor levels ala c(Congruent  = "Con", InCongruent = "InCon")
extract_composite_question_with_factors <- function(data, questions_to_select, id_variables, value_order,
                                         question_factor_levels  = NULL, 
                                         factor_one_levels  = NULL, 
                                         factor_two_levels  = NULL) {
  
  # select subset of questions we are looking at and ID variables
  data_subset <- select(data,matches( append(id_variables, questions_to_select))) 

  # now flatten this list using melt, excluding ID variables
  melted_data_subset <- melt(data_subset, id.vars=id_variables)
  #print(melted_data_subset)
  
  # then we need to set the factor levels for the various factors in our questionnaire.
  # This might be encoded in the question (e.g. q34 looking at bystander perspective, Q35 looking at user perspective)
  # Or might be explicitly coded for (e.g. a question loop, or rows in a question)
  # This is all encoded in the question string e.g. "4_Q64_1" where
  #   4 indicates level of first factor
  #   54 indicates level of question factor
  #   1 indicates level of third factor
  
  if (exists("question_factor_levels") && !is.null(question_factor_levels)){
      
      question_index = 1;
      # if we have a precursor factor defined, it's parsed before the question number is parsed
      if ( (exists("factor_one_levels") && !is.null(factor_one_levels)) )
        question_index = 2;
    
      melted_data_subset$question_factor <- unlist(purrr::transpose (stringr::str_extract_all(melted_data_subset$variable,"\\(?[0-9,.]+\\)?"))[[question_index]])
      melted_data_subset$question_factor <- factor(melted_data_subset$question_factor)
      melted_data_subset$question_factor <- revalue(melted_data_subset$question_factor, question_factor_levels)
  }
  
  if (exists("factor_one_levels") && !is.null(factor_one_levels)){
      melted_data_subset$factor_one <- unlist(purrr::transpose (stringr::str_extract_all(melted_data_subset$variable,"\\(?[0-9,.]+\\)?"))[[1]])
      melted_data_subset$factor_one <- factor(melted_data_subset$factor_one)
      melted_data_subset$factor_one <- revalue(melted_data_subset$factor_one, factor_one_levels)
  }
  
  if (exists ("factor_two_levels") && !is.null(factor_two_levels)){
      melted_data_subset$factor_two <- unlist(purrr::transpose (stringr::str_extract_all(melted_data_subset$variable,"\\(?[0-9,.]+\\)?"))[[3]])
      melted_data_subset$factor_two <- factor(melted_data_subset$factor_two)
      #print(levels(melted_data_subset$factor_two))
      melted_data_subset$factor_two <- revalue(melted_data_subset$factor_two, factor_two_levels)
  }
  
  melted_data_subset$ParticipantID <- factor(melted_data_subset$ParticipantID)
  
  melted_data_subset$value <- factor(melted_data_subset$value)

  #if (! is.null(value_order)){
  #  melted_data_subset$value <- factor(melted_data_subset$value, ordered = TRUE, levels = value_order)
  #} else {
  #  melted_data_subset$value <- factor(melted_data_subset$value)
  #}
  return (na.omit(melted_data_subset))
}

common.loopfactor <- c(
  "4" = "Camera usage",
  "5" = "Microphone usage",
  "7" = "Diminished reality",
  "8" = "Activity tracking",
  "9" = "Internal state",
  "12" = "Biometric ID",
  "13" = "Augmented perception",
  "16" = "Personal characteristics",
  "17" = "Physiological state",
  "18" = "Volumetric capture",
  "19" = "Augmented appearance"
)

common.looporder <-c(
  "Camera usage",
  "Microphone usage",
  "Activity tracking",
  "Volumetric capture",
  "Personal characteristics",
  "Biometric ID",
  "Internal state",
  "Physiological state",
  "Augmented appearance",
  "Diminished reality",
  "Augmented perception"
)

common.id_variables <- c("ParticipantID")

common.relationship <- c(
  "1" = "Close friend",
  "2" = "Friend",
  "3" = "Familiar stranger",
  "4" = "Stranger",
  "5" = "Accessibility needs"
)

common.awareness <- c(
  "1" = "None",
  "2" = "Basic",
  "3" = "Iconographic",
  "4" = "Full"
)

common.consent <- c(
  "1" = "With Consent",
  "2" = "Without Consent"
)

common.theme <-    theme(legend.position="bottom", legend.text=element_text(size=11),
          legend.title =element_blank(),
          legend.spacing.x=unit(0.8,"line"),
          legend.key.width=unit(1.8,"line"), legend.key.height=unit(1,"line")) +
      theme(axis.title.x=element_blank(),
          strip.text.x=element_text(size=12),
          axis.text=element_text(size=12),
          axis.ticks.y = element_blank(),
          axis.text.y=element_text(margin=margin(0,-8,0,0)),
          panel.background=element_blank(),
          panel.border=element_blank(),
          panel.grid.major=element_blank(),
          panel.grid.minor=element_blank(),
          panel.spacing.x = unit(1.0, "lines"),
          plot.background=element_blank())
CIColor = "red"

# common.agerange <- c(
#   "18 - 24" = 21,
#   "25 - 34" = ,
#   "35 - 44" = "Diminished reality",
#   "45 - 54" = "Tracking bystanders",
#   "55 - 64" = "Emotional & Physiological State",
#   "65 - 74" = "Biometric ID",
#   "13" = "Super hearing / sight",
#   "16" = "Personal characteristics",
#   "17" = "Medical / Health data",
#   "18" = "3D capture",
#   "19" = "Augmented appearance"
# )
```


### ENTRY QUESTIONS
# Demographics
```{r}
age_results = extract_composite_question_with_factors(raw_data, c("Q3$"), common.id_variables, NULL,
                                        c("3"  = "Age"))
age_results
levels(factor(age_results$value))

age_count <- age_results %>% count(value)
age_count$percentage <- (age_count$n / no_complete_responses) * 100
age_count

gender_results = extract_composite_question_with_factors(raw_data, c("Q4$"), common.id_variables, NULL,
                                        c("4" = "Gender"))
gender_results
gender_count <- gender_results %>% count(value)
gender_count$percentage <- (gender_count$n / no_complete_responses) * 100
gender_count

country_results = extract_composite_question_with_factors(raw_data, c("Q5$"), common.id_variables, NULL,
                                        c("5" = "Country"))
country_results
country_count <- country_results %>% count(value)
country_count$percentage <- (country_count$n / no_complete_responses) * 100
country_count
```

# AR Experience
```{r}
questionnaire_plot <- function(data, factor_one, factor_two, has_two_factors=FALSE){
  barplotdata <- NULL
  barplotdata <- data
  barplotdata$value_raw <- barplotdata$value
  barplotdata$value_multiplied <- as.numeric(barplotdata$value_raw)
  barplotdata$value_factor <- barplotdata$value_raw
  scale_size = length(levels(barplotdata$value))
  
  barplotdata$value_multiplied = (barplotdata$value_multiplied) * (no_complete_responses/scale_size) # then multiply to scale up
  print(barplotdata$value_raw_multiplied)
  
  app_plot_2 <- ggplot(data = barplotdata, aes_string(x=factor_one)) + common.theme+
      geom_bar(aes(fill=forcats::fct_rev(value_factor)), lwd=0) + coord_flip() +
  
      scale_y_continuous(limits=c(0, no_complete_responses), breaks=c(0,1/4 * no_complete_responses, 1/2 * no_complete_responses, 3/4 * no_complete_responses, no_complete_responses), labels=c("0%", "25%", "50%", "75%", "100%"))+
      stat_summary(aes(y=value_multiplied), fun.data=mean_cl_normal, fun.args = list(conf.int = 0.95), geom="errorbar", colour=CIColor, width=0.4, size=1.0) + #
      stat_summary(aes(y=value_multiplied), fun.y=mean, geom="point", colour=CIColor)+
      scale_fill_viridis_d(option = "D", drop=FALSE)+
      guides(fill = guide_legend(label.position = "bottom", reverse = TRUE, nrow=1))+
    
      xlab("")+ ylab("# of Responses")# + facet_wrap(~interactiontechnique, nrow=6)
  
  
  if (has_two_factors){
    app_plot_2 <- app_plot_2 + facet_wrap( as.formula(paste( "~", factor_two )), labeller = labeller(.rows = label_wrap_gen(20)))
  }
  
    #ExportPlot(app_plot_2, "acceptability_plot.png", 8, 20, doPDF=TRUE)
    #print(app_plot_2)
    #print(ggplot_build(app_plot_2)$data[[3]])
  return(app_plot_2)
}

#https://cran.r-project.org/web/packages/ggsignif/vignettes/intro.html 
#https://cran.r-project.org/web/packages/ARTool/vignettes/art-contrasts.html

filter_contrasts <- function(contrasts){
  result = as.data.frame(summary(contrasts))
  result = subset(result, p.value <= 0.05)
}

stats_testing <-function(data, value_order, two_factor=FALSE) {
  #data$ParticipantID <- factor(data$ParticipantID)
  #data$value <- factor(data$value, ordered = TRUE, levels = value_order)
  
  if (!two_factor){
    model.result <- art(value ~ factor_one + Error(ParticipantID), data=data)
    model.aov<-anova(model.result)
    model.contrasts<- art.con(model.result, "factor_one")
    #model.df <- as.data.frame(summary(model.contrasts))
    
    output <- list(
      model.result,
      model.aov,
      model.contrasts,
      filter_contrasts(model.contrasts)
    )
    return(output)

  } else {
    model.result <- art(value ~ factor_one*factor_two + Error(ParticipantID), data=data)
    anova_result<-anova(model.result)
    model.df_1 <- art.con(model.result, "factor_one")
    model.df_2 <- art.con(model.result, "factor_two")
    
    output<-list(
      model.result,
      anova_result,
      model.df_1,
      filter_contrasts(model.df_1),
      model.df_2,
      filter_contrasts(model.df_2)
      )
    
    return(output)
    
    #print(art.con(model.result, "factor_one"))
    #print(art.con(model.result, "factor_two"))

  }
  #return(model)
}
```


```{r}
ar_experience_results_q6 = extract_composite_question_with_factors(raw_data, c("Q6$"), common.id_variables, NULL,
                                        c("6"  = "Know what AR is"))

ar_experience_results_q6$value <- revalue(factor(ar_experience_results_q6$value), c( 
"I don't know" = "I don't know",                                                                                  
"No" = "No",                                                                                            
"Yes, but smartphone AR only (e.g. instagram filters, snapchat lenses, IKEA furniture app etc.)" =  "Yes, but\nsmartphone\nAR only",
"Yes, including AR headsets"  = "Yes, inc.\nAR headsets"
  ))

value_order = c(
"No",
"I don't know", 
"Yes, but\nsmartphone\nAR only",     
 "Yes, inc.\nAR headsets"
)

ar_experience_results_q6$value <- factor(ar_experience_results_q6$value, ordered = TRUE, levels = value_order)

ar_experience_results_q6$variable <- "Used AR Before"
q6_plot <- questionnaire_plot(ar_experience_results_q6, "variable")
print(q6_plot)
q6_count <- ar_experience_results_q6 %>% count(value)
q6_count$percentage <- (q6_count$n / no_complete_responses) * 100


#ar_experience_results_q7 = extract_composite_question_with_factors(raw_data, c("Q7$"), common.id_variables, 
#    c("No", 
#      "Yes, but smartphone AR only (e.g. instagram filters, snapchat lenses, IKEA furniture app etc.)",
#        "Yes, including AR headsets"),
#    c("7" = "Used AR Previously"))


ar_experience_results_q7 = extract_composite_question_with_factors(raw_data, c("Q7$"), common.id_variables, 
    NULL,
    c("7" = "Used AR Previously"))



ar_experience_results_q7$value <- revalue(factor(ar_experience_results_q7$value), c( 
"No" = "No",
"Sort of" = "Sort of\n\n",
"Yes" = "Yes"
  ))


ar_experience_results_q7$variable <- "Know what AR is"
q7_plot <- questionnaire_plot(ar_experience_results_q7, "variable")
print(q7_plot)
q7_count <- ar_experience_results_q7 %>% count(value)
q7_count$percentage <- (q7_count$n / no_complete_responses) * 100

print(q6_count)
print(q7_count)

```
Combination of intro questions
```{r}

q6_plot_mod <- q6_plot + theme(axis.title.y=element_blank(),
          axis.text.y=element_blank(),
          axis.ticks.y=element_blank()) + ggtitle("Used AR Before?")
  
 q7_plot_mod <- q7_plot + theme(axis.title.y=element_blank(),
          axis.text.y=element_blank(),
          axis.ticks.y=element_blank()) + ggtitle("Know what an AR headset is?")
 
knowledge_combi <- plot_grid(q6_plot_mod, q7_plot_mod,
          ncol = 2, rel_widths = c(1.0,1.0), rel_heights = c(1.0, 1.0))

print(knowledge_combi)
ExportPlot(knowledge_combi, "knowledge_combi", 9.5, 2.1, doPDF=TRUE)
```



### LOOPING QUESTIONS
# Knowledge of AR capability
Did you know AR headsets have this capability?
```{r}
know_capability.results = extract_composite_question_with_factors(raw_data, c("Q11", "Q23"), common.id_variables, NULL,
                                        c("11" = "know_capability", "27" = "know_capability"),
                                        common.loopfactor)

know_capability.results$factor_one <- fct_rev(fct_relevel( know_capability.results$factor_one, common.looporder))

know_capability.results$value <- revalue(factor(know_capability.results$value), c( 
  "I did not know AR headsets could do this" = "Did not know",
  "I was somewhat aware AR headsets could do this" = "Somewhat aware",
  "I knew AR headsets could do this" = "Aware"
  ))

know_capability.results$value <- fct_relevel( know_capability.results$value, c("Did not know", "Somewhat aware", "Aware"))

know_capability.plot <- questionnaire_plot(know_capability.results, "factor_one") + ggtitle("Did you know AR headsets have this capability?")

ExportPlot(know_capability.plot, "know_capability_plot", 8.5, 3.5, doPDF=TRUE)
print(know_capability.plot)

know_capability.results$value <- factor(know_capability.results$value, ordered = TRUE, levels = c(
  "Did not know", 
  "Somewhat aware",
  "Aware"  
))

model_result<- stats_testing(know_capability.results, NULL, FALSE)
print(model_result[2])
print(model_result[4])

```

## FROM THE PERSPECTIVE OF THE BYSTANDER
# Giving consent
How would you consent to this, if at all?
```{r, fig.width=10}
consent.results = extract_composite_question_with_factors(raw_data, c("Q13", "Q25"), common.id_variables, NULL,
                                        c("13" = "consent", "25" = "consent"),
                                        common.loopfactor, common.relationship)

consent.results$factor_one <- fct_relevel( consent.results$factor_one, common.looporder)

value_order = c(
  "Opt-out - I would never consent to this activity",
  "Opt-out by default, with ability to request your consent",
  "Opt-in by default, with ability to withdraw your consent",
  "Opt-in by default, no consent required"
)

consent.results$value <- factor(consent.results$value, ordered = TRUE, levels = value_order)

consent.results$value <- revalue(factor(consent.results$value), c( 
  "Opt-out - I would never consent to this activity" = "Opt-out - I would never\n consent to this activity",
  "Opt-out by default, with ability to request your consent" = "Opt-out, with ability\nto request your consent" ,
  "Opt-in by default, with ability to withdraw your consent" = "Opt-in, with ability\nto withdraw your consent",
  "Opt-in by default, no consent required" =   "Opt-in by default,\nno consent required"
  ))


consent.stats_results <- stats_testing(consent.results, NULL, TRUE)
print(consent.stats_results[2])
print(consent.stats_results[3])
print(consent.stats_results[4])
print(consent.stats_results[5])

consent.plot <- questionnaire_plot(consent.results, "factor_two", "factor_one", TRUE) + ggtitle("How would you wish to manage your consent to this activity?")
print(consent.plot)
ExportPlot(consent.plot, "consent_plot", 9, 6, doPDF=TRUE)

```
# Revoking consent
```{r, fig.width=8, fig.height=3.5}
revoke_consent.results = extract_composite_question_with_factors(raw_data, c("Q14", "Q26"), common.id_variables, NULL,
                                        c("14" = "revoke.consent", "26" = "revoke.consent"),
                                        common.loopfactor)

revoke_consent.results$factor_one <- fct_rev(fct_relevel( revoke_consent.results$factor_one, common.looporder))

#levels(factor(consent.results$value))

value_order = c(
  "Definitely not",
   "Probably not" ,
  "May or may not",
  "Probably yes"  ,
  "Definitely yes"   
)

revoke_consent.results$value <- factor(revoke_consent.results$value, ordered = TRUE, levels = value_order)
revoke_consent.results$value <- revalue(factor(revoke_consent.results$value), c( 
  "Definitely not"  = "Definitely\nnot",
   "Probably not"  = "Probably\nnot", 
  "May or may not" = "May or\nmay not",
  "Probably yes"  = "Probably\nyes",
  "Definitely yes" = "Definitely\nyes"   
  ))


revoke_consent.stats_results <- stats_testing(revoke_consent.results, NULL, FALSE)
print(revoke_consent.stats_results[2])
print(revoke_consent.stats_results[4])
revoke_consent.plot <- questionnaire_plot(revoke_consent.results, "factor_one")  + ggtitle("Automatic opt-in/out based on pre-provided AR preferences")
print(revoke_consent.plot)
ExportPlot(revoke_consent.plot, "revoke_consent_plot", 8.5, 3.5, doPDF=TRUE)

```

# Concern with AR
```{r}
concern.results = extract_composite_question_with_factors(raw_data, c("Q15", "Q27"), common.id_variables, NULL,
                                        c("15" = "concern", "27" = "concern"),
                                        common.loopfactor)

concern.results$factor_one <- fct_rev(fct_relevel( concern.results$factor_one, common.looporder))

concern.results 
levels(factor(concern.results$value))

value_order = c(
  "Very unconcerning" ,
  "Unconcerning" ,
  "Neutral" ,
  "Somewhat concerning",
  "Very concerning"
)

concern.results$value <- factor(concern.results$value, ordered = TRUE, levels = value_order)


concern.results$value <- revalue(factor(concern.results$value), c( 
  "Very unconcerning" = "Very\nunconcerning",
  "Unconcerning" = "Unconcerning",
  "Neutral" = "Neutral",
  "Somewhat concerning" = "Somewhat\nconcerning\n ",
  "Very concerning" = "Very\nconcerning"
  ))

concern.stats_results <- stats_testing(concern.results, NULL, FALSE)
print(concern.stats_results[2])
print(concern.stats_results[4])
concern.plot <- questionnaire_plot(concern.results, "factor_one") + ggtitle("Concern with Stranger's AR Activity")
print(concern.plot)
ExportPlot(concern.plot, "concern_plot", 8.5, 3.5, doPDF=TRUE)


```
# Concern versus smartphone AR
```{r}
concern_versus_smartphone.results = extract_composite_question_with_factors(raw_data, c("Q16", "Q28"), common.id_variables, NULL,
                                        c("16" = "concern_versus_smartphone", "28" = "concern_versus_smartphone"),
                                        common.loopfactor)

concern_versus_smartphone.results$factor_one <- fct_rev(fct_relevel( concern_versus_smartphone.results$factor_one, common.looporder))

#concern_versus_smartphone.results
#levels(factor(concern_versus_smartphone.results$value))


value_order = c(
  "Much less concerning than smartphones" ,
"Somewhat less concerning",              
"About the same",                       
"Somewhat more concerning",   
"Much more concerning than smartphones" 
)
concern_versus_smartphone.results$value <- factor(concern_versus_smartphone.results$value, ordered = TRUE, levels = value_order)

concern_versus_smartphone.results$value <- revalue(factor(concern_versus_smartphone.results$value), c( 
  "Much less concerning than smartphones" = "Much\nless\nconcerning",
"Somewhat less concerning" = "Somewhat\nless\nconcerning",              
"About the same" = "About\nthe same",                       
"Somewhat more concerning" = "Somewhat\nmore\nconcerning",   
"Much more concerning than smartphones" = "Much\nmore\nconcerning" 
  ))


concern_versus_smartphone.stats_results <- stats_testing(concern_versus_smartphone.results, NULL, FALSE) 
print(concern_versus_smartphone.stats_results[2])
print(concern_versus_smartphone.stats_results[4])
concern_versus_smartphone.plot <- questionnaire_plot(concern_versus_smartphone.results, "factor_one")  + ggtitle("Concern relative to Smartphone AR") #+ guides(fill = guide_legend(nrow = 2))
print(concern_versus_smartphone.plot)
ExportPlot(concern_versus_smartphone.plot, "concern_versus_smartphone_plot", 8.5, 3.5, doPDF=TRUE)


```

# Concern combi plot
```{r, fig.width=11.5, fig.height=4}
concern_versus_smartphone.plot_without_y_labels <- concern_versus_smartphone.plot + 
  theme(axis.title.y=element_blank(),
          axis.text.y=element_blank(),
          axis.ticks.y=element_blank())

concern_plot_mod <- concern.plot + theme(legend.justification = c(1,0))

concern_combi_plot <- plot_grid(concern_plot_mod, concern_versus_smartphone.plot_without_y_labels,
          ncol = 2, rel_widths = c(1.5,0.96))

print(concern_combi_plot)
ExportPlot(concern_combi_plot, "concern_combi_plot", 11.5, 4, doPDF=TRUE)

```


# Awareness preference with and without consent
This is a matrix question, so need to be sure about the formatting here?
19_Q30_1/2
```{r}
awareness_preference_by_consent.results = extract_composite_question_with_factors(raw_data, c("Q18", "Q30"), common.id_variables, NULL,
                                        c("20" = "awareness_preference_by_consent", "30" = "awareness_preference_by_consent"),
                                        common.loopfactor, common.consent)

awareness_preference_by_consent.results$factor_one <- fct_rev(fct_relevel( awareness_preference_by_consent.results$factor_one, common.looporder))

#awareness_preference_by_consent.results 
#levels(factor(awareness_preference_by_consent.results $value))


value_order = c(
"1 - No awareness of activity" ,
"2 - Basic awareness device sensing is active (e.g. LED colour)" ,
"3 - Awareness of activity type sensing is being used for"  ,    
"4 - Full, real-time awareness of what the headset is doing"    
)
awareness_preference_by_consent.results$value <- factor(awareness_preference_by_consent.results$value, ordered = TRUE, levels = value_order)

awareness_preference_by_consent.results$value <- revalue(factor(awareness_preference_by_consent.results$value), c( 
"1 - No awareness of activity" = "No awareness" ,
"2 - Basic awareness device sensing is active (e.g. LED colour)" = "Basic awareness\ndevice active",
"3 - Awareness of activity type sensing is being used for"  = "Awareness of\nactivity type",    
"4 - Full, real-time awareness of what the headset is doing" = "Full, real-time\nawareness"    
  ))


awareness_preference_by_consent.stats_results <- stats_testing(awareness_preference_by_consent.results, NULL, TRUE)
print(awareness_preference_by_consent.stats_results[2])
awareness_preference_by_consent.plot <- questionnaire_plot(awareness_preference_by_consent.results, "factor_one", "factor_two", TRUE) + ggtitle("Blep")
print(awareness_preference_by_consent.plot)
ExportPlot(awareness_preference_by_consent.plot, "awareness_preference_by_consent_plot", 11.5, 4, doPDF=TRUE)


```

## FROM THE PERSPECTIVE OF BEING THE AR USER
# Awareness preference for own headset
```{r}
awareness_preference_headset_informs_others.results = extract_composite_question_with_factors(raw_data, c("Q20", "Q32"), common.id_variables, NULL,
                                        c("20" = "awareness_preference_headset_informs_others", "32" = "awareness_preference_headset_informs_others"),
                                        common.loopfactor)

awareness_preference_headset_informs_others.results$factor_one <- fct_rev(fct_relevel( awareness_preference_headset_informs_others.results$factor_one, common.looporder))

#awareness_preference_headset_informs_others.results 
#levels(factor(awareness_preference_headset_informs_others.results$value))

value_order = c(
"1 - No awareness of activity" ,
"2 - Basic awareness device sensing is active (e.g. LED colour)" ,
"3 - Awareness of activity type sensing is being used for"  ,    
"4 - Full, real-time awareness of what the headset is doing"    
)
awareness_preference_headset_informs_others.results$value <- factor(awareness_preference_headset_informs_others.results$value, ordered = TRUE, levels = value_order)


awareness_preference_headset_informs_others.results$value <- revalue(factor(awareness_preference_headset_informs_others.results$value), c( 
"1 - No awareness of activity" = "No awareness" ,
"2 - Basic awareness device sensing is active (e.g. LED colour)" = "Basic awareness\ndevice active",
"3 - Awareness of activity type sensing is being used for"  = "Awareness of\nactivity type",    
"4 - Full, real-time awareness of what the headset is doing" = "Full, real-time\nawareness"     
  ))

awareness_preference_headset_informs_others.stats_results <- stats_testing(awareness_preference_headset_informs_others.results, NULL, FALSE)
print(awareness_preference_headset_informs_others.stats_results[2])
awareness_preference_headset_informs_others.plot <- questionnaire_plot(awareness_preference_headset_informs_others.results, "factor_one", NULL, FALSE)
print(awareness_preference_headset_informs_others.plot)

```

# Combine bystander and user perspectives
combine awareness_preference_headset_informs_others.results and awareness_preference_by_consent.results

```{r, fig.width=9, fig.height=4}

awareness_preference_by_consent.results$factor_two <- revalue(factor(awareness_preference_by_consent.results$factor_two), c( 
  "With Consent" = "As a bystander\nwith consent",
  "Without Consent" = "As a bystander\nwithout consent"
  ))

awareness_preference_headset_informs_others.results$factor_two <- "As the \nAR user"

combined_data <- rbind(awareness_preference_by_consent.results,awareness_preference_headset_informs_others.results )

# now combined where factor_two tells us perspective (bystander with consent, without consent, and user)

combined_data.stats_results <- stats_testing(combined_data, NULL, TRUE)
print(combined_data.stats_results[2])
print(combined_data.stats_results[3])
print(combined_data.stats_results[4])
print(combined_data.stats_results[5])
print(combined_data.stats_results[6])

combined_data.plot <- questionnaire_plot(combined_data, "factor_one", "factor_two", TRUE) + ggtitle("Preference Toward Awareness of AR Activity...")
print(combined_data.plot)
ExportPlot(combined_data.plot, "awareness_preferences_combined_plot", 9, 4, doPDF=TRUE)

```


### EXIT QUESTIONS

# Comfort with AR (less/more)
```{r}
more_or_less_comfortable_with_ar.results = extract_composite_question_with_factors(raw_data, c("Q34"), common.id_variables, 
                                        c("34" = "more_less_comfortable"))

more_or_less_comfortable_with_ar.results

value_order = c(
"Much more uncomfortable",
"More uncomfortable", 
"Neutral / No change",     
"More comfortable",
"Much more comfortable"
)

more_or_less_comfortable_with_ar.results$value <- factor(more_or_less_comfortable_with_ar.results$value, ordered = TRUE, levels = value_order)

more_or_less_comfortable_with_ar.results$value <- revalue(factor(more_or_less_comfortable_with_ar.results$value), c( 
"Much more uncomfortable" = "Much more\n uncomfortable" ,
"More uncomfortable" = "More \nuncomfortable", 
"Neutral / No change" = "Neutral /\nNo change",     
"More comfortable" = "More\ncomfortable",
"Much more comfortable" = "Much more\ncomfortable"
  ))


more_or_less_comfortable_with_ar.plot <- questionnaire_plot(more_or_less_comfortable_with_ar.results, "factor_one", NULL, FALSE) +  
  theme(axis.title.y=element_blank(),
          axis.text.y=element_blank(),
          axis.ticks.y=element_blank()) + ggtitle("Retrospective - More or less comfortable with AR")
print(more_or_less_comfortable_with_ar.plot)

```

# Comfort with AR generally
```{r}
how_comfortable_with_ar.results = extract_composite_question_with_factors(raw_data, c("Q35"), common.id_variables, 
                                        c("35" = "how_comfortable_with_ar"))

how_comfortable_with_ar.results

value_order = c(
"Extremely uncomfortable" ,
"Somewhat uncomfortable" ,
 "Neither comfortable nor uncomfortable" ,
 "Somewhat comfortable"    ,
"Extremely comfortable"   
)

how_comfortable_with_ar.results$value <- factor(how_comfortable_with_ar.results$value, ordered = TRUE, levels = value_order)

how_comfortable_with_ar.results$value <- revalue(factor(how_comfortable_with_ar.results$value), c( 
"Extremely uncomfortable" = "Extremely\nuncomfortable",
"Somewhat uncomfortable" = "Somewhat\nuncomfortable",
 "Neither comfortable nor uncomfortable" ="Neither comfortable\nnor uncomfortable",
 "Somewhat comfortable" ="Somewhat\ncomfortable" ,
"Extremely comfortable" = "Extremely\ncomfortable"  
  ))

how_comfortable_with_ar.plot <- questionnaire_plot(how_comfortable_with_ar.results, "factor_one", NULL, FALSE) +  
  theme(axis.title.y=element_blank(),
          axis.text.y=element_blank(),
          axis.ticks.y=element_blank()) + ggtitle("Retrospective - Comfort with Everyday Augmented Reality")
print(how_comfortable_with_ar.plot)

```

Combined comfort

```{r, fig.width=11.5, fig.height=2}

comfort_combi <- plot_grid(more_or_less_comfortable_with_ar.plot, how_comfortable_with_ar.plot,
          ncol = 2, rel_widths = c(1.0,1.0))

print(comfort_combi)
ExportPlot(comfort_combi, "comfort_combi", 11.5, 2, doPDF=TRUE)
```

