Merge pull request #1523 from jspsych/feature-objects-arrays-in-data

Merge branch feature-objects-arrays-in-data - fixes #670
This commit is contained in:
Becky Gilbert 2021-02-16 19:07:34 -08:00 committed by GitHub
commit 47d2f40cd6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
56 changed files with 480 additions and 151 deletions

View File

@ -128,7 +128,7 @@ var trial = {
prompt: function() { prompt: function() {
// this question prompt is dynamic - the text that is shown // this question prompt is dynamic - the text that is shown
// will change based on the participant's earlier response // will change based on the participant's earlier response
var favorite_city = JSON.parse(jsPsych.data.getLastTrialData().values()[0].responses).fav_city; var favorite_city = jsPsych.data.getLastTrialData().values()[0].responses.fav_city;
var text = "Earlier you said your favorite city is "+favorite_city+". What do you like most about "+favorite_city+"?" var text = "Earlier you said your favorite city is "+favorite_city+". What do you like most about "+favorite_city+"?"
return text; return text;
}, },

View File

@ -22,8 +22,8 @@ In addition to the [default data collected by all plugins](/overview/plugins#dat
Name | Type | Value Name | Type | Value
-----|------|------ -----|------|------
animation_sequence | JSON | An array, encoded in JSON format. Each element of the array is an object that represents a stimulus in the animation sequence. Each object has a `stimulus` property, which is the image that was displayed, and a `time` property, which is the time in ms, measured from when the sequence began, that the stimulus was displayed. animation_sequence | array | An array, where each element is an object that represents a stimulus in the animation sequence. Each object has a `stimulus` property, which is the image that was displayed, and a `time` property, which is the time in ms, measured from when the sequence began, that the stimulus was displayed. The array will be encoded in JSON format when data is saved using either the `.json()` or `.csv()` functions.
responses | JSON | An array, encoded in JSON format. Each element of the array is an object representing a response given by the subject. Each object has a `stimulus` property, indicating which image was displayed when the key was pressed, an `rt` property, indicating the time of the key press relative to the start of the animation, and a `key_press` property, indicating which key was pressed. responses | array | An array, where each element is an object representing a response given by the subject. Each object has a `stimulus` property, indicating which image was displayed when the key was pressed, an `rt` property, indicating the time of the key press relative to the start of the animation, and a `key_press` property, indicating which key was pressed. The array will be encoded in JSON format when data is saved using either the `.json()` or `.csv()` functions.
## Examples ## Examples

View File

@ -27,7 +27,7 @@ In addition to the [default data collected by all plugins](/overview/plugins#dat
| Name | Type | Value | | Name | Type | Value |
| --------- | ------- | ---------------------------------------- | | --------- | ------- | ---------------------------------------- |
| stimulus | JSON | JSON encoded representation of the array of stimuli displayed in the trial. | | stimulus | array | Array of stimuli displayed in the trial. This will be encoded as a JSON string when data is saved using the `.json()` or `.csv()` functions. |
| key_press | string | Indicates which key the subject pressed. | | key_press | string | Indicates which key the subject pressed. |
| 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. | | correct | boolean | `true` if the subject got the correct answer, `false` otherwise. |

View File

@ -32,9 +32,9 @@ In addition to the [default data collected by all plugins](/overview/plugins#dat
Name | Type | Value Name | Type | Value
-----|------|------ -----|------|------
init_locations | JSON string | A JSON-encoded object representing the initial locations of all the stimuli in the sorting area. The object is an array with one element per stimulus. Each element in the array has a "src", "x", and "y" value. "src" is the image path, and "x" and "y" are the object location. init_locations | array | An array containing objects representing the initial locations of all the stimuli in the sorting area. Each element in the array represents a stimulus, and has a "src", "x", and "y" value. "src" is the image path, and "x" and "y" are the object location. This will be encoded as a JSON string when data is saved using the `.json()` or `.csv()` functions.
moves | JSON string | A JSON-encoded object representing all of the moves the participant made when sorting. The object is an array with each element representing a move. Each element in the array has a "src", "x", and "y" value. "src" is the image path, and "x" and "y" are the object location after the move. moves | array | An array containing objects representing all of the moves the participant made when sorting. Each object represents a move. Each element in the array has a "src", "x", and "y" value. "src" is the image path, and "x" and "y" are the object location after the move. This will be encoded as a JSON string when data is saved using the `.json()` or `.csv()` functions.
final_locations | JSON string | A JSON-encoded object representing the final locations of all the stimuli in the sorting area. The object is an array with one element per stimulus. Each element in the array has a "src", "x", and "y" value. "src" is the image path, and "x" and "y" are the object location. final_locations | array | An array containing objects representing the final locations of all the stimuli in the sorting area. Each element in the array represents a stimulus, and has a "src", "x", and "y" value. "src" is the image path, and "x" and "y" are the object location. This will be encoded as a JSON string when data is saved using the `.json()` or `.csv()` functions.
rt | numeric | The response time in milliseconds for the participant to finish all sorting. rt | numeric | The response time in milliseconds for the participant to finish all sorting.
## Examples ## Examples

View File

@ -25,7 +25,7 @@ In addition to the [default data collected by all plugins](/overview/plugins#dat
| Name | Type | Value | | Name | Type | Value |
| ------------ | ----------- | ---------------------------------------- | | ------------ | ----------- | ---------------------------------------- |
| view_history | JSON string | A JSON string containing the order of pages the subject viewed (including when the subject returned to previous pages) and the time spent viewing each page. | | view_history | array | An array containing the order of pages the subject viewed (including when the subject returned to previous pages) and the time spent viewing each page. Each object in the array represents a single page view, and contains keys called `page_index` (the page number, starting with 0) and `viewing_time` (duration of the page view). This will be encoded as a JSON string when data is saved using the `.json()` or `.csv()` functions. |
| rt | numeric | The response time in milliseconds for the subject to view all of the pages. | | rt | numeric | The response time in milliseconds for the subject to view all of the pages. |
## Example ## Example

View File

@ -23,9 +23,9 @@ In addition to the [default data collected by all plugins](/overview/plugins#dat
Name | Type | Value Name | Type | Value
-----|------|------ -----|------|------
rt | numeric | The response time in milliseconds for the subject to make a response. The time is measured from when the maxdiff table 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 maxdiff table first appears on the screen until the subject's response.
labels | JSON string | A string in JSON format containing the labels corresponding to the left and right response columns. labels | object | An object with two keys, `left` and `right`, containing the labels (strings) corresponding to the left and right response columns. This will be encoded as a JSON string when data is saved using the `.json()` or `.csv()` functions.
left | string | The alternative endorsed on the left column. left | string | The alternative selected on the left column.
right | string | The alternative endorsed on the right column. right | string | The alternative selected on the right column.
## Examples ## Examples

View File

@ -68,7 +68,7 @@ In addition to the [default data collected by all plugins](/overview/plugins#dat
| correct | boolean | Whether or not the subject's key press corresponded to those provided in correct_choice. | | correct | boolean | Whether or not the subject's key press corresponded to those provided in correct_choice. |
| frame_rate | numeric | The average frame rate for the trial. 0 denotes that the subject responded before the appearance of the second frame. | | frame_rate | numeric | The average frame rate for the trial. 0 denotes that the subject responded before the appearance of the second frame. |
| number_of_frames | numeric | The number of frames that was shown in this trial. | | number_of_frames | numeric | The number of frames that was shown in this trial. |
| frame_rate_array | JSON string | The array that holds the number of miliseconds for each frame in this trial. | | frame_rate_array | array | The array that holds the number of miliseconds for each frame in this trial. This will be encoded as a JSON string when data is saved using the `.json()` or `.csv()` functions. |
| canvas_width | numeric | The width of the canvas in pixels. | | canvas_width | numeric | The width of the canvas in pixels. |
| canvas_height | numeric | The height of the canvas in pixels. | | canvas_height | numeric | The height of the canvas in pixels. |

View File

@ -24,7 +24,7 @@ In addition to the [default data collected by all plugins](/overview/plugins#dat
| Name | Type | Value | | Name | Type | Value |
| --------- | ------- | ---------------------------------------- | | --------- | ------- | ---------------------------------------- |
| stimulus | string | An JSON-encoded array of length 2 containing the HTML-formatted content that the subject saw for each trial. | | stimulus | array | An array of length 2 containing the HTML-formatted content that the subject saw for each trial. This will be encoded as a JSON string when data is saved using the `.json()` or `.csv()` functions. |
| key_press | string | Indicates which key the subject pressed. | | key_press | string | Indicates which key the subject pressed. |
| rt | numeric | The response time in milliseconds for the subject to make a response. The time is measured from when the second 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 second stimulus first appears on the screen until the subject's response. |
| correct | boolean | `true` if the subject's response matched the `answer` for this trial. | | correct | boolean | `true` if the subject's response matched the `answer` for this trial. |

View File

@ -24,7 +24,7 @@ In addition to the [default data collected by all plugins](/overview/plugins#dat
| Name | Type | Value | | Name | Type | Value |
| --------- | ------- | ---------------------------------------- | | --------- | ------- | ---------------------------------------- |
| stimulus | string | An JSON-encoded array of length 2 containing the paths to the image files that the subject saw for each trial. | | stimulus | array | An array of length 2 containing the paths to the image files that the subject saw for each trial. This will be encoded as a JSON string when data is saved using the `.json()` or `.csv()` functions. |
| key_press | string | Indicates which key the subject pressed. | | key_press | string | Indicates which key the subject pressed. |
| rt | numeric | The response time in milliseconds for the subject to make a response. The time is measured from when the second 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 second stimulus first appears on the screen until the subject's response. |
| correct | boolean | `true` if the subject's response matched the `answer` for this trial. | | correct | boolean | `true` if the subject's response matched the `answer` for this trial. |

View File

@ -25,8 +25,8 @@ In addition to the [default data collected by all plugins](/overview/plugins#dat
| Name | Type | Value | | Name | Type | Value |
| ------ | ------- | ---------------------------------------- | | ------ | ------- | ---------------------------------------- |
| grid | JSON | A JSON-encoded representation of the grid. | | grid | array | The grid representation. This will be encoded as a JSON string when data is saved using the `.json()` or `.csv()` functions. |
| target | JSON | A JSON-encoded representation of the target on the grid. | | target | array | The representation of the target location on the grid. This will be encoded as a JSON string when data is saved using the `.json()` or `.csv()` functions. |
| rt | numeric | The response time in milliseconds for the subject to make a response. The time is measured from when the second 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 second stimulus first appears on the screen until the subject's response. |
## Examples ## Examples

View File

@ -27,8 +27,8 @@ In addition to the [default data collected by all plugins](/overview/plugins#dat
| Name | Type | Value | | Name | Type | Value |
| --------- | ------- | ---------------------------------------- | | --------- | ------- | ---------------------------------------- |
| grid | JSON | A JSON-encoded representation of the grid. | | grid | array | The representation of the grid. This will be encoded as a JSON string when data is saved using the `.json()` or `.csv()` functions. |
| target | JSON | A JSON-encoded representation of the target on the grid. | | target | array | The representation of the target location on the grid. This will be encoded as a JSON string when data is saved using the `.json()` or `.csv()` functions. |
| key_press | string | Indicates which key the subject pressed. | | key_press | string | Indicates which key the subject pressed. |
| rt | numeric | The response time in milliseconds for the subject to make a response. The time is measured from when the second 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 second stimulus first appears on the screen until the subject's response. |
| correct | boolean | `true` if the subject's response matched the target. | | correct | boolean | `true` if the subject's response matched the target. |

View File

@ -21,8 +21,8 @@ In addition to the [default data collected by all plugins](/overview/plugins#dat
Name | Type | Value Name | Type | Value
-----|------|------ -----|------|------
responses | string | A JS object encoded in JSON format containing the response for each input. The encoded object will have a separate variable for the response to each input, with each variable being named after its corresponding input element. Each response is a string containing whatever the subject answered for this particular input. responses | object | An object containing the response for each input. The object will have a separate key (variable) for the response to each input, with each variable being named after its corresponding input element. Each response is a string containing whatever the subject answered for this particular input. This will be encoded as a JSON string when data is saved using the `.json()` or `.csv()` functions. |
rt | numeric | The response time in milliseconds for the subject to make a response. rt | numeric | The response time in milliseconds for the subject to make a response. |
## Examples ## Examples

View File

@ -21,9 +21,9 @@ In addition to the [default data collected by all plugins](/overview/plugins#dat
Name | Type | Value Name | Type | Value
-----|------|------ -----|------|------
responses | JSON string | A string in JSON format containing the response 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. If the `name` parameter is defined for the question, then the response will use the value of `name` as the key for the response in the `responses` object. responses | object | An object containing the response for each question. The object will have a separate key (variable) for 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 selected on the likert scale for that question. If the `name` parameter is defined for the question, then the responses object will use the value of `name` as the key for each question. This will be encoded as a JSON string when data is saved using the `.json()` or `.csv()` functions. |
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. 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(s) are submitted. |
question_order | JSON string | A string in JSON format containing an array with the order of questions. For example `[2,0,1]` would indicate that the first question was `trial.questions[2]` (the third item in the `questions` parameter), the second question was `trial.questions[0]`, and the final question was `trial.questions[1]`. question_order | array | An array with the order of questions. For example `[2,0,1]` would indicate that the first question was `trial.questions[2]` (the third item in the `questions` parameter), the second question was `trial.questions[0]`, and the final question was `trial.questions[1]`. This will be encoded as a JSON string when data is saved using the `.json()` or `.csv()` functions. |
## Examples ## Examples

View File

@ -20,9 +20,9 @@ In addition to the [default data collected by all plugins](/overview/plugins#dat
Name | Type | Value Name | Type | Value
-----|------|------ -----|------|------
responses | JSON string | A string in JSON format containing the response 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 the name of the option label. If the `name` parameter is defined for the question, then the response will use the value of `name` as the key for the response in the `responses` object. responses | object | An object containing the response for each question. The object will have a separate key (variable) for 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 the name of the option label selected (string). If the `name` parameter is defined for the question, then the responses object will use the value of `name` as the key for each question. This will be encoded as a JSON string when data is saved using the `.json()` or `.csv()` functions. |
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. 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(s) are submitted. |
question_order | JSON string | A string in JSON format containing an array with the order of questions. For example `[2,0,1]` would indicate that the first question was `trial.questions[2]` (the third item in the `questions` parameter), the second question was `trial.questions[0]`, and the final question was `trial.questions[1]`. question_order | array | An array with the order of questions. For example `[2,0,1]` would indicate that the first question was `trial.questions[2]` (the third item in the `questions` parameter), the second question was `trial.questions[0]`, and the final question was `trial.questions[1]`. This will be encoded as a JSON string when data is saved using the `.json()` or `.csv()` functions. |
## Examples ## Examples

View File

@ -21,9 +21,9 @@ In addition to the [default data collected by all plugins](/overview/plugins#dat
Name | Type | Value Name | Type | Value
-----|------|------ -----|------|------
responses | JSON string | An array containing all selected choices in JSON format 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 the name of the option label. If the `name` parameter is defined for the question, then the response will use the value of `name` as the key for the response in the `responses` object. responses | object | An object containing the response for each question. The object will have a separate key (variable) for each question, with the first question in the trial being recorded in `Q0`, the second in `Q1`, and so on. For each question, the responses are recorded as arrays containing any response options that were selected (strings). If the `name` parameter is defined for the question, then the responses object will use the value of `name` as the key for each question. This will be encoded as a JSON string when data is saved using the `.json()` or `.csv()` functions. |
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. 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(s) were submitted. |
question_order | JSON string | A string in JSON format containing an array with the order of questions. For example `[2,0,1]` would indicate that the first question was `trial.questions[2]` (the third item in the `questions` parameter), the second question was `trial.questions[0]`, and the final question was `trial.questions[1]`. question_order | array | An array with the order of questions. For example `[2,0,1]` would indicate that the first question was `trial.questions[2]` (the third item in the `questions` parameter), the second question was `trial.questions[0]`, and the final question was `trial.questions[1]`. This will be encoded as a JSON string when data is saved using the `.json()` or `.csv()` functions. |
## Examples ## Examples

View File

@ -20,9 +20,9 @@ In addition to the [default data collected by all plugins](/overview/plugins#dat
Name | Type | Value Name | Type | Value
-----|------|------ -----|------|------
responses | JSON string | A string in JSON format containing the response 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. If the `name` parameter is defined for the question, then the response will use the value of `name` as the key for the response in the `responses` object. responses | object | An object containing the response for each question. The object will have a separate key (variable) for each question, with the first question in the trial being recorded in `Q0`, the second in `Q1`, and so on. For each question, the response is a string containing whatever text was in the response box when the responses were submitted. If the `name` parameter is defined for the question, then the responses object will use the value of `name` as the key for each question. This will be encoded as a JSON string when data is saved using the `.json()` or `.csv()` functions. |
rt | numeric | The response time in milliseconds for the subject to make a response. 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(s) were submitted. |
question_order | JSON string | A string in JSON format containing an array with the order of questions. For example `[2,0,1]` would indicate that the first question was `trial.questions[2]` (the third item in the `questions` parameter), the second question was `trial.questions[0]`, and the final question was `trial.questions[1]`. question_order | array | An array with the order of questions. For example `[2,0,1]` would indicate that the first question was `trial.questions[2]` (the third item in the `questions` parameter), the second question was `trial.questions[0]`, and the final question was `trial.questions[1]`. This will be encoded as a JSON string when data is saved using the `.json()` or `.csv()` functions. |
## Examples ## Examples

View File

@ -37,7 +37,7 @@ Name | Type | Value
-----|------|------ -----|------|------
button_pressed | numeric | Indicates which button the subject pressed. The first button in the `choices` array is 0, the second is 1, and so on. button_pressed | numeric | Indicates which button the subject pressed. The first button in the `choices` array is 0, the second is 1, and so on.
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.
stimulus | string | JSON encoding of the `stimulus` array. stimulus | array | The `stimulus` array. This will be encoded as a JSON string when data is saved using the `.json()` or `.csv()` functions.
## Example ## Example

View File

@ -33,7 +33,7 @@ In addition to the [default data collected by all plugins](/overview/plugins#dat
| --------- | ------- | ---------------------------------------- | | --------- | ------- | ---------------------------------------- |
| key_press | string | Indicates which key the subject pressed. | | key_press | string | Indicates which key the subject pressed. |
| 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. |
| stimulus | string | JSON encoding of the `stimulus` array. | stimulus | array | The `stimulus` array. This will be encoded as a JSON string when data is saved using the `.json()` or `.csv()` functions. |
## Example ## Example

View File

@ -41,7 +41,7 @@ Name | Type | Value
-----|------|------ -----|------|------
response | numeric | The numeric value of the slider. response | numeric | The numeric value of the slider.
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.
stimulus | string | JSON encoding of the `stimulus` array. stimulus | array | The `stimulus` array. This will be encoded as a JSON string when data is saved using the `.json()` or `.csv()` functions.
slider_start | numeric | The starting value of the slider. slider_start | numeric | The starting value of the slider.
start | numeric | The start time of the video clip. start | numeric | The start time of the video clip.

View File

@ -34,7 +34,7 @@ In addition to the [default data collected by all plugins](/overview/plugins#dat
| 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. |
| set_size | numeric | The number of items in the search array | | set_size | numeric | The number of items in the search array |
| target_present | boolean | True if the target is present in the search array | | target_present | boolean | True if the target is present in the search array |
| locations | JSON string | JSON-encoded array where each element of the array is the pixel value of the center of an image in the search array. If the target is present, then the first element will represent the location of the target. | | locations | array | Array where each element is the pixel value of the center of an image in the search array. If the target is present, then the first element will represent the location of the target. This will be encoded as a JSON string when data is saved using the `.json()` or `.csv()` functions. |
## Example ## Example

View File

@ -29,8 +29,8 @@ In addition to the [default data collected by all plugins](/overview/plugins#dat
| Name | Type | Value | | Name | Type | Value |
| --------- | ----------- | ---------------------------------------- | | --------- | ----------- | ---------------------------------------- |
| stimulus | JSON string | A JSON encoded array where each element of the array is a stimulus from the sequence, in the order that they were shown. | | stimulus | array | Array where each element is a stimulus from the sequence, in the order that they were shown. This will be encoded as a JSON string when data is saved using the `.json()` or `.csv()` functions. |
| responses | JSON string | A JSON encoded array containing all response information. The encoded object is an array containing one element for each valid response. Each response item has three properties: `key` the key that was pressed, `stimulus` the index of the stimulus that was displayed when the response was made, and `rt` the response time measured since the start of the sequence. | | responses | array | Array containing all response information. Each element in the array is an object representing each valid response. Each response item has three properties: `key` the key that was pressed, `stimulus` the index of the stimulus that was displayed when the response was made, and `rt` the response time measured since the start of the sequence. This will be encoded as a JSON string when data is saved using the `.json()` or `.csv()` functions. |
## Examples ## Examples

View File

@ -20,7 +20,7 @@ In addition to the [default data collected by all plugins](/overview/plugins#dat
| Name | Type | Value | | Name | Type | Value |
| -------- | ----------- | ---------------------------------------- | | -------- | ----------- | ---------------------------------------- |
| stimulus | JSON string | JSON encoded array of the stimulus shown on the trial. | | stimulus | array | Two dimensional array representing the stimulus shown on the trial. This will be encoded as a JSON string when data is saved using the `.json()` or `.csv()` functions. |
### Stimulus Creation Method ### Stimulus Creation Method

View File

@ -1816,6 +1816,9 @@ jsPsych.data = (function() {
var line = ''; var line = '';
for (var j = 0; j < columns.length; j++) { for (var j = 0; j < columns.length; j++) {
var value = (typeof array[i][columns[j]] === 'undefined') ? '' : array[i][columns[j]]; var value = (typeof array[i][columns[j]] === 'undefined') ? '' : array[i][columns[j]];
if(typeof value == 'object') {
value = JSON.stringify(value);
}
var valueString = value + ""; var valueString = value + "";
line += '"' + valueString.replace(/"/g, '""') + '",'; line += '"' + valueString.replace(/"/g, '""') + '",';
} }

View File

@ -177,8 +177,8 @@ jsPsych.plugins.animation = (function() {
jsPsych.pluginAPI.cancelKeyboardResponse(response_listener); jsPsych.pluginAPI.cancelKeyboardResponse(response_listener);
var trial_data = { var trial_data = {
"animation_sequence": JSON.stringify(animation_sequence), animation_sequence: animation_sequence,
"responses": JSON.stringify(responses) responses: responses
}; };
jsPsych.finishTrial(trial_data); jsPsych.finishTrial(trial_data);

View File

@ -237,10 +237,10 @@ jsPsych.plugins["categorize-animation"] = (function() {
responded = true; responded = true;
trial_data = { trial_data = {
"stimulus": JSON.stringify(trial.stimuli), stimulus: trial.stimuli,
"rt": info.rt, rt: info.rt,
"correct": correct, correct: correct,
"key_press": info.key key_press: info.key
}; };
jsPsych.pluginAPI.cancelKeyboardResponse(keyboard_listener); jsPsych.pluginAPI.cancelKeyboardResponse(keyboard_listener);

View File

@ -362,10 +362,10 @@ jsPsych.plugins['free-sort'] = (function() {
} }
const trial_data = { const trial_data = {
"init_locations": JSON.stringify(init_locations), init_locations: init_locations,
"moves": JSON.stringify(moves), moves: moves,
"final_locations": JSON.stringify(final_locations), final_locations: final_locations,
"rt": rt rt: rt
}; };
// advance to next part // advance to next part

View File

@ -191,8 +191,8 @@ jsPsych.plugins.instructions = (function() {
display_element.innerHTML = ''; display_element.innerHTML = '';
var trial_data = { var trial_data = {
"view_history": JSON.stringify(view_history), view_history: view_history,
"rt": performance.now() - start_time rt: performance.now() - start_time
}; };
jsPsych.finishTrial(trial_data); jsPsych.finishTrial(trial_data);

View File

@ -157,10 +157,10 @@ jsPsych.plugins['maxdiff'] = (function () {
// data saving // data saving
var trial_data = { var trial_data = {
"rt": response_time, rt: response_time,
"labels": JSON.stringify({"left": trial.labels[0], "right": trial.labels[1]}), labels: {"left": trial.labels[0], "right": trial.labels[1]},
"left": get_response('left'), left: get_response('left'),
"right": get_response('right') right: get_response('right')
}; };
// next trial // next trial

View File

@ -522,44 +522,44 @@ jsPsych.plugins["rdk"] = (function() {
//Place all the data to be saved from this trial in one data object //Place all the data to be saved from this trial in one data object
var trial_data = { var trial_data = {
"rt": response.rt, //The response time rt: response.rt, //The response time
"key_press": response.key, //The key that the subject pressed key_press: response.key, //The key that the subject pressed
"correct": correctOrNot(), //If the subject response was correct correct: correctOrNot(), //If the subject response was correct
"choices": trial.choices, //The set of valid keys choices: trial.choices, //The set of valid keys
"correct_choice": trial.correct_choice, //The correct choice correct_choice: trial.correct_choice, //The correct choice
"trial_duration": trial.trial_duration, //The trial duration trial_duration: trial.trial_duration, //The trial duration
"response_ends_trial": trial.response_ends_trial, //If the response ends the trial response_ends_trial: trial.response_ends_trial, //If the response ends the trial
"number_of_apertures": trial.number_of_apertures, number_of_apertures: trial.number_of_apertures,
"number_of_dots": trial.number_of_dots, number_of_dots: trial.number_of_dots,
"number_of_sets": trial.number_of_sets, number_of_sets: trial.number_of_sets,
"coherent_direction": trial.coherent_direction, coherent_direction: trial.coherent_direction,
"coherence": trial.coherence, coherence: trial.coherence,
"opposite_coherence": trial.opposite_coherence, opposite_coherence: trial.opposite_coherence,
"dot_radius": trial.dot_radius, dot_radius: trial.dot_radius,
"dot_life": trial.dot_life, dot_life: trial.dot_life,
"move_distance": trial.move_distance, move_distance: trial.move_distance,
"aperture_width": trial.aperture_width, aperture_width: trial.aperture_width,
"aperture_height": trial.aperture_height, aperture_height: trial.aperture_height,
"dot_color": trial.dot_color, dot_color: trial.dot_color,
"background_color": trial.background_color, background_color: trial.background_color,
"RDK_type": trial.RDK_type, RDK_type: trial.RDK_type,
"aperture_type": trial.aperture_type, aperture_type: trial.aperture_type,
"reinsert_type": trial.reinsert_type, reinsert_type: trial.reinsert_type,
"frame_rate": frameRate, //The average frame rate for the trial frame_rate: frameRate, //The average frame rate for the trial
"frame_rate_array": JSON.stringify(frameRateArray), //The array of ms per frame in this trial, in the form of a JSON string frame_rate_array: frameRateArray, //The array of ms per frame in this trial
"number_of_frames": numberOfFrames, //The number of frames in this trial number_of_frames: numberOfFrames, //The number of frames in this trial
"aperture_center_x": trial.aperture_center_x, aperture_center_x: trial.aperture_center_x,
"aperture_center_y": trial.aperture_center_y, aperture_center_y: trial.aperture_center_y,
"fixation_cross": trial.fixation_cross, fixation_cross: trial.fixation_cross,
"fixation_cross_width": trial.fixation_cross_width, fixation_cross_width: trial.fixation_cross_width,
"fixation_cross_height": trial.fixation_cross_height, fixation_cross_height: trial.fixation_cross_height,
"fixation_cross_color": trial.fixation_cross_color, fixation_cross_color: trial.fixation_cross_color,
"fixation_cross_thickness": trial.fixation_cross_thickness, fixation_cross_thickness: trial.fixation_cross_thickness,
"border": trial.border, border: trial.border,
"border_thickness": trial.border_thickness, border_thickness: trial.border_thickness,
"border_color": trial.border_color, border_color: trial.border_color,
"canvas_width": canvasWidth, canvas_width: canvasWidth,
"canvas_height": canvasHeight canvas_height: canvasHeight
} }

View File

@ -136,11 +136,11 @@ jsPsych.plugins['same-different-html'] = (function() {
} }
var trial_data = { var trial_data = {
"rt": info.rt, rt: info.rt,
"answer": trial.answer, answer: trial.answer,
"correct": correct, correct: correct,
"stimulus": JSON.stringify([trial.stimuli[0], trial.stimuli[1]]), stimulus: [trial.stimuli[0], trial.stimuli[1]],
"key_press": info.key key_press: info.key
}; };
if (first_stim_info) { if (first_stim_info) {
trial_data["rt_stim1"] = first_stim_info.rt; trial_data["rt_stim1"] = first_stim_info.rt;

View File

@ -137,11 +137,11 @@ jsPsych.plugins['same-different-image'] = (function() {
} }
var trial_data = { var trial_data = {
"rt": info.rt, rt: info.rt,
"answer": trial.answer, answer: trial.answer,
"correct": correct, correct: correct,
"stimulus": JSON.stringify([trial.stimuli[0], trial.stimuli[1]]), stimulus: [trial.stimuli[0], trial.stimuli[1]],
"key_press": info.key key_press: info.key
}; };
if (first_stim_info) { if (first_stim_info) {
trial_data["rt_stim1"] = first_stim_info.rt; trial_data["rt_stim1"] = first_stim_info.rt;

View File

@ -151,12 +151,12 @@ jsPsych.plugins["serial-reaction-time-mouse"] = (function() {
// gather the data to store for the trial // gather the data to store for the trial
var trial_data = { var trial_data = {
"rt": response.rt, rt: response.rt,
"grid": JSON.stringify(trial.grid), grid: trial.grid,
"target": JSON.stringify(trial.target), target: trial.target,
"response_row": response.row, response_row: response.row,
"response_column": response.column, response_column: response.column,
"correct": response.row == trial.target[0] && response.column == trial.target[1] correct: response.row == trial.target[0] && response.column == trial.target[1]
}; };
// clear the display // clear the display

View File

@ -171,11 +171,11 @@ jsPsych.plugins["serial-reaction-time"] = (function() {
// gather the data to store for the trial // gather the data to store for the trial
var trial_data = { var trial_data = {
"rt": response.rt, rt: response.rt,
"key_press": response.key, key_press: response.key,
"correct": response.correct, correct: response.correct,
"grid": JSON.stringify(trial.grid), grid: trial.grid,
"target": JSON.stringify(trial.target) target: trial.target
}; };
// clear the display // clear the display

View File

@ -105,8 +105,8 @@ jsPsych.plugins['survey-html-form'] = (function() {
// save data // save data
var trialdata = { var trialdata = {
"rt": response_time, rt: response_time,
"responses": JSON.stringify(question_data) responses: question_data
}; };
display_element.innerHTML = ''; display_element.innerHTML = '';

View File

@ -177,9 +177,9 @@ jsPsych.plugins['survey-likert'] = (function() {
// save data // save data
var trial_data = { var trial_data = {
"rt": response_time, rt: response_time,
"responses": JSON.stringify(question_data), responses: question_data,
"question_order": JSON.stringify(question_order) question_order: question_order
}; };
display_element.innerHTML = ''; display_element.innerHTML = '';

View File

@ -191,9 +191,9 @@ jsPsych.plugins['survey-multi-choice'] = (function() {
} }
// save data // save data
var trial_data = { var trial_data = {
"rt": response_time, rt: response_time,
"responses": JSON.stringify(question_data), responses: question_data,
"question_order": JSON.stringify(question_order) question_order: question_order
}; };
display_element.innerHTML = ''; display_element.innerHTML = '';

View File

@ -215,8 +215,8 @@ jsPsych.plugins['survey-multi-select'] = (function() {
// save data // save data
var trial_data = { var trial_data = {
"rt": response_time, "rt": response_time,
"responses": JSON.stringify(question_data), "responses": question_data,
"question_order": JSON.stringify(question_order) "question_order": question_order
}; };
display_element.innerHTML = ''; display_element.innerHTML = '';

View File

@ -168,8 +168,8 @@ jsPsych.plugins['survey-text'] = (function() {
} }
// save data // save data
var trialdata = { var trialdata = {
"rt": response_time, rt: response_time,
"responses": JSON.stringify(question_data) responses: question_data
}; };
display_element.innerHTML = ''; display_element.innerHTML = '';

View File

@ -263,9 +263,9 @@ jsPsych.plugins["video-button-response"] = (function() {
// gather the data to store for the trial // gather the data to store for the trial
var trial_data = { var trial_data = {
"rt": response.rt, rt: response.rt,
"stimulus": JSON.stringify(trial.stimulus), stimulus: trial.stimulus,
"button_pressed": response.button button_pressed: response.button
}; };
// clear the display // clear the display

View File

@ -227,9 +227,9 @@ jsPsych.plugins["video-keyboard-response"] = (function() {
// gather the data to store for the trial // gather the data to store for the trial
var trial_data = { var trial_data = {
"rt": response.rt, rt: response.rt,
"stimulus": JSON.stringify(trial.stimulus), stimulus: trial.stimulus,
"key_press": response.key key_press: response.key
}; };
// clear the display // clear the display

View File

@ -317,11 +317,11 @@ jsPsych.plugins["video-slider-response"] = (function() {
// gather the data to store for the trial // gather the data to store for the trial
var trial_data = { var trial_data = {
"rt": response.rt, rt: response.rt,
"stimulus": JSON.stringify(trial.stimulus), stimulus: trial.stimulus,
"start": trial.start, start: trial.start,
"slider_start": trial.slider_start, slider_start: trial.slider_start,
"response": response.response response: response.response
}; };
// clear the display // clear the display

View File

@ -235,7 +235,7 @@ jsPsych.plugins["visual-search-circle"] = (function() {
correct: correct, correct: correct,
rt: rt, rt: rt,
key_press: key_press, key_press: key_press,
locations: JSON.stringify(display_locs), locations: display_locs,
target_present: trial.target_present, target_present: trial.target_present,
set_size: trial.set_size set_size: trial.set_size
}; };

View File

@ -184,8 +184,8 @@ jsPsych.plugins['vsl-animate-occlusion'] = (function() {
jsPsych.pluginAPI.cancelKeyboardResponse(key_listener); jsPsych.pluginAPI.cancelKeyboardResponse(key_listener);
var trial_data = { var trial_data = {
"stimuli": JSON.stringify(trial.stimuli), stimuli: trial.stimuli,
"responses": JSON.stringify(responses) responses: responses
}; };
jsPsych.finishTrial(trial_data); jsPsych.finishTrial(trial_data);

View File

@ -57,7 +57,7 @@ jsPsych.plugins['vsl-grid-scene'] = (function() {
display_element.innerHTML = ''; display_element.innerHTML = '';
var trial_data = { var trial_data = {
"stimulus": JSON.stringify(trial.stimuli) stimulus: trial.stimuli
}; };
jsPsych.finishTrial(trial_data); jsPsych.finishTrial(trial_data);

View File

@ -0,0 +1,85 @@
const root = '../../';
const utils = require('../testing-utils.js');
jest.useFakeTimers();
describe('data conversion to csv', function(){
beforeEach(function(){
require(root + 'jspsych.js');
require(root + 'plugins/jspsych-survey-text.js');
});
test('survey-text data response object is correctly converted', function(){
var trial = {
type: 'survey-text',
questions: [
{prompt: 'Q1'},
{prompt: 'Q2'}
]
}
var timeline = [trial];
jsPsych.init({timeline});
document.querySelector('#input-0').value = 'Response 1';
document.querySelector('#input-1').value = 'Response 2';
utils.clickTarget(document.querySelector('#jspsych-survey-text-next'));
var csv_data = jsPsych.data.get().ignore(['rt','internal_node_id', 'time_elapsed', 'trial_type']).csv();
expect(csv_data).toBe('"responses","trial_index"\r\n"{""Q0"":""Response 1"",""Q1"":""Response 2""}","0"\r\n');
})
test('same-different-html stimulus array is correctly converted', function(){
require(root + 'plugins/jspsych-same-different-html.js');
var trial = {
type: 'same-different-html',
stimuli: ['<p>Climbing</p>', '<p>Walking</p>'],
answer: 'different',
gap_duration: 0,
first_stim_duration: null
}
var timeline = [trial];
jsPsych.init({timeline: timeline});
expect(jsPsych.getDisplayElement().innerHTML).toMatch('<p>Climbing</p>');
utils.pressKey('q');
jest.runAllTimers();
expect(jsPsych.getDisplayElement().innerHTML).toMatch('<p>Walking</p>');
utils.pressKey('q');
expect(jsPsych.getDisplayElement().innerHTML).toBe('');
var csv_data = jsPsych.data.get().ignore(['rt','internal_node_id','time_elapsed','trial_type','rt_stim1','key_press_stim1']).csv();
expect(csv_data).toBe('"answer","correct","stimulus","key_press","trial_index"\r\n"different","false","[""<p>Climbing</p>"",""<p>Walking</p>""]","q","0"\r\n')
})
test('survey-multi-select response array is correctly converted', function(){
require(root + 'plugins/jspsych-survey-multi-select.js');
var trial = {
type: 'survey-multi-select',
questions: [
{prompt: "foo", options: ["fuzz", "bizz", "bar"], name: 'q'}
]
};
var timeline = [trial];
jsPsych.init({timeline: timeline});
expect(jsPsych.getDisplayElement().innerHTML).toMatch('foo');
utils.clickTarget(document.querySelector('#jspsych-survey-multi-select-response-0-0'));
utils.clickTarget(document.querySelector('#jspsych-survey-multi-select-response-0-1'));
utils.clickTarget(document.querySelector('#jspsych-survey-multi-select-next'));
expect(jsPsych.getDisplayElement().innerHTML).toBe('');
var csv_data = jsPsych.data.get().ignore(['rt','internal_node_id','time_elapsed','trial_type','question_order']).csv();
expect(csv_data).toBe('"responses","trial_index"\r\n"{""q"":[""fuzz"",""bizz""]}","0"\r\n')
})
});

View File

@ -0,0 +1,120 @@
const root = '../../';
const utils = require('../testing-utils.js');
jest.useFakeTimers();
describe('data conversion to json', function(){
beforeEach(function(){
require(root + 'jspsych.js');
});
test('survey-text data response object is correctly converted', function(){
require(root + 'plugins/jspsych-survey-text.js');
var trial = {
type: 'survey-text',
questions: [
{prompt: 'Q1'},
{prompt: 'Q2'}
]
}
var timeline = [trial];
jsPsych.init({timeline});
document.querySelector('#input-0').value = 'Response 1';
document.querySelector('#input-1').value = 'Response 2';
utils.clickTarget(document.querySelector('#jspsych-survey-text-next'));
var json_data = jsPsych.data.get().ignore(['rt','internal_node_id', 'time_elapsed', 'trial_type']).json();
expect(json_data).toBe(JSON.stringify([{responses: {Q0: "Response 1", Q1: "Response 2"}, trial_index: 0}]));
})
test('same-different-html stimulus array is correctly converted', function(){
require(root + 'plugins/jspsych-same-different-html.js');
var trial = {
type: 'same-different-html',
stimuli: ['<p>Climbing</p>', '<p>Walking</p>'],
answer: 'different',
gap_duration: 0,
first_stim_duration: null
}
var timeline = [trial];
jsPsych.init({timeline: timeline});
expect(jsPsych.getDisplayElement().innerHTML).toMatch('<p>Climbing</p>');
utils.pressKey('q');
jest.runAllTimers();
expect(jsPsych.getDisplayElement().innerHTML).toMatch('<p>Walking</p>');
utils.pressKey('q');
expect(jsPsych.getDisplayElement().innerHTML).toBe('');
var json_data = jsPsych.data.get().ignore(['rt','internal_node_id','time_elapsed','trial_type','rt_stim1','key_press_stim1']).json();
expect(json_data).toBe(JSON.stringify([{answer: 'different', correct: false, stimulus: ['<p>Climbing</p>','<p>Walking</p>'], key_press: 'q', trial_index: 0}]));
})
test('survey-multi-select response array is correctly converted', function(){
require(root + 'plugins/jspsych-survey-multi-select.js');
var trial = {
type: 'survey-multi-select',
questions: [
{prompt: "foo", options: ["fuzz", "bizz", "bar"], name: 'q'}
]
};
var timeline = [trial];
jsPsych.init({timeline: timeline});
expect(jsPsych.getDisplayElement().innerHTML).toMatch('foo');
utils.clickTarget(document.querySelector('#jspsych-survey-multi-select-response-0-0'));
utils.clickTarget(document.querySelector('#jspsych-survey-multi-select-response-0-1'));
utils.clickTarget(document.querySelector('#jspsych-survey-multi-select-next'));
expect(jsPsych.getDisplayElement().innerHTML).toBe('');
var json_data = jsPsych.data.get().ignore(['rt','internal_node_id','time_elapsed','trial_type','question_order']).json();
var data_js = [
{
responses: {
q: ["fuzz","bizz"],
},
trial_index: 0
}
];
expect(json_data).toBe(JSON.stringify(data_js));
})
test('instructions view_history is correctly converted - issue #670', function(){
require(root + 'plugins/jspsych-instructions.js');
var trial = {
type: 'instructions',
pages: ['page 1','page 2'],
key_forward: 'a',
allow_keys: true
};
jsPsych.init({timeline: [trial]});
expect(jsPsych.getDisplayElement().innerHTML).toMatch('page 1');
utils.pressKey('a');
expect(jsPsych.getDisplayElement().innerHTML).toMatch('page 2');
utils.pressKey('a');
expect(jsPsych.getDisplayElement().innerHTML).toBe('');
var json_data = jsPsych.data.get().ignore(['rt','internal_node_id','time_elapsed']).json();
var js_data = JSON.parse(json_data);
expect(Array.isArray(js_data[0].view_history)).toBe(true);
expect(js_data[0].view_history.length).toBe(2);
expect(js_data[0].view_history[0].page_index).toBe(0);
expect(js_data[0].view_history[1].page_index).toBe(1);
})
});

View File

@ -63,6 +63,7 @@ describe('DataCollection', function(){
}); });
test('#values', function(){ test('#values', function(){
expect(JSON.stringify(jsPsych.data.get().values())).toBe(JSON.stringify(data)); expect(JSON.stringify(jsPsych.data.get().values())).toBe(JSON.stringify(data));
expect(jsPsych.data.get().values()).toBe(data);
}); });
test('#first', function(){ test('#first', function(){
expect(jsPsych.data.get().first(3).count()).toBe(3); expect(jsPsych.data.get().first(3).count()).toBe(3);

View File

@ -136,5 +136,22 @@ describe('cloze', function(){
expect(called).toBeTruthy(); expect(called).toBeTruthy();
}); });
test('response data is stored as an array', function(){
var trial = {
type: 'cloze',
text: 'This is a %cloze% text. Here is another cloze response box %%.'
}
jsPsych.init({
timeline: [trial]
});
document.getElementById('input0').value = 'cloze1';
document.getElementById('input1').value = 'cloze2';
utils.clickTarget(document.querySelector('#finish_cloze_button'));
var data = jsPsych.data.get().values()[0].answers;
expect(data.length).toBe(2);
expect(data[0]).toBe('cloze1');
expect(data[1]).toBe('cloze2');
});
}); });

View File

@ -63,4 +63,23 @@ describe('instructions plugin', function(){
expect(jsPsych.getDisplayElement().innerHTML).toBe(''); expect(jsPsych.getDisplayElement().innerHTML).toBe('');
}) })
test('view history data is stored as array of objects', function(){
var trial = {
type: 'instructions',
pages: ['page 1', 'page 2'],
key_forward: 'a'
}
jsPsych.init({
timeline: [trial]
});
utils.pressKey('a');
utils.pressKey('a');
expect(jsPsych.getDisplayElement().innerHTML).toBe('');
var data = jsPsych.data.get().values()[0].view_history;
expect(data[0].page_index).toBe(0);
expect(data[1].page_index).toBe(1);
})
}); });

View File

@ -14,4 +14,48 @@ describe('rdk plugin', function(){
expect(typeof window.jsPsych.plugins['rdk']).not.toBe('undefined'); expect(typeof window.jsPsych.plugins['rdk']).not.toBe('undefined');
}); });
test('choices and frame data are stored as arrays', function(){
var trial = {
type: 'rdk',
number_of_dots: 200,
RDK_type: 3,
choices: ['a', 'l'],
correct_choice: 'l',
coherent_direction: 0
}
jsPsych.init({
timeline: [trial]
});
utils.pressKey('l')
var data = jsPsych.data.get().values()[0];
expect(Array.isArray(data.choices)).toBe(true);
expect(data.choices).toStrictEqual(['a', 'l']);
expect(Array.isArray(data.frame_rate_array)).toBe(true);
});
test('responses are scored correctly', function(){
var trial = {
type: 'rdk',
number_of_dots: 200,
RDK_type: 3,
choices: ['a', 'l'],
correct_choice: 'l',
coherent_direction: 0
}
jsPsych.init({
timeline: [trial,trial]
});
utils.pressKey('l');
utils.pressKey('a');
var data = jsPsych.data.get().values();
expect(data[0].key_press).toBe('l');
expect(data[0].correct).toBe(true);
expect(data[1].key_press).toBe('a');
expect(data[1].correct).toBe(false);
});
}); });

View File

@ -62,7 +62,47 @@ describe('serial-reaction-time plugin', function(){
jest.runTimersToTime(1000); jest.runTimersToTime(1000);
expect(jsPsych.getDisplayElement().innerHTML).toBe(''); expect(jsPsych.getDisplayElement().innerHTML).toBe('');
//expect(jsPsych.data.get().last(1).values()[0].correct).toBe(true); expect(jsPsych.data.get().last(1).values()[0].correct).toBe(true);
});
test('responses are scored correctly', function(){
var trial1 = {
type: 'serial-reaction-time',
target: [0,0]
}
var trial2 = {
type: 'serial-reaction-time',
target: [0,1]
}
jsPsych.init({
timeline: [trial1, trial2]
});
expect(document.querySelector('#jspsych-serial-reaction-time-stimulus-cell-0-0').style.backgroundColor).toBe('rgb(153, 153, 153)');
expect(document.querySelector('#jspsych-serial-reaction-time-stimulus-cell-0-1').style.backgroundColor).toBe('');
expect(document.querySelector('#jspsych-serial-reaction-time-stimulus-cell-0-2').style.backgroundColor).toBe('');
expect(document.querySelector('#jspsych-serial-reaction-time-stimulus-cell-0-3').style.backgroundColor).toBe('');
utils.pressKey('3');
jest.runAllTimers();
expect(document.querySelector('#jspsych-serial-reaction-time-stimulus-cell-0-0').style.backgroundColor).toBe('');
expect(document.querySelector('#jspsych-serial-reaction-time-stimulus-cell-0-1').style.backgroundColor).toBe('rgb(153, 153, 153)');
expect(document.querySelector('#jspsych-serial-reaction-time-stimulus-cell-0-2').style.backgroundColor).toBe('');
expect(document.querySelector('#jspsych-serial-reaction-time-stimulus-cell-0-3').style.backgroundColor).toBe('');
utils.pressKey('3');
expect(jsPsych.getDisplayElement().innerHTML).toBe('');
var trial_data = jsPsych.data.get().last(2).values();
expect(trial_data[0].correct).toBe(true);
expect(trial_data[1].correct).toBe(false);
}); });

View File

@ -37,7 +37,7 @@ describe('survey-html-form plugin', function(){
expect(jsPsych.getDisplayElement().innerHTML).toBe(''); expect(jsPsych.getDisplayElement().innerHTML).toBe('');
// Check whether data is parsed properly // Check whether data is parsed properly
var data = JSON.parse(jsPsych.data.get().values()[0].responses) var data = jsPsych.data.get().values()[0].responses;
expect(data.second).toBe(TEST_VALUE) expect(data.second).toBe(TEST_VALUE)
}); });

View File

@ -37,7 +37,7 @@ describe('survey-likert plugin', function(){
utils.clickTarget(document.querySelector('#jspsych-survey-likert-next')); utils.clickTarget(document.querySelector('#jspsych-survey-likert-next'));
var survey_data = JSON.parse(jsPsych.data.get().values()[0].responses); var survey_data = jsPsych.data.get().values()[0].responses;
expect(survey_data.Q0).toBe(0); expect(survey_data.Q0).toBe(0);
expect(survey_data.Q1).toBe(1); expect(survey_data.Q1).toBe(1);
expect(survey_data.Q2).toBe(2); expect(survey_data.Q2).toBe(2);

View File

@ -37,7 +37,7 @@ describe('survey-multi-choice plugin', function(){
utils.clickTarget(document.querySelector('#jspsych-survey-multi-choice-next')); utils.clickTarget(document.querySelector('#jspsych-survey-multi-choice-next'));
var survey_data = JSON.parse(jsPsych.data.get().values()[0].responses); var survey_data = jsPsych.data.get().values()[0].responses;
expect(survey_data.Q0).toBe('a'); expect(survey_data.Q0).toBe('a');
expect(survey_data.Q1).toBe('b'); expect(survey_data.Q1).toBe('b');
expect(survey_data.Q2).toBe('c'); expect(survey_data.Q2).toBe('c');

View File

@ -60,7 +60,7 @@ describe('survey-multi-select plugin', function(){
utils.clickTarget(document.querySelector('#jspsych-survey-multi-select-next')); utils.clickTarget(document.querySelector('#jspsych-survey-multi-select-next'));
var survey_data = JSON.parse(jsPsych.data.get().values()[0].responses); var survey_data = jsPsych.data.get().values()[0].responses;
expect(survey_data.Q0[0]).toBe('a'); expect(survey_data.Q0[0]).toBe('a');
expect(survey_data.Q1[0]).toBe('b'); expect(survey_data.Q1[0]).toBe('b');
expect(survey_data.Q2[0]).toBe('c'); expect(survey_data.Q2[0]).toBe('c');

View File

@ -104,7 +104,7 @@ describe('survey-text plugin', function(){
utils.clickTarget(document.querySelector('#jspsych-survey-text-next')); utils.clickTarget(document.querySelector('#jspsych-survey-text-next'));
var survey_data = JSON.parse(jsPsych.data.get().values()[0].responses); var survey_data = jsPsych.data.get().values()[0].responses;
expect(survey_data.Q0).toBe('a0'); expect(survey_data.Q0).toBe('a0');
expect(survey_data.Q1).toBe('a1'); expect(survey_data.Q1).toBe('a1');
expect(survey_data.Q2).toBe('a2'); expect(survey_data.Q2).toBe('a2');