Merge remote-tracking branch 'origin/dev' into dev

Conflicts:
	docs/markdown_docs/plugins/jspsych-survey-likert.md
	docs/markdown_docs/plugins/jspsych-survey-text.md
This commit is contained in:
Josh de Leeuw 2015-05-27 09:02:40 -04:00
commit 744308e763
16 changed files with 97 additions and 24 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
.DS_Store
Thumbs.db

View File

@ -9,14 +9,15 @@ This table lists the parameters associated with this plugin. Parameters with a d
Parameter | Type | Default Value | Description
----------|------|---------------|------------
stimuli | array | *undefined* | Each element of the array is a stimulus. A stimulus can be either a path to an image file or a string containing valid HTML markup. Each stimulus will be presented in its own trial, and thus the length of this array determines the total number of trials.
is_html | boolean | false | If the elements of the `stimuli` array are strings containing HTML content, then this parameter must be set to true.
is_html | boolean | false | If the elements of the `stimuli` array are strings containing HTML content, then this parameter must be set to true.
key_answer | array | *undefined* | Each element of the array is a [numeric key code](http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes) indicating the correct response for the corresponding trial. The length of this array should match the `stimuli` array.
choices | array | *undefined* | This array contains the keys that the subject is allowed to press in order to respond to the stimulus. Keys can be specified as their [numeric key code](http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes) or as characters (e.g. `'a'`, `'q'`).
choices | array | *undefined* | This array contains the keys that the subject is allowed to press in order to respond to the stimulus. Keys can be specified as their [numeric key code](http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes) or as characters (e.g. `'a'`, `'q'`).
text_answer | array | "" | Array of strings representing a label that is associated with each correct answer. Used in conjunction with the `correct_text` and `incorrect_text` parameters.
correct_text | string | "Correct." | String to show when the correct answer is given. Can contain HTML formatting. The special string `%ANS%` can be used within the string. If present, the plugin will put the `text_answer` for the trial in place of the %ANS% string (see example below).
incorrect_text | string | "Wrong." | String to show when the wrong answer is given. Can contain HTML formatting. The special string `%ANS%` can be used within the string. If present, the plugin will put the `text_answer` for the trial in place of the %ANS% string (see example below).
prompt | string | "" | 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).
force_correct_button_press | boolean | false | If set to true, then the subject must press the correct response key after feedback is given in order to advance to the next trial.
show_stim_with_feedback | boolean | true | If set to true, then the stimulus will be shown during feedback. If false, then only the text feedback will display during feedback.
timing_stim | numeric | -1 | How long to show the stimulus for (milliseconds). If -1, then the stimulus is shown until a response is given.
timing_feedback_duration | numeric | 2000 | How long to show the feedback for (milliseconds).
@ -28,7 +29,7 @@ Name | Type | Value
-----|------|------
stimulus | string | Either the path to the image file or the string containing the HTML formatted content that the subject saw on this 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 stimulus first appears on the screen until 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 stimulus first appears on the screen until the subject's response.
correct | boolean | `true` if the subject got the correct answer, `false` otherwise.
## Examples
@ -79,4 +80,3 @@ var categorization_block = {
prompt: "<p class='prompt'>Press P for letter. Press Q for number.</p>"
};
```

View File

@ -23,6 +23,7 @@ questions | array | *undefined* | Each array element is an array of strings. The
labels | array | *undefined* | Each array element is an array of arrays. The innermost arrays contain a set of labels to display for an individual question. The middle level of arrays groups together the sets of labels that appear in a single trial. This level should correspond to the `questions` array.
intervals | array | *undefined* | Each array element is an array of integers. The integers define how many different levels of a response there are (i.e. how many choices exist for each question). The length of the inner arrays should correspond the the length of the inner arrays for the `questions` array. The number of intervals does not have to match the number of labels.
show_ticks | boolean | true | If true, then tick marks will be displayed on the sliders to indicate where the acceptable responses lie on the slider.
preamble | array | empty string | Array of HTML formatted strings to display at the top of each page above all the questions. Each element of the array corresponds to a trial/page of questions.
## Data Generated
@ -30,7 +31,11 @@ In addition to the [default data collected by all plugins](), this plugin collec
Name | Type | Value
-----|------|------
<<<<<<< HEAD
responses | JSON string | A string in JSON format containing the responses for each question. The encoded object will have a separate variable for the response to each question, with the first question in the trial being recorded in `Q0`, the second in `Q1`, and so on. The responses are recorded as integers, representing the position of the slider on the scale.
=======
Q0, Q1, ... , Q*n* | numeric | The response to each question will be recorded in its own variable, with the first question in the trial being recorded in `Q0`, the second in `Q1`, and so on. The responses are recorded as integers, representing the position of the slider on the scale.
>>>>>>> origin/dev
rt | numeric | The response time in milliseconds for the subject to make a response. The time is measured from when the questions first appear on the screen until the subject's response.
## Examples

View File

@ -9,6 +9,7 @@ This table lists the parameters associated with this plugin. Parameters with a d
Parameter | Type | Default Value | Description
----------|------|---------------|------------
questions | array | *undefined* | Each array is an array of strings. The strings are the prompts for the subject to respond to. Each string gets its own response field. Each set of strings (inner arrays) will be presented on the same page (trial). The length of the outer array sets the number of trials in the block.
preamble | string | empty string | HTML formatted string to display at the top of the page above all the questions.
## Data Generated
@ -16,7 +17,11 @@ In addition to the [default data collected by all plugins](), this plugin collec
Name | Type | Value
-----|------|------
<<<<<<< HEAD
responses | JSON string | A string in JSON format containing the responses for each question. The encoded object will have a separate variable for the response to each question, with the first question in the trial being recorded in `Q0`, the second in `Q1`, and so on. Each response is a string containing whatever the subject typed into the associated text box.
=======
Q0, Q1, ... , Q_n_ | string | Each question in the trial gets its own response in the data object. The first question will be `Q0`, the second `Q1`, and so on. Each response is a string containing whatever the subject typed into the associated text box.
>>>>>>> origin/dev
rt | numeric | The response time in milliseconds for the subject to make a response.
## Examples

View File

@ -382,6 +382,16 @@
var trials = jsPsych[plugin_name].create(chunk_timeline[i]);
// add chunk level data to all trials
if(typeof chunk_definition.data !== 'undefined'){
for(t in trials){
trials[t].data = chunk_definition.data;
}
}
// add block/trial level data to all trials
trials = addParamToTrialsArr(trials, chunk_timeline[i].data, 'data', undefined, true);
// add options that are generic to all plugins
trials = addGenericTrialOptions(trials, chunk_timeline[i]);
@ -468,20 +478,20 @@
function addGenericTrialOptions(trials_arr, opts) {
// modify this list to add new generic parameters
var genericParameters = ['type', 'data', 'timing_post_trial', 'on_finish'];
var genericParameters = ['type', 'timing_post_trial', 'on_finish'];
// default values for generics above
var defaultValues = [, , 1000, ];
var defaultValues = [, 1000, ];
for (var i = 0; i < genericParameters.length; i++) {
trials_arr = addParamToTrialsArr(trials_arr, opts[genericParameters[i]], genericParameters[i], defaultValues[i]);
trials_arr = addParamToTrialsArr(trials_arr, opts[genericParameters[i]], genericParameters[i], defaultValues[i], false);
}
return trials_arr;
}
function addParamToTrialsArr(trials_arr, param, param_name, default_value) {
function addParamToTrialsArr(trials_arr, param, param_name, default_value, extend) {
if (typeof default_value !== 'undefined') {
param = (typeof param === 'undefined') ? default_value : param;
@ -489,18 +499,26 @@
if (typeof param !== 'undefined') {
if (Array.isArray(param)) {
// check if data object array is the same length as the number of trials
// check if parameter setting is the same length as the number of trials
if (param.length != trials_arr.length) {
throw new Error('Invalid specification of parameter ' + param_name + ' in plugin type ' + trials_arr[i].type + '. Length of parameter array does not match the number of trials in the block.');
} else {
for (var i = 0; i < trials_arr.length; i++) {
trials_arr[i][param_name] = param[i];
if(extend && typeof trials_arr[i][param_name] !== 'undefined'){
trials_arr[i][param_name] = $.extend({}, trials_arr[i][param_name], param[i])
} else {
trials_arr[i][param_name] = param[i];
}
}
}
} else {
// use the same data object for each trial
for (var i = 0; i < trials_arr.length; i++) {
trials_arr[i][param_name] = param;
if(extend && typeof trials_arr[i][param_name] !== 'undefined'){
trials_arr[i][param_name] = $.extend({}, trials_arr[i][param_name], param)
} else {
trials_arr[i][param_name] = param;
}
}
}
}

View File

@ -12,7 +12,7 @@
plugin.create = function(params) {
params = jsPsych.pluginAPI.enforceArray(params, ['choices', 'data']);
params = jsPsych.pluginAPI.enforceArray(params, ['choices']);
var trials = new Array(params.stimuli.length);
for (var i = 0; i < trials.length; i++) {

View File

@ -12,7 +12,7 @@
plugin.create = function(params) {
params = jsPsych.pluginAPI.enforceArray(params, ['key_answer', 'text_answer', 'choices', 'data']);
params = jsPsych.pluginAPI.enforceArray(params, ['key_answer', 'text_answer', 'choices']);
var trials = new Array(params.stimuli.length);
for (var i = 0; i < trials.length; i++) {

View File

@ -12,7 +12,7 @@
plugin.create = function(params) {
params = jsPsych.pluginAPI.enforceArray(params, ['choices', 'stimuli', 'key_answer', 'text_answer', 'data']);
params = jsPsych.pluginAPI.enforceArray(params, ['choices', 'stimuli', 'key_answer', 'text_answer']);
var trials = [];
for (var i = 0; i < params.stimuli.length; i++) {

View File

@ -16,7 +16,7 @@
plugin.create = function(params) {
params = jsPsych.pluginAPI.enforceArray(params, ['data']);
//params = jsPsych.pluginAPI.enforceArray(params, ['data']);
var n_trials = (typeof params.starting_value == 'undefined') ? 1 : params.starting_value.length

View File

@ -14,7 +14,7 @@
plugin.create = function(params) {
params = jsPsych.pluginAPI.enforceArray(params, ['data', 'answer'])
params = jsPsych.pluginAPI.enforceArray(params, ['answer'])
var trials = new Array(params.stimuli.length);
for (var i = 0; i < trials.length; i++) {
@ -40,11 +40,11 @@
// this evaluates the function and replaces
// it with the output of the function
trial = jsPsych.pluginAPI.normalizeTrialVariables(trial);
// unpack the stimuli array (for backwards code compatibility. this could be cleaned up in the future)
trial.a_path = trial.stimuli[0];
trial.b_path = trial.stimuli[1];
// this array holds handlers from setTimeout calls
// that need to be cleared if the trial ends early
var setTimeoutHandlers = [];

View File

@ -15,7 +15,7 @@
plugin.create = function(params) {
jsPsych.pluginAPI.enforceArray(params, ['data']);
//jsPsych.pluginAPI.enforceArray(params, ['data']);
var trials = new Array(params.stimuli.length);
for (var i = 0; i < trials.length; i++) {

View File

@ -15,7 +15,7 @@
plugin.create = function(params) {
params = jsPsych.pluginAPI.enforceArray(params, ['stimuli', 'choices', 'data']);
params = jsPsych.pluginAPI.enforceArray(params, ['stimuli', 'choices']);
var trials = new Array(params.stimuli.length);
for (var i = 0; i < trials.length; i++) {
@ -123,7 +123,7 @@
};
// start the response listener
if(trial.choices != "none") {
if(JSON.stringify(trial.choices) != JSON.stringify(["none"])) {
var keyboardListener = jsPsych.pluginAPI.getKeyboardResponse(after_response, trial.choices);
}

View File

@ -15,7 +15,7 @@
plugin.create = function(params) {
params = jsPsych.pluginAPI.enforceArray(params, ['data']);
//params = jsPsych.pluginAPI.enforceArray(params, ['data']);
var trials = [];
for (var i = 0; i < params.questions.length; i++) {

View File

@ -15,7 +15,7 @@
plugin.create = function(params) {
params = jsPsych.pluginAPI.enforceArray(params, ['data']);
//params = jsPsych.pluginAPI.enforceArray(params, ['data']);
var trials = [];
for (var i = 0; i < params.questions.length; i++) {

View File

@ -16,7 +16,7 @@
plugin.create = function(params) {
params = jsPsych.pluginAPI.enforceArray(params, ['text', 'cont_key']);
params = jsPsych.pluginAPI.enforceArray(params, ['cont_key']);
var trials = new Array(params.text.length);
for (var i = 0; i < trials.length; i++) {

View File

@ -0,0 +1,44 @@
<!doctype html>
<html>
<head>
<script src="js/jquery.min.js"></script>
<script src="../jspsych.js"></script>
<script src="../plugins/jspsych-single-stim.js"></script>
<link rel="stylesheet" href="../css/jspsych.css"></link>
<style>
img { width: 300px; }
</style>
</head>
<body>
<div id="jspsych-target"></div>
</body>
<script>
var block_1 = {
type: 'single-stim',
stimuli: ['img/happy_face_1.jpg', 'img/sad_face_1.jpg'],
choices: [89,78], // Y or N
prompt: '<p class="center-content">Have you seen this face before? Y or N.</p>',
data: [{ block_data: "trial 1" }, {block_data: "trial_2"}]
}
var chunk = {
chunk_type: 'linear',
timeline: [block_1],
data: { chunk_data: true }
}
function start(){
jsPsych.init({
display_element: $('#jspsych-target'),
experiment_structure: [chunk],
on_finish: function(){
jsPsych.data.displayData();
}
});
}
jsPsych.preloadImages(['img/happy_face_1.jpg','img/sad_face_1.jpg'], start);
</script>
</html>