<commit_before>/* ************************************ */
/* Define helper functions */
/* ************************************ */
function getDisplayElement() {
  $('<div class = display_stage_background></div>').appendTo('body')
  return $('<div class = display_stage></div>').appendTo('body')
}

function evalAttentionChecks() {
  var check_percent = 1
  if (run_attention_checks) {
    var attention_check_trials = jsPsych.data.getTrialsOfType('attention-check')
    var checks_passed = 0
    for (var i = 0; i < attention_check_trials.length; i++) {
      if (attention_check_trials[i].correct === true) {
        checks_passed += 1
      }
    }
    check_percent = checks_passed / attention_check_trials.length
  }
  return check_percent
}

function addID() {
  jsPsych.data.addDataToLastTrial({
    'exp_id': 'emotion_regulation'
  })
}

var getInstructFeedback = function() {
  return '<div class = centerbox><p class = "center-block-text">' + feedback_instruct_text +
    '</p></div>'
}

var getChoiceText = function() {
  var options = jsPsych.randomization.shuffle(['Distract', 'Reappraise'])
  var choice_text = '<div class = leftBox><div class = center-text>' + options[0] +
    '</div></div>' + '<div class = rightBox><div class = center-text>' + options[1] +
    '</div></div>'
  return choice_text
}

var getTrainingInstruct = function() {
  var instructions = trainingVars.instruction.shift()
  var instruct_text = ''
  if (instructions == 'distract') {
    instruct_text =
      '<div class = centerbox><div class = center-block-text>For this trial, think about something that is emotionally neutral (distract).</div></div>'
  } else if (instructions == 'reappraise') {
    instruct_text =
      '<div class = centerbox><div class = center-block-text>For this trial, thinking about the image in a way that reduces its negative meaning (reappraisal).</div></div>'
  }
  return instruct_text
}

var getTrainingImage = function() {
  var intensity = trainingVars.intense.shift()
  var stim = ''
  if (intensity == 'high') {
    stim = base_path + 'high_intensity/' + high_intensity_stims.shift()
  } else {
    stim = base_path + 'low_intensity/' + low_intensity_stims.shift()
  }
  return '<div class = imageBox><img class = image src = ' + stim + ' </img></div>'
}

var getPracticeInstruct = function() {
  var instructions = practiceVars.instruction.shift()
  var instruct_text = ''
  if (instructions == 'choose') {
    instruct_text =
      '<div class = centerbox><div class = center-block-text>For this trial, choose whether to think of something emotionally neutral (distract) or think about the image in a way that reduces its negative meaning (reppraisal).</div></div>'
  } else if (instructions == 'distract') {
    instruct_text =
      '<div class = centerbox><div class = center-block-text>For this trial, think about something that is emotionally neutral (distract).</div></div>'
  } else if (instructions == 'reappraise') {
    instruct_text =
      '<div class = centerbox><div class = center-block-text>For this trial, thinking about the image in a way that reduces its negative meaning (reappraisal).</div></div>'
  }
  return instruct_text
}

var getPracticeImage = function() {
  var intensity = practiceVars.intense.shift()
  var stim = ''
  if (intensity == 'high') {
    stim = base_path + 'high_intensity/' + high_intensity_stims.shift()
  } else {
    stim = base_path + 'low_intensity/' + low_intensity_stims.shift()
  }
  return '<div class = imageBox><img class = image src = ' + stim + ' </img></div>'
}

var setImage = function() {
  var intensity = stim_intensities.shift()
  if (intensity == 'high') {
    curr_stim = 'high_intensity/' + high_intensity_stims.shift()
  } else {
    curr_stim = 'low_intensity/' + low_intensity_stims.shift()
  }
}

var getImage = function() {
  var stim = base_path + curr_stim
  return '<div class = imageBox><img class = image src = ' + stim + ' </img></div>'
}

/* ************************************ */
/* Define experimental variables */
/* ************************************ */
// generic task variables
var run_attention_checks = false
var attention_check_thresh = 0.65
var sumInstructTime = 0 //ms
var instructTimeThresh = 0 ///in seconds

// task specific variables
var training_len = 4
var practice_len = 8
var exp_len = 30
var curr_trial = 0
var choices = [37, 39]

