forked from nerrull/timbre-study
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassign_task.html
More file actions
173 lines (142 loc) · 6.66 KB
/
assign_task.html
File metadata and controls
173 lines (142 loc) · 6.66 KB
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
<!DOCTYPE html>
<html>
<head>
<script src="javascript/jquery-3.1.1.min.js"></script>
<script src="/assets/javascripts/jatos.js"></script>
<link rel="stylesheet" href="bootstrap-3.3.7/css/bootstrap.min.css">
<link href="static/css/forms.css" rel="stylesheet" type="text/css" media="all">
<script src="utils/uuid.js"></script>
</head>
<body>
<div class= "TaskDescription">
<div id="description_div"></div>
<div id="next_button">...Loading study data</div>
</div>
</div>
</div>
<script>
function getRandomTaskID(){
let task_ids = ["TEXTURE", "COLOR", "SHAPE"]
let v = Math.floor (Math.random()*3);
return task_ids[v];
}
function shuffle(array) {
var currentIndex = array.length, temporaryValue, randomIndex;
// While there remain elements to shuffle...
while (0 !== currentIndex) {
// Pick a remaining element...
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;
// And swap it with the current element.
temporaryValue = array[currentIndex];
array[currentIndex] = array[randomIndex];
array[randomIndex] = temporaryValue;
}
return array;
}
function generateTaskSamples( studyData, mode){
var taskDict = {};
var samples = {}
var nTasks = [1,6,6,6,6,6];
// var nTasks = [1,1,1,1,1,1];
var nSamplesPerTask = [15,30,30,30,30,30];
// var nSamplesPerTask = [15,40,40,40,40,40];
// var nSamplesPerTask = [2,2,2,2,2,2];
var totalSamples = nTasks.map((v, i) => nSamplesPerTask[i]*v).reduce((pv, v) => pv+v)
console.log("Total study samples : " +totalSamples)
var actual_num_samples = studyData["n_samples"]
console.log("Number of samples : " + actual_num_samples )
var nTotalSamples = actual_num_samples;
var shuffleIndexes = [...Array(nTotalSamples)].map((_,i) => i);
sampleIndexes = shuffle(shuffleIndexes);
while (sampleIndexes.length < totalSamples){
let s2 = shuffle(shuffleIndexes.slice());
sampleIndexes = sampleIndexes.concat(s2);
console.log(sampleIndexes)
}
var nPhases = nTasks.length;
jatos.studySessionData["num_tasks"] = nTasks;
var task_modes = ["PRACTICE","BASELINE", "BASELINE", ...[...Array(3)].map((_,i)=>mode)]
jatos.studySessionData["task_modes"] = task_modes;
jatos.studySessionData["num_phases"] = nPhases;
results = {}
sampleIndex =0;
// Generate sample sets for tasks
for (var p =0; p<nPhases; p++){
taskDict[p]={};
results[p]={};
for (var t =0; t<nTasks[p]; t++){
var sampleList =[];
for (var s =0; s<nSamplesPerTask[p]; s++){
sampleList.push(sampleIndexes[sampleIndex]);
let sample = studyData.samples[sampleIndexes[sampleIndex]];
samples[sampleIndexes[sampleIndex]] = sample;
sampleIndex ++;
}
taskDict[p][t]= sampleList;
results[p][t]={};
}
}
console.log(samples)
console.log(taskDict)
jatos.studySessionData["results"] = results;
return [taskDict, samples];
}
function sessionSuccess(){
console.log("Succesfully sent session data");
console.log(jatos.studySessionData);
}
function sessionFailure(){
console.log("Failed to send session data");
}
jatos.onLoad(function () {
if (jatos.studySessionData["task_type"] ==null){
jatos.studySessionData["task_type"] = getRandomTaskID();
}
var lang = "default";
if (jatos.studySessionData.language){
lang = jatos.studySessionData.language
}
let loading_string = "...Loading study data"
if (lang =="fr"){
loading_string = "...Chargement des données de l'étude"
}
$("#next_button").html(loading_string);
//Load the correct description and display it
$.ajax({
url:"static/html/task_descriptions.html",
type:'GET',
success: function(data) {
console.log("Task type : " +jatos.studySessionData["task_type"])
console.log("Language: "+lang)
var description = $('<div>').append(data).find('#task_description').find(`#${lang}`);
let title = $('<div>').append(data).find('#title').find(`#${lang}`)
// console.log(description)
// console.log(title)
$('#description_div').html( description );
}
});
var json= $.getJSON("static/data/study_data.json", function(studyData){
tasks_samples = generateTaskSamples(studyData,jatos.studySessionData["task_type"] );
var samples = tasks_samples[1];
jatos.studySessionData["task_dict"] =tasks_samples[0];
jatos.studySessionData["task_index"] = 0;
jatos.studySessionData["phase_index"] = 0;
jatos.studySessionData["num_practices"] = 1;
jatos.studySessionData["volume"] = 0.5;
jatos.studySessionData["uuid"] = uuid4();
console.log("Participant UUID: "+jatos.studySessionData["uuid"])
let continueString ="Continue"
if (lang =="fr") {continueString= "Continuer"};
$("#next_button").html(`<button id="continue" type="button" class="btn btn-success">${continueString}</button>`)
$("#continue").click(function(){
sessionStorage.removeItem("sample_data");
jatos.submitResultData(JSON.stringify(jatos.studySessionData));
sessionStorage.setItem("sample_data", JSON.stringify(samples))
jatos.startNextComponent()
});
});
});
</script>
</body>
</html>