mirror of
https://github.com/jspsych/jsPsych.git
synced 2025-05-10 19:20:55 +00:00
change jsPsych.data.getData() to jsPsych.data.get()
This commit is contained in:
parent
a25351de60
commit
065fd8d4b0
@ -79,7 +79,7 @@
|
|||||||
type: "text",
|
type: "text",
|
||||||
text: function() {
|
text: function() {
|
||||||
|
|
||||||
var trials = jsPsych.data.getData().filter({test_part: 'test'});
|
var trials = jsPsych.data.get().filter({test_part: 'test'});
|
||||||
var correct_trials = trials.filter({correct: true});
|
var correct_trials = trials.filter({correct: true});
|
||||||
var accuracy = Math.round(correct_trials.count() / trials.count() * 100);
|
var accuracy = Math.round(correct_trials.count() / trials.count() * 100);
|
||||||
var rt = Math.round(correct_trials.select('rt').mean());
|
var rt = Math.round(correct_trials.select('rt').mean());
|
||||||
|
@ -204,7 +204,7 @@ window.jsPsych = (function() {
|
|||||||
jsPsych.data.write(data);
|
jsPsych.data.write(data);
|
||||||
|
|
||||||
// get back the data with all of the defaults in
|
// get back the data with all of the defaults in
|
||||||
var trial_data = jsPsych.data.getData().filter({trial_index: global_trial_index});
|
var trial_data = jsPsych.data.get().filter({trial_index: global_trial_index});
|
||||||
|
|
||||||
// for trial-level callbacks, we just want to pass in a reference to the values
|
// for trial-level callbacks, we just want to pass in a reference to the values
|
||||||
// of the DataCollection, for easy access and editing.
|
// of the DataCollection, for easy access and editing.
|
||||||
@ -766,7 +766,7 @@ window.jsPsych = (function() {
|
|||||||
document.webkitExitFullscreen();
|
document.webkitExitFullscreen();
|
||||||
}
|
}
|
||||||
|
|
||||||
opts.on_finish(jsPsych.data.getData());
|
opts.on_finish(jsPsych.data.get());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1187,7 +1187,7 @@ jsPsych.data = (function() {
|
|||||||
interactionData = DataCollection();
|
interactionData = DataCollection();
|
||||||
}
|
}
|
||||||
|
|
||||||
module.getData = function() {
|
module.get = function() {
|
||||||
return allData;
|
return allData;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -14,44 +14,44 @@ jsPsych.data._customInsert(data);
|
|||||||
|
|
||||||
describe('DataCollection', function(){
|
describe('DataCollection', function(){
|
||||||
test('#filter', function(){
|
test('#filter', function(){
|
||||||
expect(jsPsych.data.getData().filter({filter: true}).count()).toBe(2);
|
expect(jsPsych.data.get().filter({filter: true}).count()).toBe(2);
|
||||||
});
|
});
|
||||||
test('#filter OR', function(){
|
test('#filter OR', function(){
|
||||||
expect(jsPsych.data.getData().filter([{filter: true}, {rt: 300}]).count()).toBe(2);
|
expect(jsPsych.data.get().filter([{filter: true}, {rt: 300}]).count()).toBe(2);
|
||||||
expect(jsPsych.data.getData().filter([{filter: true}, {rt: 200}]).count()).toBe(3);
|
expect(jsPsych.data.get().filter([{filter: true}, {rt: 200}]).count()).toBe(3);
|
||||||
})
|
})
|
||||||
test('#filterCustom', function(){
|
test('#filterCustom', function(){
|
||||||
expect(jsPsych.data.getData().filterCustom(function(x){ return x.rt > 200 && x.filter == false}).count()).toBe(2);
|
expect(jsPsych.data.get().filterCustom(function(x){ return x.rt > 200 && x.filter == false}).count()).toBe(2);
|
||||||
});
|
});
|
||||||
test('#ignore', function(){
|
test('#ignore', function(){
|
||||||
expect(jsPsych.data.getData().ignore('rt').select('rt').count()).toBe(0);
|
expect(jsPsych.data.get().ignore('rt').select('rt').count()).toBe(0);
|
||||||
});
|
});
|
||||||
test('#select', function(){
|
test('#select', function(){
|
||||||
expect(JSON.stringify(jsPsych.data.getData().select('rt').values)).toBe(JSON.stringify([100,200,300,400,500]));
|
expect(JSON.stringify(jsPsych.data.get().select('rt').values)).toBe(JSON.stringify([100,200,300,400,500]));
|
||||||
});
|
});
|
||||||
test('#addToAll', function(){
|
test('#addToAll', function(){
|
||||||
expect(jsPsych.data.getData().readOnly().addToAll({added: 5}).select('added').count()).toBe(5);
|
expect(jsPsych.data.get().readOnly().addToAll({added: 5}).select('added').count()).toBe(5);
|
||||||
});
|
});
|
||||||
test('#addToLast', function(){
|
test('#addToLast', function(){
|
||||||
jsPsych.data.getData().addToLast({lastonly: true});
|
jsPsych.data.get().addToLast({lastonly: true});
|
||||||
expect(jsPsych.data.getData().values()[4].lastonly).toBe(true);
|
expect(jsPsych.data.get().values()[4].lastonly).toBe(true);
|
||||||
});
|
});
|
||||||
test('#readOnly', function(){
|
test('#readOnly', function(){
|
||||||
var d = jsPsych.data.getData().readOnly().values();
|
var d = jsPsych.data.get().readOnly().values();
|
||||||
d[0].rt = 0;
|
d[0].rt = 0;
|
||||||
expect(jsPsych.data.getData().values()[0].rt).toBe(100);
|
expect(jsPsych.data.get().values()[0].rt).toBe(100);
|
||||||
});
|
});
|
||||||
test('not #readOnly', function(){
|
test('not #readOnly', function(){
|
||||||
var d = jsPsych.data.getData().values();
|
var d = jsPsych.data.get().values();
|
||||||
d[0].rt = 0;
|
d[0].rt = 0;
|
||||||
expect(jsPsych.data.getData().values()[0].rt).toBe(0);
|
expect(jsPsych.data.get().values()[0].rt).toBe(0);
|
||||||
});
|
});
|
||||||
test('#count', function(){
|
test('#count', function(){
|
||||||
expect(jsPsych.data.getData().count()).toBe(5);
|
expect(jsPsych.data.get().count()).toBe(5);
|
||||||
});
|
});
|
||||||
test('#push', function(){
|
test('#push', function(){
|
||||||
jsPsych.data.getData().push({rt: 600, filter: true});
|
jsPsych.data.get().push({rt: 600, filter: true});
|
||||||
expect(jsPsych.data.getData().count()).toBe(6);
|
expect(jsPsych.data.get().count()).toBe(6);
|
||||||
data = [
|
data = [
|
||||||
{rt: 100, filter: true},
|
{rt: 100, filter: true},
|
||||||
{rt: 200, filter: false},
|
{rt: 200, filter: false},
|
||||||
@ -62,19 +62,19 @@ describe('DataCollection', function(){
|
|||||||
jsPsych.data._customInsert(data);
|
jsPsych.data._customInsert(data);
|
||||||
});
|
});
|
||||||
test('#values', function(){
|
test('#values', function(){
|
||||||
expect(JSON.stringify(jsPsych.data.getData().values())).toBe(JSON.stringify(data));
|
expect(JSON.stringify(jsPsych.data.get().values())).toBe(JSON.stringify(data));
|
||||||
});
|
});
|
||||||
test('#first', function(){
|
test('#first', function(){
|
||||||
expect(jsPsych.data.getData().first(3).count()).toBe(3);
|
expect(jsPsych.data.get().first(3).count()).toBe(3);
|
||||||
expect(jsPsych.data.getData().first(2).values()[1].rt).toBe(200);
|
expect(jsPsych.data.get().first(2).values()[1].rt).toBe(200);
|
||||||
});
|
});
|
||||||
test('#last', function(){
|
test('#last', function(){
|
||||||
expect(jsPsych.data.getData().last(2).count(2)).toBe(2);
|
expect(jsPsych.data.get().last(2).count(2)).toBe(2);
|
||||||
expect(jsPsych.data.getData().last(2).values()[0].rt).toBe(400);
|
expect(jsPsych.data.get().last(2).values()[0].rt).toBe(400);
|
||||||
});
|
});
|
||||||
test('#join', function(){
|
test('#join', function(){
|
||||||
var dc1 = jsPsych.data.getData().filter({filter: true});
|
var dc1 = jsPsych.data.get().filter({filter: true});
|
||||||
var dc2 = jsPsych.data.getData().filter({rt: 500});
|
var dc2 = jsPsych.data.get().filter({rt: 500});
|
||||||
var data = dc1.join(dc2);
|
var data = dc1.join(dc2);
|
||||||
expect(data.count()).toBe(3);
|
expect(data.count()).toBe(3);
|
||||||
expect(data.values()[2].rt).toBe(500);
|
expect(data.values()[2].rt).toBe(500);
|
||||||
|
@ -12,36 +12,39 @@ var data = [
|
|||||||
|
|
||||||
jsPsych.data._customInsert(data);
|
jsPsych.data._customInsert(data);
|
||||||
|
|
||||||
describe('DataCollection', function(){
|
describe('DataColumn', function(){
|
||||||
|
test('#sum', function(){
|
||||||
|
expect(jsPsych.data.get().select('rt').sum()).toBe(1500);
|
||||||
|
});
|
||||||
test('#mean', function(){
|
test('#mean', function(){
|
||||||
expect(jsPsych.data.getData().select('rt').mean()).toBe(300);
|
expect(jsPsych.data.get().select('rt').mean()).toBe(300);
|
||||||
});
|
});
|
||||||
test('#count', function(){
|
test('#count', function(){
|
||||||
expect(jsPsych.data.getData().select('rt').count()).toBe(5);
|
expect(jsPsych.data.get().select('rt').count()).toBe(5);
|
||||||
});
|
});
|
||||||
test('#min', function(){
|
test('#min', function(){
|
||||||
expect(jsPsych.data.getData().select('rt').min()).toBe(100);
|
expect(jsPsych.data.get().select('rt').min()).toBe(100);
|
||||||
});
|
});
|
||||||
test('#max', function(){
|
test('#max', function(){
|
||||||
expect(jsPsych.data.getData().select('rt').max()).toBe(500);
|
expect(jsPsych.data.get().select('rt').max()).toBe(500);
|
||||||
});
|
});
|
||||||
test('#variance', function(){
|
test('#variance', function(){
|
||||||
expect(jsPsych.data.getData().select('rt').variance()).toBe((Math.pow(200,2)+Math.pow(100,2)+Math.pow(100,2)+Math.pow(200,2))/5);
|
expect(jsPsych.data.get().select('rt').variance()).toBe((Math.pow(200,2)+Math.pow(100,2)+Math.pow(100,2)+Math.pow(200,2))/5);
|
||||||
});
|
});
|
||||||
test('#sd', function(){
|
test('#sd', function(){
|
||||||
expect(jsPsych.data.getData().select('rt').sd()).toBe(Math.sqrt((Math.pow(200,2)+Math.pow(100,2)+Math.pow(100,2)+Math.pow(200,2))/5));
|
expect(jsPsych.data.get().select('rt').sd()).toBe(Math.sqrt((Math.pow(200,2)+Math.pow(100,2)+Math.pow(100,2)+Math.pow(200,2))/5));
|
||||||
});
|
});
|
||||||
test('#median', function(){
|
test('#median', function(){
|
||||||
expect(jsPsych.data.getData().select('rt').median()).toBe(300);
|
expect(jsPsych.data.get().select('rt').median()).toBe(300);
|
||||||
});
|
});
|
||||||
test('#subset', function(){
|
test('#subset', function(){
|
||||||
expect(jsPsych.data.getData().select('rt').subset(function(x){ return x > 300; }).count()).toBe(2);
|
expect(jsPsych.data.get().select('rt').subset(function(x){ return x > 300; }).count()).toBe(2);
|
||||||
});
|
});
|
||||||
test('#frequencies', function(){
|
test('#frequencies', function(){
|
||||||
expect(jsPsych.data.getData().select('filter').frequencies()).toEqual({true:2, false: 3})
|
expect(jsPsych.data.get().select('filter').frequencies()).toEqual({true:2, false: 3})
|
||||||
});
|
});
|
||||||
test('#all', function(){
|
test('#all', function(){
|
||||||
expect(jsPsych.data.getData().select('rt').all(function(x){ return x < 600})).toBe(true);
|
expect(jsPsych.data.get().select('rt').all(function(x){ return x < 600})).toBe(true);
|
||||||
expect(jsPsych.data.getData().select('filter').all(function(x){ return x; })).toBe(false);
|
expect(jsPsych.data.get().select('filter').all(function(x){ return x; })).toBe(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -14,7 +14,7 @@ describe('Basic data recording', function(){
|
|||||||
document.dispatchEvent(new KeyboardEvent('keydown', {keyCode: 32}));
|
document.dispatchEvent(new KeyboardEvent('keydown', {keyCode: 32}));
|
||||||
document.dispatchEvent(new KeyboardEvent('keyup', {keyCode: 32}));
|
document.dispatchEvent(new KeyboardEvent('keyup', {keyCode: 32}));
|
||||||
// check if data contains rt
|
// check if data contains rt
|
||||||
expect(jsPsych.data.getData().select('rt').count()).toBe(1);
|
expect(jsPsych.data.get().select('rt').count()).toBe(1);
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -30,7 +30,7 @@ describe('#addProperties', function(){
|
|||||||
document.dispatchEvent(new KeyboardEvent('keydown', {keyCode: 32}));
|
document.dispatchEvent(new KeyboardEvent('keydown', {keyCode: 32}));
|
||||||
document.dispatchEvent(new KeyboardEvent('keyup', {keyCode: 32}));
|
document.dispatchEvent(new KeyboardEvent('keyup', {keyCode: 32}));
|
||||||
// check if data contains testprop
|
// check if data contains testprop
|
||||||
expect(jsPsych.data.getData().select('testprop').count()).toBe(1);
|
expect(jsPsych.data.get().select('testprop').count()).toBe(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should add data to all trials retroactively', function(){
|
test('should add data to all trials retroactively', function(){
|
||||||
@ -43,9 +43,9 @@ describe('#addProperties', function(){
|
|||||||
document.dispatchEvent(new KeyboardEvent('keydown', {keyCode: 32}));
|
document.dispatchEvent(new KeyboardEvent('keydown', {keyCode: 32}));
|
||||||
document.dispatchEvent(new KeyboardEvent('keyup', {keyCode: 32}));
|
document.dispatchEvent(new KeyboardEvent('keyup', {keyCode: 32}));
|
||||||
// check if data contains testprop
|
// check if data contains testprop
|
||||||
expect(jsPsych.data.getData().select('testprop').count()).toBe(0);
|
expect(jsPsych.data.get().select('testprop').count()).toBe(0);
|
||||||
jsPsych.data.addProperties({'testprop': 1});
|
jsPsych.data.addProperties({'testprop': 1});
|
||||||
expect(jsPsych.data.getData().select('testprop').count()).toBe(1);
|
expect(jsPsych.data.get().select('testprop').count()).toBe(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
@ -67,8 +67,8 @@ describe('#addDataToLastTrial', function(){
|
|||||||
document.dispatchEvent(new KeyboardEvent('keydown', {keyCode: 32}));
|
document.dispatchEvent(new KeyboardEvent('keydown', {keyCode: 32}));
|
||||||
document.dispatchEvent(new KeyboardEvent('keyup', {keyCode: 32}));
|
document.dispatchEvent(new KeyboardEvent('keyup', {keyCode: 32}));
|
||||||
// check data structure
|
// check data structure
|
||||||
expect(jsPsych.data.getData().select('testA').values[0]).toBe(1);
|
expect(jsPsych.data.get().select('testA').values[0]).toBe(1);
|
||||||
expect(jsPsych.data.getData().select('testB').values[0]).toBe(2);
|
expect(jsPsych.data.get().select('testB').values[0]).toBe(2);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ describe('The on_finish trial level event handler', function(){
|
|||||||
jsPsych.init({
|
jsPsych.init({
|
||||||
timeline: [trial],
|
timeline: [trial],
|
||||||
on_finish: function() {
|
on_finish: function() {
|
||||||
promise_data.final_key_press = jsPsych.data.getData().values()[0].key_press;
|
promise_data.final_key_press = jsPsych.data.get().values()[0].key_press;
|
||||||
resolve(promise_data);
|
resolve(promise_data);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user