mirror of
https://github.com/jspsych/jsPsych.git
synced 2025-05-12 08:38:11 +00:00
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:
commit
47d2f40cd6
@ -128,7 +128,7 @@ var trial = {
|
||||
prompt: function() {
|
||||
// this question prompt is dynamic - the text that is shown
|
||||
// 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+"?"
|
||||
return text;
|
||||
},
|
||||
|
@ -22,8 +22,8 @@ In addition to the [default data collected by all plugins](/overview/plugins#dat
|
||||
|
||||
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.
|
||||
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.
|
||||
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 | 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
|
||||
|
||||
|
@ -27,7 +27,7 @@ In addition to the [default data collected by all plugins](/overview/plugins#dat
|
||||
|
||||
| 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. |
|
||||
| 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. |
|
||||
|
@ -32,9 +32,9 @@ In addition to the [default data collected by all plugins](/overview/plugins#dat
|
||||
|
||||
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.
|
||||
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.
|
||||
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.
|
||||
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 | 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 | 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.
|
||||
|
||||
## Examples
|
||||
|
@ -25,7 +25,7 @@ In addition to the [default data collected by all plugins](/overview/plugins#dat
|
||||
|
||||
| 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. |
|
||||
|
||||
## Example
|
||||
|
@ -23,9 +23,9 @@ In addition to the [default data collected by all plugins](/overview/plugins#dat
|
||||
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.
|
||||
labels | JSON string | A string in JSON format containing the labels corresponding to the left and right response columns.
|
||||
left | string | The alternative endorsed on the left column.
|
||||
right | string | The alternative endorsed on the right column.
|
||||
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 selected on the left column.
|
||||
right | string | The alternative selected on the right column.
|
||||
|
||||
|
||||
## Examples
|
||||
|
@ -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. |
|
||||
| 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. |
|
||||
| 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_height | numeric | The height of the canvas in pixels. |
|
||||
|
||||
|
@ -24,7 +24,7 @@ In addition to the [default data collected by all plugins](/overview/plugins#dat
|
||||
|
||||
| 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. |
|
||||
| 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. |
|
||||
|
@ -24,7 +24,7 @@ In addition to the [default data collected by all plugins](/overview/plugins#dat
|
||||
|
||||
| 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. |
|
||||
| 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. |
|
||||
|
@ -25,8 +25,8 @@ In addition to the [default data collected by all plugins](/overview/plugins#dat
|
||||
|
||||
| Name | Type | Value |
|
||||
| ------ | ------- | ---------------------------------------- |
|
||||
| grid | JSON | A JSON-encoded representation of the grid. |
|
||||
| target | JSON | A JSON-encoded representation of the target on 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 | 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. |
|
||||
|
||||
## Examples
|
||||
|
@ -27,8 +27,8 @@ In addition to the [default data collected by all plugins](/overview/plugins#dat
|
||||
|
||||
| Name | Type | Value |
|
||||
| --------- | ------- | ---------------------------------------- |
|
||||
| grid | JSON | A JSON-encoded representation of the grid. |
|
||||
| target | JSON | A JSON-encoded representation of the target on 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 | 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. |
|
||||
| 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. |
|
||||
|
@ -21,8 +21,8 @@ In addition to the [default data collected by all plugins](/overview/plugins#dat
|
||||
|
||||
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.
|
||||
rt | numeric | The response time in milliseconds for the subject to make a response.
|
||||
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. |
|
||||
|
||||
## Examples
|
||||
|
||||
|
@ -21,9 +21,9 @@ In addition to the [default data collected by all plugins](/overview/plugins#dat
|
||||
|
||||
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.
|
||||
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.
|
||||
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]`.
|
||||
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(s) are submitted. |
|
||||
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
|
||||
|
||||
|
@ -20,9 +20,9 @@ In addition to the [default data collected by all plugins](/overview/plugins#dat
|
||||
|
||||
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.
|
||||
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.
|
||||
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]`.
|
||||
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(s) are submitted. |
|
||||
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
|
||||
|
||||
|
@ -21,9 +21,9 @@ In addition to the [default data collected by all plugins](/overview/plugins#dat
|
||||
|
||||
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.
|
||||
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.
|
||||
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]`.
|
||||
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(s) were submitted. |
|
||||
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
|
||||
|
||||
|
@ -20,9 +20,9 @@ In addition to the [default data collected by all plugins](/overview/plugins#dat
|
||||
|
||||
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.
|
||||
rt | numeric | The response time in milliseconds for the subject to make a response.
|
||||
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]`.
|
||||
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. The time is measured from when the questions first appear on the screen until the subject's response(s) were submitted. |
|
||||
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
|
||||
|
||||
|
@ -35,9 +35,9 @@ In addition to the [default data collected by all plugins](/overview/plugins#dat
|
||||
|
||||
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.
|
||||
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.
|
||||
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.
|
||||
stimulus | array | The `stimulus` array. This will be encoded as a JSON string when data is saved using the `.json()` or `.csv()` functions.
|
||||
|
||||
## Example
|
||||
|
||||
|
@ -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. |
|
||||
| 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
|
||||
|
||||
|
@ -41,8 +41,8 @@ Name | Type | Value
|
||||
-----|------|------
|
||||
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.
|
||||
stimulus | string | JSON encoding of the `stimulus` array.
|
||||
slider_start | numeric | The starting value of the slider.
|
||||
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.
|
||||
start | numeric | The start time of the video clip.
|
||||
|
||||
## Example
|
||||
|
@ -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. |
|
||||
| set_size | numeric | The number of items 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
|
||||
|
||||
|
@ -29,8 +29,8 @@ In addition to the [default data collected by all plugins](/overview/plugins#dat
|
||||
|
||||
| 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. |
|
||||
| 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. |
|
||||
| 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 | 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
|
||||
|
||||
|
@ -20,7 +20,7 @@ In addition to the [default data collected by all plugins](/overview/plugins#dat
|
||||
|
||||
| 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
|
||||
|
||||
|
@ -1816,6 +1816,9 @@ jsPsych.data = (function() {
|
||||
var line = '';
|
||||
for (var j = 0; j < columns.length; j++) {
|
||||
var value = (typeof array[i][columns[j]] === 'undefined') ? '' : array[i][columns[j]];
|
||||
if(typeof value == 'object') {
|
||||
value = JSON.stringify(value);
|
||||
}
|
||||
var valueString = value + "";
|
||||
line += '"' + valueString.replace(/"/g, '""') + '",';
|
||||
}
|
||||
|
@ -177,8 +177,8 @@ jsPsych.plugins.animation = (function() {
|
||||
jsPsych.pluginAPI.cancelKeyboardResponse(response_listener);
|
||||
|
||||
var trial_data = {
|
||||
"animation_sequence": JSON.stringify(animation_sequence),
|
||||
"responses": JSON.stringify(responses)
|
||||
animation_sequence: animation_sequence,
|
||||
responses: responses
|
||||
};
|
||||
|
||||
jsPsych.finishTrial(trial_data);
|
||||
|
@ -237,10 +237,10 @@ jsPsych.plugins["categorize-animation"] = (function() {
|
||||
responded = true;
|
||||
|
||||
trial_data = {
|
||||
"stimulus": JSON.stringify(trial.stimuli),
|
||||
"rt": info.rt,
|
||||
"correct": correct,
|
||||
"key_press": info.key
|
||||
stimulus: trial.stimuli,
|
||||
rt: info.rt,
|
||||
correct: correct,
|
||||
key_press: info.key
|
||||
};
|
||||
|
||||
jsPsych.pluginAPI.cancelKeyboardResponse(keyboard_listener);
|
||||
|
@ -362,10 +362,10 @@ jsPsych.plugins['free-sort'] = (function() {
|
||||
}
|
||||
|
||||
const trial_data = {
|
||||
"init_locations": JSON.stringify(init_locations),
|
||||
"moves": JSON.stringify(moves),
|
||||
"final_locations": JSON.stringify(final_locations),
|
||||
"rt": rt
|
||||
init_locations: init_locations,
|
||||
moves: moves,
|
||||
final_locations: final_locations,
|
||||
rt: rt
|
||||
};
|
||||
|
||||
// advance to next part
|
||||
|
@ -191,8 +191,8 @@ jsPsych.plugins.instructions = (function() {
|
||||
display_element.innerHTML = '';
|
||||
|
||||
var trial_data = {
|
||||
"view_history": JSON.stringify(view_history),
|
||||
"rt": performance.now() - start_time
|
||||
view_history: view_history,
|
||||
rt: performance.now() - start_time
|
||||
};
|
||||
|
||||
jsPsych.finishTrial(trial_data);
|
||||
|
@ -157,10 +157,10 @@ jsPsych.plugins['maxdiff'] = (function () {
|
||||
|
||||
// data saving
|
||||
var trial_data = {
|
||||
"rt": response_time,
|
||||
"labels": JSON.stringify({"left": trial.labels[0], "right": trial.labels[1]}),
|
||||
"left": get_response('left'),
|
||||
"right": get_response('right')
|
||||
rt: response_time,
|
||||
labels: {"left": trial.labels[0], "right": trial.labels[1]},
|
||||
left: get_response('left'),
|
||||
right: get_response('right')
|
||||
};
|
||||
|
||||
// next trial
|
||||
|
@ -522,44 +522,44 @@ jsPsych.plugins["rdk"] = (function() {
|
||||
|
||||
//Place all the data to be saved from this trial in one data object
|
||||
var trial_data = {
|
||||
"rt": response.rt, //The response time
|
||||
"key_press": response.key, //The key that the subject pressed
|
||||
"correct": correctOrNot(), //If the subject response was correct
|
||||
"choices": trial.choices, //The set of valid keys
|
||||
"correct_choice": trial.correct_choice, //The correct choice
|
||||
"trial_duration": trial.trial_duration, //The trial duration
|
||||
"response_ends_trial": trial.response_ends_trial, //If the response ends the trial
|
||||
"number_of_apertures": trial.number_of_apertures,
|
||||
"number_of_dots": trial.number_of_dots,
|
||||
"number_of_sets": trial.number_of_sets,
|
||||
"coherent_direction": trial.coherent_direction,
|
||||
"coherence": trial.coherence,
|
||||
"opposite_coherence": trial.opposite_coherence,
|
||||
"dot_radius": trial.dot_radius,
|
||||
"dot_life": trial.dot_life,
|
||||
"move_distance": trial.move_distance,
|
||||
"aperture_width": trial.aperture_width,
|
||||
"aperture_height": trial.aperture_height,
|
||||
"dot_color": trial.dot_color,
|
||||
"background_color": trial.background_color,
|
||||
"RDK_type": trial.RDK_type,
|
||||
"aperture_type": trial.aperture_type,
|
||||
"reinsert_type": trial.reinsert_type,
|
||||
"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
|
||||
"number_of_frames": numberOfFrames, //The number of frames in this trial
|
||||
"aperture_center_x": trial.aperture_center_x,
|
||||
"aperture_center_y": trial.aperture_center_y,
|
||||
"fixation_cross": trial.fixation_cross,
|
||||
"fixation_cross_width": trial.fixation_cross_width,
|
||||
"fixation_cross_height": trial.fixation_cross_height,
|
||||
"fixation_cross_color": trial.fixation_cross_color,
|
||||
"fixation_cross_thickness": trial.fixation_cross_thickness,
|
||||
"border": trial.border,
|
||||
"border_thickness": trial.border_thickness,
|
||||
"border_color": trial.border_color,
|
||||
"canvas_width": canvasWidth,
|
||||
"canvas_height": canvasHeight
|
||||
rt: response.rt, //The response time
|
||||
key_press: response.key, //The key that the subject pressed
|
||||
correct: correctOrNot(), //If the subject response was correct
|
||||
choices: trial.choices, //The set of valid keys
|
||||
correct_choice: trial.correct_choice, //The correct choice
|
||||
trial_duration: trial.trial_duration, //The trial duration
|
||||
response_ends_trial: trial.response_ends_trial, //If the response ends the trial
|
||||
number_of_apertures: trial.number_of_apertures,
|
||||
number_of_dots: trial.number_of_dots,
|
||||
number_of_sets: trial.number_of_sets,
|
||||
coherent_direction: trial.coherent_direction,
|
||||
coherence: trial.coherence,
|
||||
opposite_coherence: trial.opposite_coherence,
|
||||
dot_radius: trial.dot_radius,
|
||||
dot_life: trial.dot_life,
|
||||
move_distance: trial.move_distance,
|
||||
aperture_width: trial.aperture_width,
|
||||
aperture_height: trial.aperture_height,
|
||||
dot_color: trial.dot_color,
|
||||
background_color: trial.background_color,
|
||||
RDK_type: trial.RDK_type,
|
||||
aperture_type: trial.aperture_type,
|
||||
reinsert_type: trial.reinsert_type,
|
||||
frame_rate: frameRate, //The average frame rate for the trial
|
||||
frame_rate_array: frameRateArray, //The array of ms per frame in this trial
|
||||
number_of_frames: numberOfFrames, //The number of frames in this trial
|
||||
aperture_center_x: trial.aperture_center_x,
|
||||
aperture_center_y: trial.aperture_center_y,
|
||||
fixation_cross: trial.fixation_cross,
|
||||
fixation_cross_width: trial.fixation_cross_width,
|
||||
fixation_cross_height: trial.fixation_cross_height,
|
||||
fixation_cross_color: trial.fixation_cross_color,
|
||||
fixation_cross_thickness: trial.fixation_cross_thickness,
|
||||
border: trial.border,
|
||||
border_thickness: trial.border_thickness,
|
||||
border_color: trial.border_color,
|
||||
canvas_width: canvasWidth,
|
||||
canvas_height: canvasHeight
|
||||
|
||||
}
|
||||
|
||||
|
@ -136,11 +136,11 @@ jsPsych.plugins['same-different-html'] = (function() {
|
||||
}
|
||||
|
||||
var trial_data = {
|
||||
"rt": info.rt,
|
||||
"answer": trial.answer,
|
||||
"correct": correct,
|
||||
"stimulus": JSON.stringify([trial.stimuli[0], trial.stimuli[1]]),
|
||||
"key_press": info.key
|
||||
rt: info.rt,
|
||||
answer: trial.answer,
|
||||
correct: correct,
|
||||
stimulus: [trial.stimuli[0], trial.stimuli[1]],
|
||||
key_press: info.key
|
||||
};
|
||||
if (first_stim_info) {
|
||||
trial_data["rt_stim1"] = first_stim_info.rt;
|
||||
|
@ -137,11 +137,11 @@ jsPsych.plugins['same-different-image'] = (function() {
|
||||
}
|
||||
|
||||
var trial_data = {
|
||||
"rt": info.rt,
|
||||
"answer": trial.answer,
|
||||
"correct": correct,
|
||||
"stimulus": JSON.stringify([trial.stimuli[0], trial.stimuli[1]]),
|
||||
"key_press": info.key
|
||||
rt: info.rt,
|
||||
answer: trial.answer,
|
||||
correct: correct,
|
||||
stimulus: [trial.stimuli[0], trial.stimuli[1]],
|
||||
key_press: info.key
|
||||
};
|
||||
if (first_stim_info) {
|
||||
trial_data["rt_stim1"] = first_stim_info.rt;
|
||||
|
@ -151,12 +151,12 @@ jsPsych.plugins["serial-reaction-time-mouse"] = (function() {
|
||||
|
||||
// gather the data to store for the trial
|
||||
var trial_data = {
|
||||
"rt": response.rt,
|
||||
"grid": JSON.stringify(trial.grid),
|
||||
"target": JSON.stringify(trial.target),
|
||||
"response_row": response.row,
|
||||
"response_column": response.column,
|
||||
"correct": response.row == trial.target[0] && response.column == trial.target[1]
|
||||
rt: response.rt,
|
||||
grid: trial.grid,
|
||||
target: trial.target,
|
||||
response_row: response.row,
|
||||
response_column: response.column,
|
||||
correct: response.row == trial.target[0] && response.column == trial.target[1]
|
||||
};
|
||||
|
||||
// clear the display
|
||||
|
@ -171,11 +171,11 @@ jsPsych.plugins["serial-reaction-time"] = (function() {
|
||||
|
||||
// gather the data to store for the trial
|
||||
var trial_data = {
|
||||
"rt": response.rt,
|
||||
"key_press": response.key,
|
||||
"correct": response.correct,
|
||||
"grid": JSON.stringify(trial.grid),
|
||||
"target": JSON.stringify(trial.target)
|
||||
rt: response.rt,
|
||||
key_press: response.key,
|
||||
correct: response.correct,
|
||||
grid: trial.grid,
|
||||
target: trial.target
|
||||
};
|
||||
|
||||
// clear the display
|
||||
|
@ -105,8 +105,8 @@ jsPsych.plugins['survey-html-form'] = (function() {
|
||||
|
||||
// save data
|
||||
var trialdata = {
|
||||
"rt": response_time,
|
||||
"responses": JSON.stringify(question_data)
|
||||
rt: response_time,
|
||||
responses: question_data
|
||||
};
|
||||
|
||||
display_element.innerHTML = '';
|
||||
|
@ -177,9 +177,9 @@ jsPsych.plugins['survey-likert'] = (function() {
|
||||
|
||||
// save data
|
||||
var trial_data = {
|
||||
"rt": response_time,
|
||||
"responses": JSON.stringify(question_data),
|
||||
"question_order": JSON.stringify(question_order)
|
||||
rt: response_time,
|
||||
responses: question_data,
|
||||
question_order: question_order
|
||||
};
|
||||
|
||||
display_element.innerHTML = '';
|
||||
|
@ -191,9 +191,9 @@ jsPsych.plugins['survey-multi-choice'] = (function() {
|
||||
}
|
||||
// save data
|
||||
var trial_data = {
|
||||
"rt": response_time,
|
||||
"responses": JSON.stringify(question_data),
|
||||
"question_order": JSON.stringify(question_order)
|
||||
rt: response_time,
|
||||
responses: question_data,
|
||||
question_order: question_order
|
||||
};
|
||||
display_element.innerHTML = '';
|
||||
|
||||
|
@ -215,8 +215,8 @@ jsPsych.plugins['survey-multi-select'] = (function() {
|
||||
// save data
|
||||
var trial_data = {
|
||||
"rt": response_time,
|
||||
"responses": JSON.stringify(question_data),
|
||||
"question_order": JSON.stringify(question_order)
|
||||
"responses": question_data,
|
||||
"question_order": question_order
|
||||
};
|
||||
display_element.innerHTML = '';
|
||||
|
||||
|
@ -168,8 +168,8 @@ jsPsych.plugins['survey-text'] = (function() {
|
||||
}
|
||||
// save data
|
||||
var trialdata = {
|
||||
"rt": response_time,
|
||||
"responses": JSON.stringify(question_data)
|
||||
rt: response_time,
|
||||
responses: question_data
|
||||
};
|
||||
|
||||
display_element.innerHTML = '';
|
||||
|
@ -263,9 +263,9 @@ jsPsych.plugins["video-button-response"] = (function() {
|
||||
|
||||
// gather the data to store for the trial
|
||||
var trial_data = {
|
||||
"rt": response.rt,
|
||||
"stimulus": JSON.stringify(trial.stimulus),
|
||||
"button_pressed": response.button
|
||||
rt: response.rt,
|
||||
stimulus: trial.stimulus,
|
||||
button_pressed: response.button
|
||||
};
|
||||
|
||||
// clear the display
|
||||
|
@ -227,9 +227,9 @@ jsPsych.plugins["video-keyboard-response"] = (function() {
|
||||
|
||||
// gather the data to store for the trial
|
||||
var trial_data = {
|
||||
"rt": response.rt,
|
||||
"stimulus": JSON.stringify(trial.stimulus),
|
||||
"key_press": response.key
|
||||
rt: response.rt,
|
||||
stimulus: trial.stimulus,
|
||||
key_press: response.key
|
||||
};
|
||||
|
||||
// clear the display
|
||||
|
@ -317,11 +317,11 @@ jsPsych.plugins["video-slider-response"] = (function() {
|
||||
|
||||
// gather the data to store for the trial
|
||||
var trial_data = {
|
||||
"rt": response.rt,
|
||||
"stimulus": JSON.stringify(trial.stimulus),
|
||||
"start": trial.start,
|
||||
"slider_start": trial.slider_start,
|
||||
"response": response.response
|
||||
rt: response.rt,
|
||||
stimulus: trial.stimulus,
|
||||
start: trial.start,
|
||||
slider_start: trial.slider_start,
|
||||
response: response.response
|
||||
};
|
||||
|
||||
// clear the display
|
||||
|
@ -235,7 +235,7 @@ jsPsych.plugins["visual-search-circle"] = (function() {
|
||||
correct: correct,
|
||||
rt: rt,
|
||||
key_press: key_press,
|
||||
locations: JSON.stringify(display_locs),
|
||||
locations: display_locs,
|
||||
target_present: trial.target_present,
|
||||
set_size: trial.set_size
|
||||
};
|
||||
|
@ -184,8 +184,8 @@ jsPsych.plugins['vsl-animate-occlusion'] = (function() {
|
||||
jsPsych.pluginAPI.cancelKeyboardResponse(key_listener);
|
||||
|
||||
var trial_data = {
|
||||
"stimuli": JSON.stringify(trial.stimuli),
|
||||
"responses": JSON.stringify(responses)
|
||||
stimuli: trial.stimuli,
|
||||
responses: responses
|
||||
};
|
||||
|
||||
jsPsych.finishTrial(trial_data);
|
||||
|
@ -57,7 +57,7 @@ jsPsych.plugins['vsl-grid-scene'] = (function() {
|
||||
display_element.innerHTML = '';
|
||||
|
||||
var trial_data = {
|
||||
"stimulus": JSON.stringify(trial.stimuli)
|
||||
stimulus: trial.stimuli
|
||||
};
|
||||
|
||||
jsPsych.finishTrial(trial_data);
|
||||
|
85
tests/jsPsych.data/data-csv-conversion.test.js
Normal file
85
tests/jsPsych.data/data-csv-conversion.test.js
Normal 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')
|
||||
})
|
||||
|
||||
});
|
120
tests/jsPsych.data/data-json-conversion.test.js
Normal file
120
tests/jsPsych.data/data-json-conversion.test.js
Normal 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);
|
||||
})
|
||||
|
||||
});
|
@ -63,6 +63,7 @@ describe('DataCollection', function(){
|
||||
});
|
||||
test('#values', function(){
|
||||
expect(JSON.stringify(jsPsych.data.get().values())).toBe(JSON.stringify(data));
|
||||
expect(jsPsych.data.get().values()).toBe(data);
|
||||
});
|
||||
test('#first', function(){
|
||||
expect(jsPsych.data.get().first(3).count()).toBe(3);
|
||||
|
@ -136,5 +136,22 @@ describe('cloze', function(){
|
||||
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');
|
||||
});
|
||||
});
|
@ -63,4 +63,23 @@ describe('instructions plugin', function(){
|
||||
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);
|
||||
})
|
||||
|
||||
});
|
||||
|
@ -14,4 +14,48 @@ describe('rdk plugin', function(){
|
||||
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);
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -62,7 +62,47 @@ describe('serial-reaction-time plugin', function(){
|
||||
jest.runTimersToTime(1000);
|
||||
|
||||
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);
|
||||
|
||||
});
|
||||
|
||||
|
@ -37,7 +37,7 @@ describe('survey-html-form plugin', function(){
|
||||
expect(jsPsych.getDisplayElement().innerHTML).toBe('');
|
||||
|
||||
// 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)
|
||||
});
|
||||
|
||||
|
@ -37,7 +37,7 @@ describe('survey-likert plugin', function(){
|
||||
|
||||
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.Q1).toBe(1);
|
||||
expect(survey_data.Q2).toBe(2);
|
||||
|
@ -37,7 +37,7 @@ describe('survey-multi-choice plugin', function(){
|
||||
|
||||
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.Q1).toBe('b');
|
||||
expect(survey_data.Q2).toBe('c');
|
||||
|
@ -60,7 +60,7 @@ describe('survey-multi-select plugin', function(){
|
||||
|
||||
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.Q1[0]).toBe('b');
|
||||
expect(survey_data.Q2[0]).toBe('c');
|
||||
|
@ -104,7 +104,7 @@ describe('survey-text plugin', function(){
|
||||
|
||||
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.Q1).toBe('a1');
|
||||
expect(survey_data.Q2).toBe('a2');
|
||||
|
Loading…
Reference in New Issue
Block a user