var base_path = '/static/experiments/emotion_regulation/images/'
var low_intensity_stims = ['1270.JPG', '1301.JPG', '2278.JPG', '2312.JPG', '2490.JPG', '2691.JPG',
  '2700.JPG', '6010.JPG', '6020.JPG', '6190.JPG', '6241.JPG', '6836.JPG', '7300.JPG', '9101.JPG',
  '9102.JPG', '9120.JPG', '9140.JPG', '9160.JPG', '9171.JPG', '9440.JPG', '9470.JPG'
]
var low_intensity_stims = jsPsych.randomization.shuffle(low_intensity_stims)
var high_intensity_stims = ['2053.JPG', '2800.JPG', '3000.JPG', '3010.JPG', '3015.JPG', '3030.JPG',
  '3068.JPG', '3140.JPG', '3150.JPG', '3180.JPG', '3230.JPG', '3261.JPG', '3530.JPG', '6831.JPG',
  '9181.JPG', '9252.JPG', '9301.JPG', '9320.JPG', '9433.JPG', '9410.JPG', '9420.JPG'
]
var high_intensity_stims = jsPsych.randomization.shuffle(high_intensity_stims)
var stim_intensities = jsPsych.randomization.repeat(['high', 'low'], exp_len / 2)
var trainingVars = {
  'instruction': [],
  'intense': []
}
if (Math.random() < 0.5) {
  trainingVars.instruction.push('distract');
  trainingVars.intense.push('low');
  trainingVars.instruction.push('distract');
  trainingVars.intense.push('high');
  trainingVars.instruction.push('reappraise');
  trainingVars.intense.push('low');
  trainingVars.instruction.push('reappraise');
  trainingVars.intense.push('high');
} else {
  trainingVars.instruction.push('reappraise');
  trainingVars.intense.push('low');
  trainingVars.instruction.push('reappraise');
  trainingVars.intense.push('high');
  trainingVars.instruction.push('distract');
  trainingVars.intense.push('low');<commit_msg>implemented image preloading in emotion regulation task<commit_after>/* ************************************ */
/* Define helper functions */
/* ************************************ */
function getDisplayElement() {
  $('<div class = display_stage_background></div>').appendTo('body')
  return $('<div class = display_stage></div>').appendTo('body')
}

function evalAttentionChecks() {
  var check_percent = 1
  if (run_attention_checks) {
    var attention_check_trials = jsPsych.data.getTrialsOfType('attention-check')
    var checks_passed = 0
    for (var i = 0; i < attention_check_trials.length; i++) {
      if (attention_check_trials[i].correct === true) {
        checks_passed += 1
      }
    }
    check_percent = checks_passed / attention_check_trials.length
  }
  return check_percent
}

function addID() {
  jsPsych.data.addDataToLastTrial({
    'exp_id': 'emotion_regulation'
  })
}

var getInstructFeedback = function() {
  return '<div class = centerbox><p class = "center-block-text">' + feedback_instruct_text +
    '</p></div>'
}

var getChoiceText = function() {
  var options = jsPsych.randomization.shuffle(['Distract', 'Reappraise'])
  var choice_text = '<div class = leftBox><div class = center-text>' + options[0] +
    '</div></div>' + '<div class = rightBox><div class = center-text>' + options[1] +
    '</div></div>'
  return choice_text
}

var getTrainingInstruct = function() {
  var instructions = trainingVars.instruction.shift()
  var instruct_text = ''
  if (instructions == 'distract') {
    instruct_text =
      '<div class = centerbox><div class = center-block-text>For this trial, think about something that is emotionally neutral (distract).</div></div>'
  } else if (instructions == 'reappraise') {
    instruct_text =
      '<div class = centerbox><div class = center-block-text>For this trial, thinking about the image in a way that reduces its negative meaning (reappraisal).</div></div>'
  }
  return instruct_text
}

var getTrainingImage = function() {
  var intensity = trainingVars.intense.shift()
  var stim = ''
  if (intensity == 'high') {
    stim = base_path + 'high_intensity/' + high_intensity_stims.shift()
  } else {
    stim = base_path + 'low_intensity/' + low_intensity_stims.shift()
  }
  return '<div class = imageBox><img class = image src = ' + stim + ' </img></div>'
}

var getPracticeInstruct = function() {
  var instructions = practiceVars.instruction.shift()
  var instruct_text = ''
  if (instructions == 'choose') {
    instruct_text =
      '<div class = centerbox><div class = center-block-text>For this trial, choose whether to think of something emotionally neutral (distract) or think about the image in a way that reduces its negative meaning (reppraisal).</div></div>'
  } else if (instructions == 'distract') {
    instruct_text =
      '<div class = centerbox><div class = center-block-text>For this trial, think about something that is emotionally neutral (distract).</div></div>'
  } else if (instructions == 'reappraise') {
    instruct_text =
      '<div class = centerbox><div class = center-block-text>For this trial, thinking about the image in a way that reduces its negative meaning (reappraisal).</div></div>'
  }
  return instruct_text
}

var getPracticeImage = function() {
  var intensity = practiceVars.intense.shift()
  var stim = ''
  if (intensity == 'high') {
    stim = base_path + 'high_intensity/' + high_intensity_stims.shift()
  } else {
    stim = base_path + 'low_intensity/' + low_intensity_stims.shift()
  }
  return '<div class = imageBox><img class = image src = ' + stim + ' </img></div>'
}

var setImage = function() {
  var intensity = stim_intensities.shift()
  if (intensity == 'high') {
    curr_stim = 'high_intensity/' + high_intensity_stims.shift()
  } else {
    curr_stim = 'low_intensity/' + low_intensity_stims.shift()
  }
}

var getImage = function() {
  var stim = base_path + curr_stim
  return '<div class = imageBox><img class = image src = ' + stim + ' </img></div>'
}

/* ************************************ */
/* Define experimental variables */
/* ************************************ */
// generic task variables
var run_attention_checks = false
var attention_check_thresh = 0.65
var sumInstructTime = 0 //ms
var instructTimeThresh = 0 ///in seconds

// task specific variables
var training_len = 4
var practice_len = 8
var exp_len = 30
var curr_trial = 0
var choices = [37, 39]

var base_path = '/static/experiments/emotion_regulation/images/'
var low_intensity_stims = ['1270.JPG', '1301.JPG', '2278.JPG', '2312.JPG', '2490.JPG', '2691.JPG',
  '2700.JPG', '6010.JPG', '6020.JPG', '6190.JPG', '6241.JPG', '6836.JPG', '7300.JPG', '9101.JPG',
  '9102.JPG', '9120.JPG', '9140.JPG', '9160.JPG', '9171.JPG', '9440.JPG', '9470.JPG'
]
var low_intensity_stims = jsPsych.randomization.shuffle(low_intensity_stims)
var high_intensity_stims = ['2053.JPG', '2800.JPG', '3000.JPG', '3010.JPG', '3015.JPG', '3030.JPG',
  '3068.JPG', '3140.JPG', '3150.JPG', '3180.JPG', '3230.JPG', '3261.JPG', '3530.JPG', '6831.JPG',
  '9181.JPG', '9252.JPG', '9301.JPG', '9320.JPG', '9433.JPG', '9410.JPG', '9420.JPG'
]
var high_intensity_stims = jsPsych.randomization.shuffle(high_intensity_stims)
var stim_intensities = jsPsych.randomization.repeat(['high', 'low'], exp_len / 2)
var trainingVars = {
  'instruction': [],
  'intense': []
}

var images = []
for (var i = 0; i < low_intensity_stims.length; i++) {
  images.push(base_path + low_intensity_stims[i])
  images.push(base_path + high_intensity_stims[i])
}
//preload images
jsPsych.pluginAPI.preloadImages(images)

if (Math.random() < 0.5) {
  trainingVars.instruction.push('distract');
  trainingVars.intense.push('low');
  trainingVars.instruction.push('distract');
  trainingVars.intense.push('high');
  trainingVars.instruction.push('reappraise');
  trainingVars.intense.push('low');
  trainingVars.instruction.push('reappraise');
  trainingVars.intense.push('high');
} else {
  trainingVars.instruction.push('reappraise');
  trainingVars.intense.push('low');
  trainingVars.instruction.push('reappraise');
  trainingVars.intense.push('high');
  trainingVars.instruction.push('distract');
  trainingVars.intense.push('low');
{'fraction_non_alphanumeric': 0.17650458185420623, 'fraction_numerical': 0.031618921819532735, 'mean_word_length': 4.422560429722471, 'pattern_counts': {'":': 0, '<': 104, '<?xml version=': 0, '>': 93, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3691318', 'n_tokens_mistral': 4306, 'n_tokens_neox': 4015, 'n_words': 901}