-
Notifications
You must be signed in to change notification settings - Fork 0
/
triplet_task.html
144 lines (109 loc) · 5.95 KB
/
triplet_task.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
<!DOCTYPE html>
<html>
<head>
<title>Triplet task</title>
<script src='jatos.js'></script>
<script src='./jspsych-6.3.1/jspsych.js'></script>
<script src='./extra_functions/lodash.js'></script>
<script src='./extra_functions/jquery-3.4.1.js' type='text/javascript'></script>
<script src="./extra_functions/jspsych-triplets-keyboard-response.js"></script>
<script src="./jspsych-6.3.1/plugins/jspsych-preload.js"></script>
<script src="./jspsych-6.3.1/plugins/jspsych-html-keyboard-response.js"></script>
<link href='./jspsych-6.3.1/css/jspsych.css' rel='stylesheet' type='text/css'>
</link>
<link href='./extra_files/custom.css' rel='stylesheet' type='text/css'>
</link>
</head>
<body></body>
<script>
jatos.onLoad(function () {
// debugger
var session_trials = []
var trial_stage_name = []
// Is this practice, pre or post
if (jatos.studySessionData.inputData.session_counters.practice == 0) {
jatos.studySessionData.inputData.session_counters.practice++
session_trials = jatos.studySessionData.inputData.triplet_practice_trials[jatos.studySessionData.inputData.session_counters.practice - 1]
trial_stage_name = 'practice'
} else if (jatos.studySessionData.inputData.session_counters.exposure == 0) {
jatos.studySessionData.inputData.session_counters.pre_exposure++
session_trials = jatos.studySessionData.inputData.pre_exposure_trials[jatos.studySessionData.inputData.session_counters.pre_exposure - 1]
trial_stage_name = 'pre_exposure'
} else {
jatos.studySessionData.inputData.session_counters.post_exposure++
session_trials = jatos.studySessionData.inputData.post_exposure_trials[jatos.studySessionData.inputData.session_counters.post_exposure - 1]
trial_stage_name = 'post_exposure'
}
var trial = {
type: 'triplets-keyboard-response',
query_stimulus: jsPsych.timelineVariable('query_stimulus'),
ref_left_stimulus: jsPsych.timelineVariable('ref_left_stimulus'),
ref_right_stimulus: jsPsych.timelineVariable('ref_right_stimulus'),
ref_left_y_offset: jsPsych.timelineVariable('ref_left_y_offset'),
ref_right_y_offset: jsPsych.timelineVariable('ref_right_y_offset'),
stimulus_height: 400,
choices: ['q', 'p'],
trial_duration: jatos.studySessionData.inputData.experiment_parameters.triplet_trial_dur,
post_response_delay: jatos.studySessionData.inputData.experiment_parameters.triplet_trial_iti,
stim_min_duration: jatos.studySessionData.inputData.experiment_parameters.triplet_stim_min_duration,
data: { trial_stage: trial_stage_name },
on_finish: function (data) {
// Counterbalancing condition?
data.cb_condition = jatos.studySessionData.inputData.cb_condition
// What session is this
data.session = jatos.studySessionData.inputData.session_counters[trial_stage_name]
if (jsPsych.timelineVariable('correct_response') == null) {
data.correct = null
data.correct_response = null
} else if (jsPsych.pluginAPI.compareKeys(data.response, jsPsych.timelineVariable('correct_response'))) {
data.correct = true;
data.correct_response = jsPsych.timelineVariable('correct_response')
} else {
data.correct = false
data.correct_response = jsPsych.timelineVariable('correct_response')
}
}
}
var session_procedure = {
timeline: [trial],
timeline_variables: session_trials,
randomize_order: false,
post_trial_gap: 0,
}
// Preload trial
var all_query_images = session_trials.map(item => item.query_stimulus)
var all_ref_left_images = session_trials.map(item => item.ref_left_stimulus)
var all_ref_right_images = session_trials.map(item => item.ref_right_stimulus)
var all_images_preload = [...all_query_images,...all_ref_left_images,...all_ref_right_images]
var preload_trial = {
type: 'preload',
images: all_images_preload
}
jsPsych.init({
timeline: [preload_trial, session_procedure],
on_finish: function (data) {
// debugger
// Get the data and save it!
if (jatos.studySessionData.inputData.session_counters.pre_exposure == 0) {
jatos.studySessionData.outputData.practice.push(...data.values().filter(item => item.trial_stage == trial_stage_name))
} else if (jatos.studySessionData.inputData.session_counters.exposure == 0) {
jatos.studySessionData.outputData.pre_exposure.push(...data.values().filter(item => item.trial_stage == trial_stage_name))
} else {
jatos.studySessionData.outputData.post_exposure.push(...data.values().filter(item => item.trial_stage == trial_stage_name))
}
// Make JATOS remember that this session was run
jatos.studySessionData.latestFinishedComponentId = jatos.componentId;
jatos.studySessionData.latestFinishedComponentPos = jatos.componentPos;
jatos.studySessionData.latestFinishedComponentTitle = jatos.componentProperties.title;
jatos.submitResultData("[triplet_task_start---" +
JSON.stringify(jatos.studySessionData) + "---triplet_task_end]",
function () {
jatos.startComponentByPos(
jatos.studySessionData.inputData.component_positions.break
)
})
}
});
}); // jatos on load
</script>
</html>