mirror of
https://github.com/jspsych/jsPsych.git
synced 2025-05-10 19:20:55 +00:00
created jspsych-utils.js
added function to generate flat data array from hierarchical jspsych.data object.
This commit is contained in:
parent
34cffa2b14
commit
a08dbc7029
34
utils/jspsych-utils.js
Normal file
34
utils/jspsych-utils.js
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
/* utility package for jsPsych */
|
||||||
|
|
||||||
|
(function($) {
|
||||||
|
|
||||||
|
jsPsych.utils = (function(){
|
||||||
|
|
||||||
|
// public methods
|
||||||
|
var public_object = {};
|
||||||
|
|
||||||
|
// take the hierarchically arranged jsPsych.data object and turn it into
|
||||||
|
// a one-dimensional array where each entry is data from a single trial
|
||||||
|
// append_data is optional and can be items that should be added to all
|
||||||
|
// trials, such as a subject identifier
|
||||||
|
public_object.flatten_data_object = function(data_object, append_data={})
|
||||||
|
{
|
||||||
|
var trials = [];
|
||||||
|
|
||||||
|
// loop through data_object
|
||||||
|
for(var i = 0; i < data_object.length; i++)
|
||||||
|
{
|
||||||
|
for(var j = 0; j < data_object[i].length; j++)
|
||||||
|
{
|
||||||
|
var data = $.extend({}, data_object[i][j], append_data);
|
||||||
|
trials.push(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return trials;
|
||||||
|
}
|
||||||
|
|
||||||
|
return public_object;
|
||||||
|
})();
|
||||||
|
|
||||||
|
)(jQuery);
|
Loading…
Reference in New Issue
Block a user