-
Notifications
You must be signed in to change notification settings - Fork 1
/
task.html
160 lines (138 loc) · 6.25 KB
/
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<!DOCTYPE html>
<html>
<head>
<script src="p5/p5.min.js"></script>
<script src="jspsych-6.0.4/jspsych.js"></script>
<script src="jspsych-6.0.4/plugins/jspsych-html-keyboard-response.js"></script>
<script src="jspsych-6.0.4/plugins/jspsych-image-keyboard-response.js"></script>
<script src="jspsych-6.0.4/plugins/jspsych-audio-button-response.js"></script>
<script type="text/javascript" src="toxiclib/toxiclibs.min.js"></script>
<script src="utils/audio.js"></script>
<script src="utils/force_graph.js"></script>
<script src="utils/processing_sketches.js"></script>
<script src="audio-image-space.js"></script>
<script src="javascript/jquery-3.1.1.min.js"></script>
<script src="/assets/javascripts/jatos.js"></script>
<link href="static/css/forms.css" rel="stylesheet" type="text/css" media="all">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<script>
jatos.onLoad(function () {
/* create timeline */
var timeline = [];
var test_sounds = [];
var test_images = [];
var test_coordinates = [];
var test_colors = [];
var test_envelopes =[];
var sess =jatos.studySessionData;
console.log(sess);
console.log(`Task index ${sess.task_index}`);
var mode =sess.task_modes[sess.phase_index];
var samples = sess.task_dict[sess.phase_index][sess.task_index];
var sample_data = JSON.parse(sessionStorage.getItem("sample_data"));
console.log(sample_data)
var target_index = 0;
for (var i =0; i<samples.length; i++){
var index = samples[i];
console.log(index);
var sample= sample_data[index]
console.log(sample);
test_sounds.push(`static/audio/${sample.name}.mp3`);
if (sess.task_modes[sess.phase_index] =="TEXTURE"){
test_images.push(`static/image/${sample.name}.jpg`);
}
if (sess.task_modes[sess.phase_index] =="PRACTICE")(
target_index = Math.floor(Math.random(0, samples.length))
)
if (sess.phase_index ==5){
test_coordinates.push([Math.random()*0.8+0.1, Math.random()*0.8+0.1])
}
else{
//Limit coordinates to 0.1-0.9
let coords = [0,0];
coords[0] = 0.1 + sample.coords[0] *0.8;
coords[1] = 0.1 + sample.coords[1] *0.8
test_coordinates.push([coords[0], coords[1]])
}
test_colors.push([sample.color[0], sample.color[1], sample.color[2]])
test_envelopes.push(sample.env);
// test_envelopes.push(sample.env);
}
console.log(test_sounds);
console.log(test_images);
console.log(test_coordinates);
var lang = "default";
if (jatos.studySessionData.language){
lang = jatos.studySessionData.language
}
/* define image space trial */
var image_space = {
type:"audio-image-space",
sounds: test_sounds,
images: test_images,
colors: test_colors,
envelopes: test_envelopes,
mode :sess.task_modes[sess.phase_index],
coordinates : test_coordinates,
dims : [800,800],
image_size: 64,
target_index: 0,
task_index: sess.task_index,
phase_index: sess.phase_index,
num_trials: sess.num_tasks[sess.phase_index],
num_phases: sess.num_phases,
language : lang,
volume: sess.volume,
}
timeline.push(image_space);
jsPsych.init({
timeline: timeline,
preload_audio: test_sounds,
on_finish: function() {
var resultJson = jsPsych.data.get().json();
/* console.log ("Results:\n" +resultJson)
console.log("Incrementing task index") */
//console.log("Task index:" + jatos.studySessionData.task_index)
//Increment phase index
results= JSON.parse(resultJson)[0]
time = results["elapsed_time"];
misclick = results["num_misclicks"];
listens = results["listen_count"];
jatos.studySessionData.results[jatos.studySessionData.phase_index][jatos.studySessionData.task_index] =
{
"time": time,
"misclicks": misclick,
"listens": listens
};
jatos.studySessionData.volume = results.volume;
jatos.studySessionData.task_index += 1;
if (jatos.studySessionData.task_index >= jatos.studySessionData.num_tasks[jatos.studySessionData.phase_index]){
jatos.studySessionData.phase_index +=1;
jatos.studySessionData.task_index = 0;
if (jatos.studySessionData.phase_index == jatos.studySessionData.num_practices){
jatos.submitResultData(resultJson);
jatos.startComponentByPos(sess.studyStartComponentIndex);
}
//Go to questionnaire for last two task trials
if (jatos.studySessionData.phase_index == jatos.studySessionData.num_phases-1 ||jatos.studySessionData.phase_index == jatos.studySessionData.num_phases){
jatos.submitResultData(resultJson, jatos.startNextComponent);
}
//Just go to new phase description
else{
jatos.submitResultData(resultJson);
jatos.startComponentByPos(jatos.studySessionData.phaseComponentIndex);
}
}
//Continue tasks in current phase
else{
jatos.submitResultData(resultJson);
jatos.startComponentByPos(sess.taskComponentIndex);
}
}
});
});
</script>
</body>