-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgonogo.html
139 lines (123 loc) · 4.55 KB
/
gonogo.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
<!DOCTYPE html>
<html>
<head>
<title>Go/No-go</title>
<script src="./dist/jspsych.js"></script>
<script src="./dist/plugin-html-keyboard-response.js"></script>
<script src="./dist/plugin-html-button-response.js"></script>
<script src="./dist/plugin-fullscreen.js"></script>
<script src="./config/variables.js"></script>
<script src="./config/jp.js"></script> <!-- Use en.js for English instructions, ja.js for Japanese -->
<link href="./dist/jspsych.css" rel="stylesheet" type="text/css" />
<link href="./style/style.css" rel="stylesheet" type="text/css" />
</head>
<body></body>
<script>
function generateFixedRatioArray(length, target, target_probability) {
let array = [];
const totalSpecial = Math.round(length * target_probability);
const otherNumbersCount = length - totalSpecial;
for (let i = 0; i < totalSpecial; i++) {
array.push(target);
}
for (let i = 0; i < otherNumbersCount; i++) {
let randomNumber;
do {
randomNumber = Math.floor(Math.random() * 9) + 1;
} while (randomNumber === target);
array.push(randomNumber);
}
// 配列をシャッフル
array = array.sort(() => Math.random() - 0.5);
return array;
}
function test_stimuli () {
const array = generateFixedRatioArray(gonogo.trial_length, gonogo.trial_target, gonogo.trial_target_probability);
const stimuli = [];
for (let i = 0; i < array.length; i++) {
if (array[i] === 3) {
stimuli.push({ stimulus: `<span style="font-size: 6rem; font-weight: bold;">${array[i]}</span>`, correct_response: "" });
} else {
stimuli.push({ stimulus: `<span style="font-size: 6rem; font-weight: bold;">${array[i]}</span>`, correct_response: " " });
}
}
return stimuli;
}
const jsPsych = initJsPsych({
on_finish: function() {
jsPsych.data.displayData(); // for debugging
}
});
let timeline = [];
const enter_fullscreen = {
type: jsPsychFullscreen,
fullscreen_mode: true,
message: lang.fullscreen,
button_label: lang.utils.next
}
const welcome = {
type: jsPsychHtmlButtonResponse,
stimulus: lang.welcome,
choices: [lang.utils.next]
};
const instructions = {
type: jsPsychHtmlButtonResponse,
stimulus: lang.instructions.gonogo,
choices: [lang.utils.next]
};
const beginTask = {
type: jsPsychHtmlButtonResponse,
stimulus: lang.begin,
choices: [lang.utils.next],
post_trial_gap: interstimuli_interval.instructions
};
timeline.push(enter_fullscreen, welcome, instructions, beginTask);
const test = {
type: jsPsychHtmlKeyboardResponse,
stimulus: jsPsych.timelineVariable('stimulus'),
trial_duration: gonogo.trial_duration,
post_trial_gap: gonogo.interstimuli_interval,
choices: [" ", ""],
data: {
task: 'response',
correct_response: jsPsych.timelineVariable('correct_response')
},
on_finish: function(data){
if (data.response == null && data.correct_response == "") { // if not the target, no response is correct but returns null in data.response so make it rue as it is correct
data.correct = true;
} else {
data.correct = jsPsych.pluginAPI.compareKeys(data.response, data.correct_response); // if the target, compare the response with the correct response
}
}
}
const test_procedure = {
timeline: [test],
timeline_variables: test_stimuli()
}
timeline.push(test_procedure);
const end = {
type: jsPsychHtmlButtonResponse,
stimulus: lang.end,
choices: [lang.utils.finish]
};
const exit_fullscreen = {
type: jsPsychFullscreen,
fullscreen_mode: false,
delay_after: 0
}
timeline.push(end, exit_fullscreen);
// for debugging...
const debrief_block = {
type: jsPsychHtmlKeyboardResponse,
stimulus: function() {
const trials = jsPsych.data.get().filter({task: 'response'});
const correct_trials = trials.filter({correct: true});
const accuracy = Math.round(correct_trials.count() / trials.count() * 100);
// const rt = Math.round(correct_trials.select('rt').mean());
return feedback(accuracy);
}
};
timeline.push(debrief_block);
jsPsych.run(timeline);
</script>
</html>