This repository has been archived by the owner on Mar 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from brown-ccv/feat-attention-checks
Feat: Attention Checks
- Loading branch information
Showing
8 changed files
with
178 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
const multiSurvey = require("../trials/multiSurvey.js"); | ||
|
||
describe("multiSurvey trial", () => { | ||
it(" with same ans choices for all questions", () => { | ||
const preamble = "Answer the below questions"; | ||
const options = { | ||
preamble: preamble, | ||
prompts: ["hello?", "1?", "2?"], | ||
ansChoices: { choices: ["no", "yes"] }, | ||
}; | ||
const questions = [ | ||
{ prompt: "hello?", options: ["no", "yes"], required: true }, | ||
{ prompt: "1?", options: ["no", "yes"], required: true }, | ||
{ prompt: "2?", options: ["no", "yes"], required: true }, | ||
]; | ||
const result = multiSurvey(options); | ||
expect(result.preamble).toContain(preamble); | ||
expect(result.questions).toEqual(questions); | ||
}); | ||
|
||
it(" with different ans choices for each questions", () => { | ||
const preamble = "Answer the below questions"; | ||
const options = { | ||
preamble: preamble, | ||
prompts: ["hello?", "1?", "2?"], | ||
ansChoices: { | ||
1: ["no", "yes", "maybe"], | ||
2: ["not at all", "yes"], | ||
3: ["nope", "yeah"], | ||
}, | ||
}; | ||
const questions = [ | ||
{ prompt: "hello?", options: ["no", "yes", "maybe"], required: true }, | ||
{ prompt: "1?", options: ["not at all", "yes"], required: true }, | ||
{ prompt: "2?", options: ["nope", "yeah"], required: true }, | ||
]; | ||
const result = multiSurvey(options); | ||
expect(result.preamble).toContain(preamble); | ||
expect(result.questions).toEqual(questions); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const slider = require("../trials/slider.js"); | ||
|
||
describe("slider trial", () => { | ||
it("slider with require movement", () => { | ||
const message = "Move the slider to the right."; | ||
const result = slider( | ||
message); | ||
const data = { | ||
prompt: null, | ||
answer: null, | ||
response: "response", | ||
}; | ||
result.on_finish(data); | ||
expect(result.stimulus).toContain(message); | ||
expect(result.require_movement).toEqual(true); | ||
expect(data.prompt).toEqual([message]); | ||
expect(data.answer).toEqual([data.response]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const survey = require("../trials/survey.js"); | ||
|
||
describe("survey trial", () => { | ||
it("survey with require movement", () => { | ||
const message = "What is your age?"; | ||
const result = survey( | ||
{message:message}); | ||
const data = { | ||
prompt: null, | ||
answer: null, | ||
responses: JSON.stringify({Q0:"response"}), | ||
}; | ||
result.on_finish(data); | ||
expect(result.questions[0].prompt).toContain(message); | ||
expect(data.prompt[0]).toContain(message); | ||
expect(data.answer).toEqual("response"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
* @description | ||
* Builds a multi choice/select survey trial. | ||
* @module | ||
* @param {Object} options | ||
* @param {string} options.responseType - This tells jsPsych which plugin file to use to run the trial. (default: 'survey_multi_choice') | ||
* @param {string} options.preamble - HTML formatted string to display at the top of the page above all the questions. (default: empty string) | ||
* @param {string|Array} options.prompts - The question prompts, this can be a string (one question) or an Array of strings (multiple questions) (default: "") | ||
* @param {Object} options.ansChoices - Object consisting of the key as the answer choice name and value as the array of answer choices. (default: {}) | ||
*/ | ||
|
||
module.exports = function (options) { | ||
const defaults = { | ||
responseType: "survey_multi_choice", | ||
preamble: "", | ||
prompts: [], | ||
ansChoices: {}, | ||
}; | ||
const { responseType, preamble, prompts, ansChoices } = { | ||
...defaults, | ||
...options, | ||
}; | ||
|
||
// setting questions from prompts and answer choices | ||
let questions = []; | ||
const answers = Object.values(ansChoices); | ||
prompts.forEach(function (prompt, index) { | ||
let options = answers.length === 1 ? answers[0] : answers[index]; | ||
questions.push({ | ||
prompt: prompt, | ||
options, | ||
required: true, | ||
}); | ||
}); | ||
|
||
return { | ||
type: responseType, | ||
preamble: preamble, | ||
questions: questions, | ||
on_finish: (data) => { | ||
window.scrollTo(0, 0); | ||
data.prompt = prompts; | ||
data.ans_choices = [ansChoices]; | ||
data.answer = [{ answer: JSON.parse(data.responses) }]; | ||
}, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
* @description | ||
* Builds a trial with a onscreen message and allows the subject to respond by dragging a slider. | ||
* @module | ||
* @param {string} message - The string to be displayed, this can be formatted as an HTML string. (default: empty string) | ||
*/ | ||
|
||
module.exports = function (message = "") { | ||
return { | ||
type: "html_slider_response", | ||
require_movement: true, | ||
stimulus: message, | ||
on_finish: (data) => { | ||
data.prompt = [message]; | ||
data.answer = [data.response]; | ||
}, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const { baseStimulus } = require("../lib/markup/stimuli"); | ||
|
||
/** | ||
* @description | ||
* Builds a trial with a question and with free response text fields. The subject types in answers. | ||
* @module | ||
* @param {Object} options | ||
* @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.message - Onscreen message to be shown in the trial. (default: "") | ||
*/ | ||
|
||
module.exports = function (options) { | ||
const defaults = { | ||
stimulus: "", | ||
message: "", | ||
}; | ||
const { stimulus, message } = { ...defaults, ...options }; | ||
|
||
const stimulusOrMessage = | ||
message !== "" ? baseStimulus(`<h1>${message}</h1>`, true) : stimulus; | ||
|
||
return { | ||
type: "survey_text", | ||
questions: [{ prompt: stimulusOrMessage, required: true }], | ||
on_finish: (data) => { | ||
data.prompt = [stimulusOrMessage]; | ||
data.answer = JSON.parse(data.responses)["Q0"]; | ||
}, | ||
}; | ||
}; |