-
Notifications
You must be signed in to change notification settings - Fork 1
/
ld_trials.js
209 lines (194 loc) · 5.9 KB
/
ld_trials.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/*
* This file contains all the possible discrete sub trials of
* a lexical decision task.
*/
/*
* Presents the fixation cross
*/
let present_fixation = {
type: jsPsychHtmlKeyboardResponse,
stimulus: '<span style="font-size:40px;">+</span>',
choices: "NO_KEYS",
trial_duration: FIXCROSS_DURATION,
on_finish: function(data) {
if (typeof data.rt == "number") {
data.rt = Math.round(data.rt);
}
}
};
/*
* This stimulus will present a forward mask
*/
let forward_mask = {
type: jsPsychHtmlKeyboardResponse,
stimulus: function(){
return "<p class='stimulus'>" +
jsPsych.timelineVariable('forward_mask', true) +
"</p>";
},
choices: "NO_KEYS",
trial_duration: MASK_DURATION,
data: { useful_data_flag: false },
on_finish(data) {
if (typeof data.rt == "number") {
data.rt = Math.round(data.rt);
}
}
};
/*
* This stimulus will present a visual prime stimulus
*/
let visual_prime = {
type: jsPsychHtmlKeyboardResponse,
stimulus: function(){
return "<p class='stimulus'>" +
jsPsych.timelineVariable('visual_prime', true) + "</p>";
},
choices: "NO_KEYS",
trial_duration: PRIME_DURATION,
post_trial_gap: PRIME_GAP_DURATION,
on_finish(data) {
if (typeof data.rt == "number") {
data.rt = Math.round(data.rt);
}
}
};
/*
* This will present an auditory prime stimulus.
*/
let auditory_prime = {
type : jsPsychAudioKeyboardResponse,
stimulus : function() {return jsPsych.timelineVariable("auditory_prime");},
choices : "NO_KEYS",
trial_duration : PRIME_DURATION,
post_trial_gap : PRIME_GAP_DURATION,
on_finish(data) {
if (typeof data.rt == "number") {
data.rt = Math.round(data.rt);
}
}
}
/*
* this will present a backwards mask.
*/
let backward_mask = {
type: jsPsychHtmlKeyboardResponse,
stimulus: function(){
return "<p class='stimulus'>" +
jsPsych.timelineVariable('backward_mask', true) +
"</p>";
},
choices: "NO_KEYS",
trial_duration: MASK_DURATION,
data: { useful_data_flag: false },
on_finish(data) {
if (typeof data.rt == "number") {
data.rt = Math.round(data.rt);
}
}
}
/**
* Returns an array that represents the allowed choices to respond.
*
* @return {(string|*)[]}
*/
function createChoicesArray() {
return [getWordKey(), getNonWordKey()];
}
/*
* This saves the data of a visual or auditory target stimulus
*/
function saveTargetData(data) {
let word_key = getWordKey();
let answer = null;
let pressed_key = null;
if (data.response !== null) {
pressed_key = data.response.toUpperCase();
}
// Add "static" information to output
data.id = jsPsych.timelineVariable('id');
data.condition = jsPsych.timelineVariable('item_type');
data.word = jsPsych.timelineVariable('word');
data.expected_answer = jsPsych.timelineVariable('expected_answer');
data.forward_mask = jsPsych.timelineVariable('forward_mask');
data.visual_prime = jsPsych.timelineVariable('visual_prime');
data.auditory_prime = jsPsych.timelineVariable('auditory_prime');
data.backward_mask = jsPsych.timelineVariable('backward_mask');
data.auditory_target = jsPsych.timelineVariable('auditory_target');
data.visual_target = jsPsych.timelineVariable('visual_target');
data.useful_data_flag = true; // Mark this stimulus as import for analysis.
// compute correctness, pressed_key could be null in case of no response.
if (typeof pressed_key === 'string') {
answer = pressed_key === word_key ? 1 : 0;
}
// Add dynamic info to output.
data.answer = answer;
data.correct = answer === data.expected_answer;
// Some find an integer representation of a boolean handy for analysis.
data.integer_correct = data.correct ? 1 : 0;
data.pressed_key = pressed_key;
if (typeof data.rt == "number") {
data.rt = Math.round(data.rt);
}
}
/*
* This will present an auditory target word. The participant should
* decide whether it is a word or not.
*
* Note: At would be at least weird to have both an auditory and a visual target.
*/
let auditory_target = {
type: jsPsychAudioKeyboardResponse,
stimulus: function() {
return jsPsych.timelineVariable('auditory_target')
},
choices: createChoicesArray,
trial_duration: RESPONSE_TIMEOUT_DURATION,
response_ends_trial: true,
post_trial_gap: DEFAULT_ITI,
on_finish: function(data) {
saveTargetData(data);
}
};
/*
* This will present an visual target word. The participant should
* decide whether it is a word or not.
*
* Note: At would be at least weird to have both an auditory and a visual target.
*/
let visual_target = {
type: jsPsychHtmlKeyboardResponse,
stimulus: function() {
return "<p class='stimulus'>" +
jsPsych.timelineVariable('visual_target', true) +
"</p>";
},
choices: createChoicesArray,
trial_duration: RESPONSE_TIMEOUT_DURATION,
response_ends_trial: true,
post_trial_gap: DEFAULT_ITI,
on_finish: function(data) {
saveTargetData(data);
}
};
let present_feedback = {
type: jsPsychHtmlKeyboardResponse,
stimulus: function() {
let incorrect_feedback_text =
`<span class="feedback_incorrect">${INCORRECT_TEXT}</span>`;
let correct_feedback_text =
`<span class="feedback_correct">${CORRECT_TEXT}</span>`;
let last_resp_acc = jsPsych.data.getLastTrialData().values()[0].correct;
if (last_resp_acc === true) {
return correct_feedback_text
}
return incorrect_feedback_text;
},
choices: "NO_KEYS",
trial_duration: FEEDBACK_DURATION,
on_finish(data) {
if (typeof data.rt == "number") {
data.rt = Math.round(data.rt);
}
}
};