-
Notifications
You must be signed in to change notification settings - Fork 0
/
experiment.js
54 lines (44 loc) · 1.27 KB
/
experiment.js
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
const dataPipeExpId = "4GbxQiLvfkDv";
const jsPsych = initJsPsych();
let condition;
const subjectId = jsPsych.randomization.randomID(10);
jsPsych.data.addProperties({ subject: subjectId });
getConditionThenRun();
async function getConditionThenRun() {
condition = await jsPsychPipe.getCondition(dataPipeExpId);
buildAndRunExperiment();
}
function buildAndRunExperiment() {
const showConditionTrial = {
type: jsPsychHtmlButtonResponse,
stimulus: `You are in condition ${condition}`,
choices: ["Continue"],
};
const drawSomethingTrial = {
type: jsPsychSketchpad,
prompt: "<p>Draw a shape!</p>",
prompt_location: "abovecanvas",
canvas_width: 300,
canvas_height: 300,
canvas_border_width: 2,
save_strokes: false,
save_final_image: true,
on_finish: function (data) {
const base64string = data.png.replace('data:', '').replace(/^.+,/, '');
jsPsychPipe.saveBase64Data(dataPipeExpId, `${subjectId}_image.png`, base64string);
data.png = null;
}
};
const saveData = {
type: jsPsychPipe,
action: "save",
experiment_id: "4GbxQiLvfkDv",
filename: `${subjectId}_data.json`,
data: ()=>jsPsych.data.get().json()
};
jsPsych.run([
showConditionTrial,
drawSomethingTrial,
saveData
]);
}