remove XAB plugin

This commit is contained in:
Josh de Leeuw 2018-01-03 14:05:11 -05:00
parent f7966aeaf1
commit 6abdd01d7e
7 changed files with 0 additions and 555 deletions

View File

@ -1,51 +0,0 @@
# jspsych-xab plugin
The XAB-html plugin displays an HTML object stimulus (X). After a short gap, the plugin displays two additional stimuli (A and B). The subject selects which of the two stimuli matches X using the keyboard.
## Parameters
Parameters with a default value of *undefined* must be specified. Other parameters can be left unspecified if the default value is acceptable.
Parameter | Type | Default Value | Description
----------|------|---------------|------------
stimuli | array | *undefined* | Array of two or three elements. If it is two elements, then the plugin will show the first element as X and as the target during the A/B portion (the second element will be the foil). If it is three elements, then the first is X the second is the target (A) and the third is the foil (B). This is useful if X and A are not identical, but A is still the correct choice (e.g., a categorization experiment where the goal is to pick the item that is in the same category). Stimuli are html strings.
left_key | numeric or string | 'Q' | Which key the subject should press to indicate that the target is on the left side.
right_key | numeric or string | 'P' | Which key the subject should press to indicate that the target is on the right side.
prompt | string | null | This string can contain HTML markup. Any content here will be displayed below the stimulus. The intention is that it can be used to provide a reminder about the action the subject is supposed to take (e.g., which key to press).
timing_x | numeric | 1000 | How long to show the X stimulus for in milliseconds.
timing_xab_gap | numeric | 1000 | How long to show a blank screen in between X and AB in milliseconds.
timing_ab | numeric | null | How long to show A and B in milliseconds. If the value of this parameter is null, then the stimuli will remain on the screen until a response is given.
timing_response | numeric | null | The maximum duration to wait for a response, measured from the onset of the AB portion of the trial. If null, then the trial will wait indefinitely for a response.
## Data Generated
In addition to the [default data collected by all plugins](overview#datacollectedbyplugins), this plugin collects the following data for each trial.
Name | Type | Value
-----|------|------
stimulus | string | JSON-encoded array of the stimuli used in the trial.
key_press | numeric | Indicates which key the subject pressed. The value is the [numeric key code](http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes) corresponding to the subject's response.
rt | numeric | The response time in milliseconds for the subject to make a response. The time is measured from when the A and B stimuli first appear on the screen until the subject's response.
correct | boolean | True if the subject picks the correct answer.
## Examples
#### Doing an exact match task
```javascript
var block = {
type: 'xab',
stimuli: ['A', 'B'],
prompt: "Press Q if the text you just saw is on the left. Press P if the text you just saw is on the right."
}
```
#### Matching based on a feature
```javascript
var block = {
type: 'xab',
stimuli: ['A', 'B', 'C'],
prompt: "Press Q if the text you just saw is on the left. Press P if the text you just saw is on the right."
}
```

View File

@ -1,51 +0,0 @@
# jspsych-xab plugin
The XAB plugin displays an image. After a short gap, the plugin displays two additional stimuli (A and B). The subject selects which of the two stimuli matches X using the keyboard.
## Parameters
Parameters with a default value of *undefined* must be specified. Other parameters can be left unspecified if the default value is acceptable.
Parameter | Type | Default Value | Description
----------|------|---------------|------------
stimuli | array | *undefined* | Array of two or three elements. If it is two elements, then the plugin will show the first element as X and as the target during the A/B portion (the second element will be the foil). If it is three elements, then the first is X the second is the target (A) and the third is the foil (B). This is useful if X and A are not identical, but A is still the correct choice (e.g., a categorization experiment where the goal is to pick the item that is in the same category). Stimuli can be paths to images, or html strings.
left_key | numeric or string | 'Q' | Which key the subject should press to indicate that the target is on the left side.
right_key | numeric or string | 'P' | Which key the subject should press to indicate that the target is on the right side.
prompt | string | null | This string can contain HTML markup. Any content here will be displayed below the stimulus. The intention is that it can be used to provide a reminder about the action the subject is supposed to take (e.g., which key to press).
timing_x | numeric | 1000 | How long to show the X stimulus for in milliseconds.
timing_xab_gap | numeric | 1000 | How long to show a blank screen in between X and AB in milliseconds.
timing_ab | numeric | null | How long to show A and B in milliseconds. If the value of this parameter is null, then the stimuli will remain on the screen until a response is given.
timing_response | numeric | null | The maximum duration to wait for a response, measured from the onset of the AB portion of the trial. If null, then the trial will wait indefinitely for a response.
## Data Generated
In addition to the [default data collected by all plugins](overview#datacollectedbyplugins), this plugin collects the following data for each trial.
Name | Type | Value
-----|------|------
stimulus | string | JSON-encoded array of the stimuli used in the trial.
key_press | numeric | Indicates which key the subject pressed. The value is the [numeric key code](http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes) corresponding to the subject's response.
rt | numeric | The response time in milliseconds for the subject to make a response. The time is measured from when the A and B stimuli first appear on the screen until the subject's response.
correct | boolean | True if the subject picks the correct answer.
## Examples
#### Doing an exact match task
```javascript
var block = {
type: 'xab',
stimuli: ['img/happy_face.png', 'img/sad_face.png'],
prompt: "Press Q if the face you just saw is on the left. Press P if the face you just saw is on the right."
}
```
#### Matching based on a feature
```javascript
var block = {
type: 'xab',
stimuli: ['img/happy_joe_face.png', 'img/sad_joe_face.png', 'img/sad_fred_face.png'],
prompt: "Press Q if the person you just saw is on the left. Press P if the person you just saw is on the right."
}
```

View File

@ -98,5 +98,3 @@ Plugin | Description
[jspsych‑visual‑search‑circle](jspsych-visual-search-circle) | A customizable visual-search task modelled after [Wang, Cavanagh, & Green (1994)](http://dx.doi.org/10.3758/BF03206946). The subject indicates whether or not a target is present among a set of distractors. The stimuli are displayed in a circle, evenly-spaced, equidistant from a fixation point.
[jspsych‑vsl‑animate‑occlusion](jspsych-vsl-animate-occlusion) | A visual statistical learning paradigm based on [Fiser & Aslin (2002)](http://dx.doi.org/10.1037//0278-7393.28.3.458). A sequence of stimuli are shown in an oscillatory motion. An occluding rectangle is in the center of the display, and the stimuli change when they are behind the rectangle.
[jspsych‑vsl‑grid‑scene](jspsych-vsl-grid-scene) | A visual statistical learning paradigm based on [Fiser & Aslin (2001)](http://dx.doi.org/10.1111/1467-9280.00392). A scene made up of individual stimuli arranged in a grid is shown. This plugin can also generate the HTML code to render the stimuli for use in other plugins.
[jspsych‑xab‑html](jspsych-xab-html) | A two-alternative forced choice task using HTML-formatted stimuli. A target (X) is shown, followed by a brief gap, and then two choices (A & B) are displayed. The subject must pick whichever one matches X (matches is defined however the experimenter wishes; it could be a literal match, or it could be a match on some particular property).
[jspsych‑xab‑image](jspsych-xab-image) | A two-alternative forced choice task using images. A target (X) is shown, followed by a brief gap, and then two choices (A & B) are displayed. The subject must pick whichever one matches X (matches is defined however the experimenter wishes; it could be a literal match, or it could be a match on some particular property).

View File

@ -1,32 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<script src="../jspsych.js"></script>
<script src="../plugins/jspsych-xab-image.js"></script>
<link rel="stylesheet" href="../css/jspsych.css"></link>
<style>
img {
width: 300px;
margin: 20px;
}
</style>
</head>
<body></body>
<script>
var trial = {
type: 'xab-image',
stimuli: ['img/happy_face_1.jpg', 'img/happy_face_2.jpg'],
prompt: "<p>Press Q if the face you just saw is on the left. Press P if the face you just saw is on the right.</p>",
trial_duration: 2000
}
jsPsych.init({
timeline: [trial],
on_finish: function() {
jsPsych.data.displayData();
}
});
</script>
</html>

View File

@ -1,201 +0,0 @@
/* jspsych-xab.js
* Josh de Leeuw
*
* This plugin runs a single XAB trial, where X is an image presented in isolation, and A and B are choices, with A or B being equal to X.
* The subject's goal is to identify whether A or B is identical to X.
*
* documentation: docs.jspsych.org
*
*/
jsPsych.plugins['xab-html'] = (function() {
var plugin = {};
plugin.info = {
name: 'xab-html',
description: '',
parameters: {
stimuli: {
type: jsPsych.plugins.parameterType.HTML_STRING,
pretty_name: 'Stimuli',
array: true,
default: undefined,
description: 'Array of 2 or 3 paths to images.'
},
left_key: {
type: jsPsych.plugins.parameterType.KEYCODE,
pretty_name: 'Left key',
default: 'q',
description: 'Which key the subject should press to indicate that the target is on the left side.'
},
right_key: {
type: jsPsych.plugins.parameterType.KEYCODE,
pretty_name: 'Right key',
default: 'p',
description: 'Which key the subject should press to indicate that the target is on the right side.'
},
prompt: {
type: jsPsych.plugins.parameterType.STRING,
pretty_name: 'Prompt',
default: null,
description: 'Any content here will be displayed below the stimulus.'
},
x_duration: {
type: jsPsych.plugins.parameterType.INT,
pretty_name: 'X duration',
default: 1000,
description: 'How long to show the X stimulus for in milliseconds.'
},
x_durationab_gap: {
type: jsPsych.plugins.parameterType.INT,
pretty_name: 'X durationab gap',
default: 1000,
description: 'How long to show a blank screen in between X and AB in milliseconds.'
},
ab_duration: {
type: jsPsych.plugins.parameterType.INT,
pretty_name: 'AB duration',
default: null,
description: 'How long to show A and B in milliseconds.'
},
trial_duration: {
type: jsPsych.plugins.parameterType.INT,
pretty_name: 'Trial duration',
default: null,
description: 'The maximum duration to wait for a response.'
}
}
}
plugin.trial = function(display_element, trial) {
// unpack the stimuli array
trial.x_path = trial.stimuli[0];
// if there is only a pair of stimuli, then the first is the target and is shown twice.
// if there is a triplet, then the first is X, the second is the target, and the third is foil (useful for non-exact-match XAB).
if (trial.stimuli.length == 2) {
trial.a_path = trial.stimuli[0];
trial.b_path = trial.stimuli[1];
} else {
trial.a_path = trial.stimuli[1];
trial.b_path = trial.stimuli[2];
}
// how we display the content depends on whether the content is
// HTML code or an image path.
display_element.innerHTML = '<div class="jspsych-xab-stimulus" >'+trial.x_path+'</div>';
// start a timer of length trial.x_duration to move to the next part of the trial
jsPsych.pluginAPI.setTimeout(function() {
showBlankScreen();
}, trial.x_duration);
function showBlankScreen() {
// remove the x stimulus
display_element.innerHTML = '';
// start timer
jsPsych.pluginAPI.setTimeout(function() {
showSecondStimulus();
}, trial.x_durationab_gap);
}
function showSecondStimulus() {
// randomize whether the target is on the left or the right
var images = [trial.a_path, trial.b_path];
var target_left = (Math.floor(Math.random() * 2) === 0); // 50% chance target is on left.
if (!target_left) {
images = [trial.b_path, trial.a_path];
}
// show the options
display_element.innerHTML += '<div class="jspsych-xab-stimulus left">'+images[0]+'</div>';
display_element.innerHTML += '<div class="jspsych-xab-stimulus right">'+images[1]+'</div>';
if (trial.prompt !== null) {
display_element.innerHTML += trial.prompt;
}
// if ab_duration is > 0, then we hide the stimuli after ab_duration milliseconds
if (trial.ab_duration > 0) {
jsPsych.pluginAPI.setTimeout(function() {
var matches = display_element.querySelectorAll('.jspsych-xab-stimulus');
for(var i=0; i<matches.length; i++){
matches[i].style.visibility = 'hidden';
}
}, trial.ab_duration);
}
// if trial_duration > 0, then we end the trial after trial_duration milliseconds
if (trial.trial_duration !== null) {
jsPsych.pluginAPI.setTimeout(function() {
end_trial({
rt: null,
correct: false,
key: null
});
}, trial.trial_duration);
}
// create the function that triggers when a key is pressed.
var after_response = function(info) {
var correct = false; // true when the correct response is chosen
if (info.key == trial.left_key) // 'q' key by default
{
if (target_left) {
correct = true;
}
} else if (info.key == trial.right_key) // 'p' key by default
{
if (!target_left) {
correct = true;
}
}
info.correct = correct;
end_trial(info);
};
var end_trial = function(info) {
// kill any remaining setTimeout handlers
jsPsych.pluginAPI.clearAllTimeouts();
jsPsych.pluginAPI.cancelKeyboardResponse(keyboardListener);
// create object to store data from trial
var trial_data = {
"rt": info.rt,
"correct": info.correct,
"stimulus": JSON.stringify([trial.x_path, trial.a_path, trial.b_path]),
"key_press": info.key
};
display_element.innerHTML = ''; // remove all
jsPsych.finishTrial(trial_data);
}
var keyboardListener = jsPsych.pluginAPI.getKeyboardResponse({
callback_function: after_response,
valid_responses: [trial.left_key, trial.right_key],
rt_method: 'date',
persist: false,
allow_held_key: false
});
}
};
return plugin;
})();

View File

@ -1,202 +0,0 @@
/* jspsych-xab.js
* Josh de Leeuw
*
* This plugin runs a single XAB trial, where X is an image presented in isolation, and A and B are choices, with A or B being equal to X.
* The subject's goal is to identify whether A or B is identical to X.
*
* documentation: docs.jspsych.org
*
*/
jsPsych.plugins['xab-image'] = (function() {
var plugin = {};
jsPsych.pluginAPI.registerPreload('xab-image', 'stimuli', 'image');
plugin.info = {
name: 'xab-image',
description: '',
parameters: {
stimuli: {
type: jsPsych.plugins.parameterType.IMAGE,
pretty_name: 'Stimuli',
array: true,
default: undefined,
description: 'Array of 2 or 3 HTML elements.'
},
left_key: {
type: jsPsych.plugins.parameterType.KEYCODE,
pretty_name: 'Left key',
default: 'q',
description: 'Which key the subject should press to indicate that the target is on the left side.'
},
right_key: {
type: jsPsych.plugins.parameterType.KEYCODE,
pretty_name: 'Right key',
default: 'p',
description: 'Which key the subject should press to indicate that the target is on the right side.'
},
prompt: {
type: jsPsych.plugins.parameterType.STRING,
pretty_name: 'Prompt',
default: null,
description: 'Any content here will be displayed below the stimulus.'
},
x_duration: {
type: jsPsych.plugins.parameterType.INT,
pretty_name: 'X duration',
default: 1000,
description: 'How long to show the X stimulus for in milliseconds.'
},
x_durationab_gap: {
type: jsPsych.plugins.parameterType.INT,
pretty_name: 'X durationab gap',
default: 1000,
description: 'How long to show a blank screen in between X and AB in milliseconds.'
},
ab_duration: {
type: jsPsych.plugins.parameterType.INT,
pretty_name: 'AB duration',
default: null,
description: 'How long to show A and B in milliseconds.'
},
trial_duration: {
type: jsPsych.plugins.parameterType.INT,
pretty_name: 'Trial duration',
default: null,
description: 'The maximum duration to wait for a response.'
}
}
}
plugin.trial = function(display_element, trial) {
// unpack the stimuli array
trial.x_path = trial.stimuli[0];
// if there is only a pair of stimuli, then the first is the target and is shown twice.
// if there is a triplet, then the first is X, the second is the target, and the third is foil (useful for non-exact-match XAB).
if (trial.stimuli.length == 2) {
trial.a_path = trial.stimuli[0];
trial.b_path = trial.stimuli[1];
} else {
trial.a_path = trial.stimuli[1];
trial.b_path = trial.stimuli[2];
}
// how we display the content depends on whether the content is
// HTML code or an image path.
display_element.innerHTML = '<img class="jspsych-xab-stimulus" src="'+trial.x_path+'"></img>';
// start a timer of length trial.x_duration to move to the next part of the trial
jsPsych.pluginAPI.setTimeout(function() {
showBlankScreen();
}, trial.x_duration);
function showBlankScreen() {
// remove the x stimulus
display_element.innerHTML = '';
// start timer
jsPsych.pluginAPI.setTimeout(function() {
showSecondStimulus();
}, trial.x_durationab_gap);
}
function showSecondStimulus() {
// randomize whether the target is on the left or the right
var images = [trial.a_path, trial.b_path];
var target_left = (Math.floor(Math.random() * 2) === 0); // 50% chance target is on left.
if (!target_left) {
images = [trial.b_path, trial.a_path];
}
// show the options
display_element.innerHTML += '<img class="jspsych-xab-stimulus left" src="'+images[0]+'"></img>';
display_element.innerHTML += '<img class="jspsych-xab-stimulus right" src="'+images[1]+'"></img>';
if (trial.prompt !== null) {
display_element.innerHTML += trial.prompt;
}
// if ab_duration is > 0, then we hide the stimuli after ab_duration milliseconds
if (trial.ab_duration > 0) {
jsPsych.pluginAPI.setTimeout(function() {
var matches = display_element.querySelectorAll('.jspsych-xab-stimulus');
for(var i=0; i<matches.length; i++){
matches[i].style.visibility = 'hidden';
}
}, trial.ab_duration);
}
// if trial_duration > 0, then we end the trial after trial_duration milliseconds
if (trial.trial_duration !== null) {
jsPsych.pluginAPI.setTimeout(function() {
end_trial({
rt: null,
correct: false,
key: null
});
}, trial.trial_duration);
}
// create the function that triggers when a key is pressed.
var after_response = function(info) {
var correct = false; // true when the correct response is chosen
if (info.key == trial.left_key) // 'q' key by default
{
if (target_left) {
correct = true;
}
} else if (info.key == trial.right_key) // 'p' key by default
{
if (!target_left) {
correct = true;
}
}
info.correct = correct;
end_trial(info);
};
var end_trial = function(info) {
// kill any remaining setTimeout handlers
jsPsych.pluginAPI.clearAllTimeouts();
jsPsych.pluginAPI.cancelKeyboardResponse(keyboardListener);
// create object to store data from trial
var trial_data = {
"rt": info.rt,
"correct": info.correct,
"stimulus": JSON.stringify([trial.x_path, trial.a_path, trial.b_path]),
"key_press": info.key
};
display_element.innerHTML = ''; // remove all
jsPsych.finishTrial(trial_data);
}
var keyboardListener = jsPsych.pluginAPI.getKeyboardResponse({
callback_function: after_response,
valid_responses: [trial.left_key, trial.right_key],
rt_method: 'date',
persist: false,
allow_held_key: false
});
}
};
return plugin;
})();

View File

@ -1,16 +0,0 @@
const root = '../../';
jest.useFakeTimers();
describe('vsl-grid-scene plugin', function(){
beforeEach(function(){
require(root + 'jspsych.js');
require(root + 'plugins/jspsych-vsl-grid-scene.js');
});
test('loads correctly', function(){
expect(typeof window.jsPsych.plugins['vsl-grid-scene']).not.toBe('undefined');
});
});