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

Commit

Permalink
fix: 🐛 PR fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Rashi1997 committed Feb 11, 2021
1 parent 6f17b2f commit a6251d7
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 23 deletions.
6 changes: 3 additions & 3 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ 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)
// add a random number between 0 and x to the base number
const jitterx = (base, x) => jitter(base, x)

module.exports ={
jitter,
jitter50
jitterx
}
6 changes: 3 additions & 3 deletions trials/countdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ const _ = require("lodash");
* @param {Object} options
* @param {number} options.duration - trial duration in milliseconds. (default: 1000)
* @param {string} options.text - (optional) text for the countdown. (default: "")
* @param {number} options.time - start number for the countdown. (default: 10)
* @param {number} options.time - start number for the countdown. (default: 3)
*/

module.exports = function (options) {
const defaults = {
duration: 1000,
text: "",
time: 10,
time: 3,
};
const { duration, text, time } = { defaults, ...options };
const { duration, text, time } = { ...defaults, ...options };
const times = _.range(time, 0, -1);
const timeline = times.map((val) => {
return { prompt: `<h1>${val}</h1>` };
Expand Down
10 changes: 6 additions & 4 deletions trials/fixation.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const {
pdSpotEncode,
photodiodeGhostBox,
} = require("../lib/markup/photodiode");
const { jitter50 } = require("../lib/utils");
const { jitterx } = require("../lib/utils");

/**
* @description
Expand All @@ -15,18 +15,20 @@ const { jitter50 } = require("../lib/utils");
* @param {boolean} config.USE_ELECTRON - USE_ELECTRON flag
* @param {boolean} config.USE_MTURK - USE_MTURK flag
* @param {Object} options
* @param {number} options.duration - trial duration in milliseconds. (default: 1000)
* @param {number} options.duration - trial duration in milliseconds jittered with the jitter param. (default: 1000)
* @param {number} options.jitter - jitter range (0-jitter) to add from to the trial duration (default: 50)
* @param {number} options.taskCode - Task code to be saved into data log (default: 1)
* @param {number} options.numBlinks - Number of times the pulse needs to be repeated for photodiode box, when USE_PHOTODIODE is set true. (default: 1)
*/

module.exports = function (config, options) {
const defaults = {
duration: 1000,
jitter: 50,
taskCode: 1,
numBlinks: 1,
};
const { duration, taskCode, numBlinks } = {
const { duration, jitter, taskCode, numBlinks } = {
...defaults,
...options,
};
Expand All @@ -39,7 +41,7 @@ module.exports = function (config, options) {
type: "html_keyboard_response",
stimulus: stimulus,
response_ends_trial: false,
trial_duration: jitter50(duration),
trial_duration: jitterx(duration, jitter),
on_load: () => pdSpotEncode(taskCode, numBlinks, config),
on_finish: (data) => (data.code = taskCode),
};
Expand Down
19 changes: 10 additions & 9 deletions trials/showImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const {
pdSpotEncode,
} = require("../lib/markup/photodiode");
const $ = require("jquery");
const { jitter50 } = require("../lib/utils");
const { jitterx } = require("../lib/utils");

/**
* @description
Expand All @@ -15,27 +15,28 @@ const { jitter50 } = require("../lib/utils");
* @param {boolean} config.USE_EEG - USE_EEG flag
* @param {boolean} config.USE_ELECTRON - USE_ELECTRON flag
* @param {boolean} config.USE_MTURK - USE_MTURK flag
* @param {string} image - The path of the image file to be displayed.
* @param {Object} options
* @param {number} options.duration - trial duration in milliseconds. (default: 1000)
* @param {string} options.image - The path of the image file to be displayed. (default: a blue dot image)
* @param {number} options.imageHeight - Set the height of the image in pixels. If left null (no value specified), then the image will display at its natural height. (default: 600)
* @param {number} options.imageWidth - Set the width of the image in pixels. If left null (no value specified), then the image will display at its natural width. (default: 600)
* @param {number} options.duration - trial duration in milliseconds jittered with the jitter param. (default: 1000)
* @param {number} options.jitter - jitter range (0-jitter) to add from to the trial duration (default: 50)
* @param {number} options.imageHeight - Set the height of the image in pixels. (default: 600)
* @param {number} options.imageWidth - Set the width of the image in pixels. (default: 600)
* @param {number} options.taskCode - Task code to be saved into data log (default: 1)
* @param {number} options.numBlinks - Number of times the pulse needs to be repeated for photodiode box, when USE_PHOTODIODE is set true. (default: 1)
*/

module.exports = function (config, options) {
module.exports = function (config, image, options) {
const defaults = {
duration: 1000,
image: "../img/blue.png",
jitter: 50,
imageHeight: 600,
imageWidth: 600,
taskCode: 1,
numBlinks: 1,
};
const {
duration,
image,
jitter,
imageHeight,
imageWidth,
taskCode,
Expand All @@ -47,7 +48,7 @@ module.exports = function (config, options) {
stimulus: image,
prompt: config.USE_PHOTODIODE ? photodiodeGhostBox() : "",
response_ends_trial: false,
trial_duration: jitter50(duration),
trial_duration: jitterx(duration, jitter),
on_load: () => {
$("#jspsych-image-keyboard-response-stimulus").addClass("image");
$("#jspsych-image-keyboard-response-stimulus").height(imageHeight);
Expand Down
8 changes: 4 additions & 4 deletions trials/userId.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@ const { baseStimulus } = require("../lib/markup/stimuli");
* @param {number} options.duration - trial duration in milliseconds. (default: 1000)
* @param {string} options.stimulus - Onscreen stimulus in HTML to be shown in the trial, if not set default text is empty. If the stimulus is not provided, message should be provided as a string. (default: "")
* @param {string} options.setIdMessage - Onscreen text for setting user id or for the input box to enter patient id. (default: "")
* @param {string} options.defaultPatientId - The patient id to show when requesting a patient ID. (default: "")
* @param {string} options.defaultId - The patient id to show when requesting a patient ID. (default: "")
*/

module.exports = function (jsPsych, config, options) {
const defaults = {
duration: 1000,
stimulus: "",
setIdMessage: "",
defaultPatientId: "",
defaultId: "",
};
const {
duration,
stimulus,
setIdMessage,
defaultPatientId,
defaultId,
} = { ...defaults, ...options };

const stimulusOrMessage =
Expand All @@ -55,7 +55,7 @@ module.exports = function (jsPsych, config, options) {
questions: [
{
prompt: baseStimulus(`<h1>${setIdMessage}</h1>`, true),
value: defaultPatientId,
value: defaultId,
},
],
on_finish: (data) => {
Expand Down

0 comments on commit a6251d7

Please sign in to comment.