Skip to content
This repository has been archived by the owner on Mar 1, 2024. It is now read-only.

Commit

Permalink
feat: 🎸 add showImage trial
Browse files Browse the repository at this point in the history
  • Loading branch information
Rashi1997 committed Aug 10, 2020
1 parent 3e0949d commit 6071ede
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 15 deletions.
22 changes: 9 additions & 13 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,12 @@ const defaultconfig = { USE_PHOTODIODE: false, USE_EEG: false, IS_ELECTRON: tru


module.exports = {
init: function(_config){
return _.extend(defaultconfig,_config)
}
};

fs.readdir(trials, (err, files) => {
files.forEach(file => {
let filename = file.split('.')[0]
module.exports = {
filename: require(trials+'/'+file)
};
});
});
init: function(_config){
return _.extend(defaultconfig,_config)
},
countdown: require('./trials/countdown.js'),
showMessage: require('./trials/showMessage.js'),
fixation: require('./trials/fixation.js'),
userId: require('./trials/userId.js'),
showImage: require('./trials/showImage.js')
};
12 changes: 12 additions & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// add a random number between 0 and offset to the base number
const jitter = (base, offset) => (
base + Math.floor(Math.random() * Math.floor(offset))
)

// add a random number between 0 and 50 to the base number
const jitter50 = (base) => jitter(base, 50)

module.exports ={
jitter,
jitter50
}
28 changes: 28 additions & 0 deletions trials/showImage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const { photodiodeGhostBox, pdSpotEncode } = require('../lib/markup/photodiode')
const $ = require('jquery')
const { jitter50 } = require('../lib/utils')


module.exports = function(responseType, duration, config, image, imageHeight=600, imageWidth=600, responseEndsTrial=false, taskCode = null, numBlinks = 1, buttons) {


return {
type: responseType,
stimulus: image,
prompt: (config.USE_PHOTODIODE)?photodiodeGhostBox():null,
response_ends_trial: responseEndsTrial,
trial_duration: jitter50(duration),
choices: buttons,
on_load: () => {
$('#jspsych-image-keyboard-response-stimulus').addClass('image')
$('#jspsych-image-keyboard-response-stimulus').height(imageHeight)
$('#jspsych-image-keyboard-response-stimulus').width(imageWidth)
$('html').css('cursor', 'none')
(taskCode!=null)?pdSpotEncode(taskCode, numBlinks, config):null
},
on_finish: (data) => {
data.code = code
$('html').css('cursor', 'auto')
}
}
}
4 changes: 2 additions & 2 deletions trials/userId.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const { baseStimulus } = require('../lib/markup/stimuli')
* @param {object} config - The configuration object for USE_PHOTODIODE, USE_EEG, IS_ELECTRON and USE_MTURK flags, by default only IS_ELECTRON is set to be true.
* @param {string} setIdMessage - Onscreen text for setting user id or for the input box to enter patient id.
* @param {boolean} responseEndsTrial - True if the trial ends on response,false if the trial waits for the duration, by default false value.
* @param {boolean} REACT_APP_PATIENT_ID - The patient id to show when requesting a patient ID, if not set default is empty.
* @param {boolean} defaultPatientId - The patient id to show when requesting a patient ID, if not set default is empty.
*/


Expand All @@ -30,7 +30,7 @@ module.exports = function(jsPsych, responseType, duration, config, setIdMessage
else {
return {
type: 'survey_text',
questions: [{ prompt: baseStimulus(`<h1>${setIdMessage}</h1>`, true), value: REACT_APP_PATIENT_ID}],
questions: [{ prompt: baseStimulus(`<h1>${setIdMessage}</h1>`, true), value: defaultPatientId}],
on_finish: (data) => {
const patientId = JSON.parse(data.responses)['Q0']
jsPsych.data.addProperties({patient_id: patientId, timestamp: Date.now()})
Expand Down

0 comments on commit 6071ede

Please sign in to comment.