-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoddball.html
203 lines (166 loc) · 5.58 KB
/
oddball.html
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
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/[email protected]"></script>
<script src="https://unpkg.com/@jspsych/[email protected]"></script>
<script src="https://unpkg.com/@jspsych/[email protected]"></script>
<script src="https://unpkg.com/@jspsych/[email protected]"></script>
<script src="https://unpkg.com/@jspsych/[email protected]"></script>
<script src="https://unpkg.com/@jspsych/[email protected]"></script>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/css/jspsych.css" />
<script src="./js/helper.js"></script>
</head>
<body>
<script>
var group,stage,n_blocks,n_per_block,participant,session
let url= new URL(window.location.href);
let params = new URLSearchParams(url.search);
group=params.get('group')
stage=parseInt(params.get('stage'))
var download=parseInt(params.get('download'))
n_blocks=parseInt(params.get('nb'))
n_per_block=parseInt(params.get('npb'))
if(!n_blocks) n_blocks=3
if(!n_per_block) n_per_block=100
if(isNaN(download)) download=0
window.localStorage.setItem(`oddball_markers_${stage}`,'[]')
oddball_markers= window.localStorage.getItem(`oddball_markers_${stage}`)
if(!oddball_markers) oddball_markers=[]
participant=window.localStorage.getItem('participant')
session=window.localStorage.getItem('session')
if(!stage) stage=1
if(!group) group='undefined'
console.log(group,stage,n_blocks,n_per_block,participant,session,oddball_markers)
/* initialize jsPsych */
const jsPsych = initJsPsych({show_progress_bar: true});
let timeline=[]
const preload = {
type: jsPsychPreload,
auto_preload: true
}
timeline.push(preload);
let welcome = {
type: jsPsychHtmlKeyboardResponse,
stimulus: `<h1> Welcome to the experiment.<h1>
<h1 style='color:blue'> Press any key to start ... </h1>`
};
timeline.push(welcome);
// const start = {
// type: jsPsychHtmlKeyboardResponse,
// stimulus: "<h1> Press any key to continue further ... </h1>",
// // on_load:async ()=>await setup_muse(muse_client),
// };
// timeline.push(start);
let even_stimulus= 'audio/500hz_50ms.wav'
let odd_stimulus= 'audio/2000hz_50ms.wav'
function insert_marker(marker){
triggerKeyPress(marker)
oddball_markers=addToMarkers({timestamp:getTimeInSec(),marker},`oddball_markers_${stage}`)
}
let test_indices=[...new Array(n_per_block).keys()]
let n_stim= Math.floor(n_per_block/8.0) + Math.floor(Math.random() * n_per_block/8.0) + 1
let audio_arr=test_indices.map(el=>0)
// console.log(n_stim )
for(let i = 0; i < n_stim ; i++)
{
while(true)
{
let loc= Math.floor(Math.random() * (n_per_block-1)) + 1
if(audio_arr[loc-1] !=1 && audio_arr[loc] !=1 && audio_arr[loc+1]!=1)
{
audio_arr[loc]=1
break
}
}
}
let test_counter=0
let trial_block=1
const oddball_selection=()=>{
let response=even_stimulus
if(audio_arr[test_counter]==1) {
insert_marker(1001)
response= odd_stimulus
}
else insert_marker(1002)
test_counter+=1
// console.log(test_counter)
if(test_counter==n_per_block) {
test_counter= 0
// trial_block+=1
}
return response
}
let fixation = {
type: jsPsychHtmlKeyboardResponse,
stimulus: '<div style="font-size:700px;">+</div>',
choices: "NO_KEYS",
trial_duration: 500,
data: {
task: 'fixation'
}
};
const trial = {
type: jsPsychAudioKeyboardResponse,
stimulus: oddball_selection,
choices: "NO_KEYS",
prompt:`<img src="img/speaker.png" alt="Speaker Image" width="200" height="200">`,
post_trial_gap: 900,
trial_ends_after_audio: true,
};
const trial_procedure={
timeline: [trial],
timeline_variables: test_counter,
repetitions: n_per_block,
randomize_order: true
}
const block_change = {
type: jsPsychHtmlKeyboardResponse,
// choices: "NO_KEYS",
stimulus: ()=>{return `<h1> Trial Block No: ${trial_block}/${n_blocks}</h1>
<h1 style='color:blue'> Press any key to start this trial block`},
// trial_duration: 3000,
on_finish: ()=>{
trial_block+=1
}
};
var survey_step = {
type: jsPsychSurvey,
pages: [
[
{
type: 'text',
prompt: "How many odd sounds did you hear?",
placeholder: '',
name: 'oddcount',
required: true,
},
],
],
title: 'Oddball Assessment',
button_label_finish: 'Submit',
// show_question_numbers: 'onPage'
};
const trial_blocks={
timeline: [fixation,block_change,trial_procedure,survey_step],
timeline_variables: test_counter,
repetitions: n_blocks,
randomize_order: true
}
timeline.push(trial_blocks);
const end = {
type: jsPsychHtmlKeyboardResponse,
stimulus: ()=>{
window.localStorage.setItem('stage',stage+1)
window.location.href=`exp.html?stage=${stage+1}`
},
choices: "NO_KEYS",
on_start: () => {
console.log(n_stim,oddball_markers)
if(download > 0) saveToCsv(oddball_markers)
},
};
timeline.push(end)
jsPsych.run(timeline);
</script>
</body>
</html>