-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphase_pa.html
189 lines (147 loc) · 10.1 KB
/
phase_pa.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
<!DOCTYPE html>
<html>
<head>
<title>Phase PA</title>
<script src='jatos.js'></script>
<script src='./jspsych-6.1.0/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-plugin-concept-gen.js'></script>
<script src="./extra_functions/helper_functions.js"> </script>
<link href='./jspsych-6.1.0/css/jspsych.css' rel='stylesheet' type='text/css'></link>
<style> .score_box p {font-size: 14px }</style>
</head>
<body style="background-color:#99a3a4;"></body>
<script>
jatos.onLoad(function() {
// What phase is this?
[curr_phase,phase_string,curr_session,curr_global_trial] = getPhaseAndSession()
let curr_space_object = jatos.studySessionData.inputData.concepts[phase_string]
// reset the session trial counter
jatos.studySessionData.session_trial_counter = 1;
// If this for practice run?
if (jatos.componentProperties.title.includes('practice_trials')){
// Generate a full array of trials for a full session
var session_trials =
trialCreator(jatos.studySessionData.inputData.concepts[phase_string],
jatos.studySessionData.inputData.baseTrialArray[phase_string],
jatos.studySessionData.inputData.basic_parameters,
curr_phase,curr_session)
if (!(jatos.studySessionData.debug || jatos.studySessionData.pilot)){
// Now, choose trials such that each item is used at least twice
var practice_session_trials = []
let n_practice_trials_per_toy = jatos.studySessionData.n_practice_trials/jatos.studySessionData.inputData.basic_parameters.nTargets
for (iPointName of jatos.studySessionData.inputData.basic_parameters.targetPointNames[phase_string]){
// Find trials with this target
let curr_toy_trials = session_trials.filter(item => item.prompt_point_name == iPointName).slice(0,n_practice_trials_per_toy)
practice_session_trials = practice_session_trials.concat(curr_toy_trials)
}
// Shuffle practice_session_trials
session_trials = deepCopy(shuffle(practice_session_trials))
if (session_trials.length != jatos.studySessionData.n_practice_trials){
console.error('Number of practice trials is not correct!')
}
} else {
session_trials = session_trials.slice(0,jatos.studySessionData.n_practice_trials)
}
} else {
// So not practice trials
// Then, generate trials for this session
var session_trials =
trialCreator(jatos.studySessionData.inputData.concepts[phase_string],
jatos.studySessionData.inputData.baseTrialArray[phase_string],
jatos.studySessionData.inputData.basic_parameters,
curr_phase,curr_session)
}
// Record the current trial array in the outputData variable
jatos.studySessionData.outputData.phase_results =
jatos.studySessionData.outputData.phase_results.concat(session_trials)
let n_trials = session_trials.length
let imgs_to_preload = deepCopy(jatos.studySessionData.inputData.imgs_to_preload)
imgs_to_preload.exemplar_images = session_trials.map((item) => {
return item.ex_pairs_img_path
})
imgs_to_preload.exemplar_images =
imgs_to_preload.exemplar_images.concat(jatos.studySessionData.inputData.basic_parameters.targetPathsUsed[phase_string])
let prompt_text = 'Which of the two '+
jatos.studySessionData.inputData.concepts[phase_string].concept_object +'s below is hiding this toy?'
// //////////// PLUGIN INPUT //////////////////////////////
var session_procedure = {
timeline: [
{
type: 'plugin-concept-gen',
prompt_img_name: jsPsych.timelineVariable('prompt_img_name'),
prompt_img_path: jsPsych.timelineVariable('prompt_img_path'),
prompt_img_width: jatos.studySessionData.inputData.basic_parameters.prompt_target_width,
prompt_img_height: jatos.studySessionData.inputData.basic_parameters.prompt_target_height,
prompt_img_x_coords: jatos.studySessionData.inputData.basic_parameters.prompt_img_x_coords,
prompt_img_y_coords: jatos.studySessionData.inputData.basic_parameters.prompt_img_y_coords,
ex_pairs_img_path: jsPsych.timelineVariable('ex_pairs_img_path'),
ex_pairs_img_width: curr_space_object.ex_pairs_img_width,
ex_pairs_img_height: curr_space_object.ex_pairs_img_height,
ex_pairs_img_margin_top: curr_space_object.ex_pairs_img_margin_top,
ex_pairs_maintain_aspect_ratio: true,
onscreen_idx: ['1','2'],
onscreen_idx_x_coords: curr_space_object.onscreen_idx_x_coords,
onscreen_idx_y_coords: curr_space_object.onscreen_idx_y_coords,
fb_correct_img: jatos.studySessionData.inputData.basic_parameters.fb_correct_img,
fb_incorrect_img: jatos.studySessionData.inputData.basic_parameters.fb_incorrect_img,
// audio_stimulus: jatos.studySessionData.inputData.basic_parameters.audio_stimulus,
fb_img_paths: jsPsych.timelineVariable('item_img_paths'),
item_img_names: jsPsych.timelineVariable('item_img_names'),
fb_imgs_x_coords: curr_space_object.fb_imgs_x_coords,
fb_imgs_y_coords: curr_space_object.fb_imgs_y_coords,
sort_area_width: 750,
sort_area_height: 700,
prompt: prompt_text,
choices: jatos.studySessionData.inputData.choices,
response_ends_trial: true,
timer_after_response: jatos.studySessionData.timer_after_response,
timer_allow_space_key: jatos.studySessionData.timer_allow_space_key,
timer_response_window: jatos.studySessionData.timer_response_window,
post_trial_gap: jatos.studySessionData.post_trial_gap,
correct_response: jsPsych.timelineVariable('prompt_item_idx'),
n_trials: n_trials,
phase: jsPsych.timelineVariable('phase'),
session: jsPsych.timelineVariable('session'),
on_finish: function(data){
calcRunningPerf(data)
}
}
],
timeline_variables: session_trials
}; // session_procedure
jsPsych.init({
timeline: [session_procedure],
preload_images: [...imgs_to_preload.base_images, ...imgs_to_preload.exemplar_images],
on_finish: function(data) {
// What phase is this?
[curr_phase,phase_string,curr_session,curr_global_trial] = getPhaseAndSession()
// Make JATOS remember that this session was run
jatos.studySessionData.latestFinishedComponentId = jatos.componentId;
jatos.studySessionData.latestFinishedComponentPos = jatos.componentPos;
jatos.studySessionData.latestFinishedComponentTitle = jatos.componentProperties.title;
// submit results to JATOS
// Create a temporary variable to hold data of the latest run session, so qc can be performed on this
jatos.studySessionData.last_session_data =
deepCopy(jatos.studySessionData.outputData.phase_results.filter(item => item.session == curr_session && item.phase == curr_phase));
var results_delimiter_start = "[" + phase_string + "_ses_" + curr_session + "_start---"
var results_delimiter_end = "---" + phase_string + "_ses_" + curr_session + "_end]"
jatos.submitResultData(
results_delimiter_start +
JSON.stringify(jatos.studySessionData) +
results_delimiter_end, function(){
jatos.startComponentByPos(jatos.studySessionData.script_comp_pos.intermediate_feedback);
}
);
}
// on_finish: function(data) {
// console.log('Over');
// jsPsych.data.displayData('json');
// }
});
// ///////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
});
</script>
</html>