diff --git a/docs/overview/dynamic-parameters.md b/docs/overview/dynamic-parameters.md index 87d1c349..fa98bb32 100644 --- a/docs/overview/dynamic-parameters.md +++ b/docs/overview/dynamic-parameters.md @@ -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; }, diff --git a/docs/plugins/jspsych-animation.md b/docs/plugins/jspsych-animation.md index 0389ff1e..dda01f1a 100644 --- a/docs/plugins/jspsych-animation.md +++ b/docs/plugins/jspsych-animation.md @@ -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 diff --git a/docs/plugins/jspsych-categorize-animation.md b/docs/plugins/jspsych-categorize-animation.md index 03e554d6..efb09536 100644 --- a/docs/plugins/jspsych-categorize-animation.md +++ b/docs/plugins/jspsych-categorize-animation.md @@ -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. | diff --git a/docs/plugins/jspsych-free-sort.md b/docs/plugins/jspsych-free-sort.md index 305da808..a97c85c4 100644 --- a/docs/plugins/jspsych-free-sort.md +++ b/docs/plugins/jspsych-free-sort.md @@ -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 diff --git a/docs/plugins/jspsych-instructions.md b/docs/plugins/jspsych-instructions.md index a2e9bcbb..efb063fc 100644 --- a/docs/plugins/jspsych-instructions.md +++ b/docs/plugins/jspsych-instructions.md @@ -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 diff --git a/docs/plugins/jspsych-maxdiff.md b/docs/plugins/jspsych-maxdiff.md index 07407da9..765b85df 100644 --- a/docs/plugins/jspsych-maxdiff.md +++ b/docs/plugins/jspsych-maxdiff.md @@ -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 diff --git a/docs/plugins/jspsych-rdk.md b/docs/plugins/jspsych-rdk.md index 6d209fd2..ac27c95f 100644 --- a/docs/plugins/jspsych-rdk.md +++ b/docs/plugins/jspsych-rdk.md @@ -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. | diff --git a/docs/plugins/jspsych-same-different-html.md b/docs/plugins/jspsych-same-different-html.md index c9bfedf8..c30cdd81 100644 --- a/docs/plugins/jspsych-same-different-html.md +++ b/docs/plugins/jspsych-same-different-html.md @@ -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. | diff --git a/docs/plugins/jspsych-same-different-image.md b/docs/plugins/jspsych-same-different-image.md index 89397736..2913d401 100644 --- a/docs/plugins/jspsych-same-different-image.md +++ b/docs/plugins/jspsych-same-different-image.md @@ -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. | diff --git a/docs/plugins/jspsych-serial-reaction-time-mouse.md b/docs/plugins/jspsych-serial-reaction-time-mouse.md index 261474a9..6fcba331 100644 --- a/docs/plugins/jspsych-serial-reaction-time-mouse.md +++ b/docs/plugins/jspsych-serial-reaction-time-mouse.md @@ -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 diff --git a/docs/plugins/jspsych-serial-reaction-time.md b/docs/plugins/jspsych-serial-reaction-time.md index 916cb012..6252d279 100644 --- a/docs/plugins/jspsych-serial-reaction-time.md +++ b/docs/plugins/jspsych-serial-reaction-time.md @@ -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. | diff --git a/docs/plugins/jspsych-survey-html-form.md b/docs/plugins/jspsych-survey-html-form.md index c6731897..c2361ac0 100644 --- a/docs/plugins/jspsych-survey-html-form.md +++ b/docs/plugins/jspsych-survey-html-form.md @@ -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 diff --git a/docs/plugins/jspsych-survey-likert.md b/docs/plugins/jspsych-survey-likert.md index 82e1e0e3..d54d26e4 100644 --- a/docs/plugins/jspsych-survey-likert.md +++ b/docs/plugins/jspsych-survey-likert.md @@ -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 diff --git a/docs/plugins/jspsych-survey-multi-choice.md b/docs/plugins/jspsych-survey-multi-choice.md index 839c8334..e42630ac 100644 --- a/docs/plugins/jspsych-survey-multi-choice.md +++ b/docs/plugins/jspsych-survey-multi-choice.md @@ -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 diff --git a/docs/plugins/jspsych-survey-multi-select.md b/docs/plugins/jspsych-survey-multi-select.md index 488cd42e..2b8985c3 100644 --- a/docs/plugins/jspsych-survey-multi-select.md +++ b/docs/plugins/jspsych-survey-multi-select.md @@ -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 diff --git a/docs/plugins/jspsych-survey-text.md b/docs/plugins/jspsych-survey-text.md index 19e1caa9..b3ebcb7e 100644 --- a/docs/plugins/jspsych-survey-text.md +++ b/docs/plugins/jspsych-survey-text.md @@ -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 diff --git a/docs/plugins/jspsych-video-button-response.md b/docs/plugins/jspsych-video-button-response.md index 8636d2a1..5835b48f 100644 --- a/docs/plugins/jspsych-video-button-response.md +++ b/docs/plugins/jspsych-video-button-response.md @@ -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 diff --git a/docs/plugins/jspsych-video-keyboard-response.md b/docs/plugins/jspsych-video-keyboard-response.md index a159f248..d9d6a6ef 100644 --- a/docs/plugins/jspsych-video-keyboard-response.md +++ b/docs/plugins/jspsych-video-keyboard-response.md @@ -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 diff --git a/docs/plugins/jspsych-video-slider-response.md b/docs/plugins/jspsych-video-slider-response.md index 8e79b585..c0031fcb 100644 --- a/docs/plugins/jspsych-video-slider-response.md +++ b/docs/plugins/jspsych-video-slider-response.md @@ -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 diff --git a/docs/plugins/jspsych-visual-search-circle.md b/docs/plugins/jspsych-visual-search-circle.md index 9d50aa12..9303d2f9 100644 --- a/docs/plugins/jspsych-visual-search-circle.md +++ b/docs/plugins/jspsych-visual-search-circle.md @@ -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 diff --git a/docs/plugins/jspsych-vsl-animate-occlusion.md b/docs/plugins/jspsych-vsl-animate-occlusion.md index 6aaa3a35..be0aba4b 100644 --- a/docs/plugins/jspsych-vsl-animate-occlusion.md +++ b/docs/plugins/jspsych-vsl-animate-occlusion.md @@ -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 diff --git a/docs/plugins/jspsych-vsl-grid-scene.md b/docs/plugins/jspsych-vsl-grid-scene.md index 9e76e9e1..2a104c96 100644 --- a/docs/plugins/jspsych-vsl-grid-scene.md +++ b/docs/plugins/jspsych-vsl-grid-scene.md @@ -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 diff --git a/jspsych.js b/jspsych.js index f3dfece4..6d26d298 100755 --- a/jspsych.js +++ b/jspsych.js @@ -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, '""') + '",'; } diff --git a/plugins/jspsych-animation.js b/plugins/jspsych-animation.js index 25fac133..e7acb123 100644 --- a/plugins/jspsych-animation.js +++ b/plugins/jspsych-animation.js @@ -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); diff --git a/plugins/jspsych-categorize-animation.js b/plugins/jspsych-categorize-animation.js index db1fe096..7ce7ddc2 100644 --- a/plugins/jspsych-categorize-animation.js +++ b/plugins/jspsych-categorize-animation.js @@ -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); diff --git a/plugins/jspsych-free-sort.js b/plugins/jspsych-free-sort.js index 70966e49..fdbd5e33 100644 --- a/plugins/jspsych-free-sort.js +++ b/plugins/jspsych-free-sort.js @@ -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 diff --git a/plugins/jspsych-instructions.js b/plugins/jspsych-instructions.js index 1418e71c..fab70469 100644 --- a/plugins/jspsych-instructions.js +++ b/plugins/jspsych-instructions.js @@ -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); diff --git a/plugins/jspsych-maxdiff.js b/plugins/jspsych-maxdiff.js index b30d4325..9ec0ff8d 100644 --- a/plugins/jspsych-maxdiff.js +++ b/plugins/jspsych-maxdiff.js @@ -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 diff --git a/plugins/jspsych-rdk.js b/plugins/jspsych-rdk.js index da98d091..a287dfae 100644 --- a/plugins/jspsych-rdk.js +++ b/plugins/jspsych-rdk.js @@ -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 } diff --git a/plugins/jspsych-same-different-html.js b/plugins/jspsych-same-different-html.js index df61d471..753b94e3 100644 --- a/plugins/jspsych-same-different-html.js +++ b/plugins/jspsych-same-different-html.js @@ -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; diff --git a/plugins/jspsych-same-different-image.js b/plugins/jspsych-same-different-image.js index 8b7e20e6..5de1fd8f 100644 --- a/plugins/jspsych-same-different-image.js +++ b/plugins/jspsych-same-different-image.js @@ -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; diff --git a/plugins/jspsych-serial-reaction-time-mouse.js b/plugins/jspsych-serial-reaction-time-mouse.js index 1c3ea987..cdf9b7bb 100644 --- a/plugins/jspsych-serial-reaction-time-mouse.js +++ b/plugins/jspsych-serial-reaction-time-mouse.js @@ -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 diff --git a/plugins/jspsych-serial-reaction-time.js b/plugins/jspsych-serial-reaction-time.js index 011c24d3..d962c4a5 100644 --- a/plugins/jspsych-serial-reaction-time.js +++ b/plugins/jspsych-serial-reaction-time.js @@ -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 diff --git a/plugins/jspsych-survey-html-form.js b/plugins/jspsych-survey-html-form.js index ac7ac8e8..5a66b08a 100644 --- a/plugins/jspsych-survey-html-form.js +++ b/plugins/jspsych-survey-html-form.js @@ -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 = ''; diff --git a/plugins/jspsych-survey-likert.js b/plugins/jspsych-survey-likert.js index 452d2767..45dcd278 100644 --- a/plugins/jspsych-survey-likert.js +++ b/plugins/jspsych-survey-likert.js @@ -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 = ''; diff --git a/plugins/jspsych-survey-multi-choice.js b/plugins/jspsych-survey-multi-choice.js index 9a6a57a0..281c0f2e 100644 --- a/plugins/jspsych-survey-multi-choice.js +++ b/plugins/jspsych-survey-multi-choice.js @@ -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 = ''; diff --git a/plugins/jspsych-survey-multi-select.js b/plugins/jspsych-survey-multi-select.js index 8ffd0b86..3f7755cd 100644 --- a/plugins/jspsych-survey-multi-select.js +++ b/plugins/jspsych-survey-multi-select.js @@ -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 = ''; diff --git a/plugins/jspsych-survey-text.js b/plugins/jspsych-survey-text.js index b6a15593..33861783 100644 --- a/plugins/jspsych-survey-text.js +++ b/plugins/jspsych-survey-text.js @@ -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 = ''; diff --git a/plugins/jspsych-video-button-response.js b/plugins/jspsych-video-button-response.js index cb3e29c8..5fe8c256 100644 --- a/plugins/jspsych-video-button-response.js +++ b/plugins/jspsych-video-button-response.js @@ -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 diff --git a/plugins/jspsych-video-keyboard-response.js b/plugins/jspsych-video-keyboard-response.js index 15a09bee..ff805a0b 100644 --- a/plugins/jspsych-video-keyboard-response.js +++ b/plugins/jspsych-video-keyboard-response.js @@ -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 diff --git a/plugins/jspsych-video-slider-response.js b/plugins/jspsych-video-slider-response.js index fa7a9601..6eab4401 100644 --- a/plugins/jspsych-video-slider-response.js +++ b/plugins/jspsych-video-slider-response.js @@ -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 diff --git a/plugins/jspsych-visual-search-circle.js b/plugins/jspsych-visual-search-circle.js index a8b0213b..79968ae7 100644 --- a/plugins/jspsych-visual-search-circle.js +++ b/plugins/jspsych-visual-search-circle.js @@ -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 }; diff --git a/plugins/jspsych-vsl-animate-occlusion.js b/plugins/jspsych-vsl-animate-occlusion.js index aaa54106..a001c031 100644 --- a/plugins/jspsych-vsl-animate-occlusion.js +++ b/plugins/jspsych-vsl-animate-occlusion.js @@ -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); diff --git a/plugins/jspsych-vsl-grid-scene.js b/plugins/jspsych-vsl-grid-scene.js index fe5b8210..6e6422b2 100644 --- a/plugins/jspsych-vsl-grid-scene.js +++ b/plugins/jspsych-vsl-grid-scene.js @@ -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); diff --git a/tests/jsPsych.data/data-csv-conversion.test.js b/tests/jsPsych.data/data-csv-conversion.test.js new file mode 100644 index 00000000..748d6f39 --- /dev/null +++ b/tests/jsPsych.data/data-csv-conversion.test.js @@ -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: ['
Climbing
', 'Walking
'], + answer: 'different', + gap_duration: 0, + first_stim_duration: null + } + + var timeline = [trial]; + + jsPsych.init({timeline: timeline}); + + expect(jsPsych.getDisplayElement().innerHTML).toMatch('Climbing
'); + utils.pressKey('q'); + jest.runAllTimers(); + expect(jsPsych.getDisplayElement().innerHTML).toMatch('Walking
'); + 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","[""Climbing
"",""Walking
""]","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') + }) + +}); \ No newline at end of file diff --git a/tests/jsPsych.data/data-json-conversion.test.js b/tests/jsPsych.data/data-json-conversion.test.js new file mode 100644 index 00000000..e5658926 --- /dev/null +++ b/tests/jsPsych.data/data-json-conversion.test.js @@ -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: ['Climbing
', 'Walking
'], + answer: 'different', + gap_duration: 0, + first_stim_duration: null + } + + var timeline = [trial]; + + jsPsych.init({timeline: timeline}); + + expect(jsPsych.getDisplayElement().innerHTML).toMatch('Climbing
'); + utils.pressKey('q'); + jest.runAllTimers(); + expect(jsPsych.getDisplayElement().innerHTML).toMatch('Walking
'); + 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: ['Climbing
','Walking
'], 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); + }) + +}); \ No newline at end of file diff --git a/tests/jsPsych.data/datacollection.test.js b/tests/jsPsych.data/datacollection.test.js index f6160e26..ef5155f9 100644 --- a/tests/jsPsych.data/datacollection.test.js +++ b/tests/jsPsych.data/datacollection.test.js @@ -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); diff --git a/tests/plugins/plugin-cloze.test.js b/tests/plugins/plugin-cloze.test.js index 7520f303..bbb84202 100644 --- a/tests/plugins/plugin-cloze.test.js +++ b/tests/plugins/plugin-cloze.test.js @@ -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'); + }); }); \ No newline at end of file diff --git a/tests/plugins/plugin-instructions.test.js b/tests/plugins/plugin-instructions.test.js index b5fd801e..fb3b97d1 100644 --- a/tests/plugins/plugin-instructions.test.js +++ b/tests/plugins/plugin-instructions.test.js @@ -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); + }) + }); diff --git a/tests/plugins/plugin-rdk.test.js b/tests/plugins/plugin-rdk.test.js index 30c33952..5af3d2ab 100644 --- a/tests/plugins/plugin-rdk.test.js +++ b/tests/plugins/plugin-rdk.test.js @@ -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); + }); + }); diff --git a/tests/plugins/plugin-serial-reaction-time.test.js b/tests/plugins/plugin-serial-reaction-time.test.js index 6a9030b6..80d2798a 100644 --- a/tests/plugins/plugin-serial-reaction-time.test.js +++ b/tests/plugins/plugin-serial-reaction-time.test.js @@ -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); }); diff --git a/tests/plugins/plugin-survey-html-form.test.js b/tests/plugins/plugin-survey-html-form.test.js index d73ef2ba..21c369b5 100644 --- a/tests/plugins/plugin-survey-html-form.test.js +++ b/tests/plugins/plugin-survey-html-form.test.js @@ -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) }); diff --git a/tests/plugins/plugin-survey-likert.test.js b/tests/plugins/plugin-survey-likert.test.js index 73c241b6..bb73f9f0 100644 --- a/tests/plugins/plugin-survey-likert.test.js +++ b/tests/plugins/plugin-survey-likert.test.js @@ -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); diff --git a/tests/plugins/plugin-survey-multi-choice.test.js b/tests/plugins/plugin-survey-multi-choice.test.js index 0d1c982a..025e48ed 100644 --- a/tests/plugins/plugin-survey-multi-choice.test.js +++ b/tests/plugins/plugin-survey-multi-choice.test.js @@ -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'); diff --git a/tests/plugins/plugin-survey-multi-select.test.js b/tests/plugins/plugin-survey-multi-select.test.js index 3e941024..80804134 100644 --- a/tests/plugins/plugin-survey-multi-select.test.js +++ b/tests/plugins/plugin-survey-multi-select.test.js @@ -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'); diff --git a/tests/plugins/plugin-survey-text.test.js b/tests/plugins/plugin-survey-text.test.js index a59c0c1a..4761ab2d 100644 --- a/tests/plugins/plugin-survey-text.test.js +++ b/tests/plugins/plugin-survey-text.test.js @@ -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');