-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
executable file
·49 lines (44 loc) · 1.35 KB
/
utils.js
File metadata and controls
executable file
·49 lines (44 loc) · 1.35 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
var show_data = {
type: jsPsychHtmlButtonResponse,
stimulus: function() {
// var trial_data = jsPsych.data.getLastTrialData().values();
var data_json = JSON.stringify(jsPsych.data.allData, null, 2);
return `<p style="margin-bottom:0px;"><strong>All Data:</strong></p>
<pre style="margin-top:0px;text-align:left;">${data_json}</pre>`;
},
choices: ['Repeat demo']
};
function saveData(name, data) {
var xhr = new XMLHttpRequest();
xhr.open('POST', 'record_data.php');
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.send(JSON.stringify({
filename: name,
data: data
}));
}
function createUID() {
UID = "T" + Date.now() + "_K" + Math.floor((Math.random() * 100000000) + 1);
return UID
}
function getRandomInt(max) {
return Math.floor(Math.random() * max);
}
function flip() {
return getRandomInt(2)
}
function randperm(maxValue) {
// first generate number sequence
var permArray = new Array(maxValue);
for (var i = 0; i < maxValue; i++) {
permArray[i] = i;
}
// draw out of the number sequence
for (var i = (maxValue - 1); i >= 0; --i) {
var randPos = Math.floor(i * Math.random());
var tmpStore = permArray[i];
permArray[i] = permArray[randPos];
permArray[randPos] = tmpStore;
}
return permArray;
}