forked from shawntz/psych45-demos
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheb.html
More file actions
175 lines (155 loc) · 7.77 KB
/
eb.html
File metadata and controls
175 lines (155 loc) · 7.77 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
174
175
<!DOCTYPE html>
<html>
<head>
<title>Psych 45 | Event Boundaries Demo</title>
<script src="https://unpkg.com/jspsych@7.3.2"></script>
<script src="https://unpkg.com/@jspsych/plugin-html-keyboard-response@1.1.2"></script>
<script src="https://unpkg.com/@jspsych/plugin-fullscreen@1.1.0"></script>
<script src="https://unpkg.com/@jspsych/plugin-browser-check@1.0.0"></script>
<script src="https://unpkg.com/@jspsych/plugin-video-keyboard-response@1.0.0"></script>
<link href="https://unpkg.com/jspsych@7.3.2/css/jspsych.css" rel="stylesheet" type="text/css" />
<style>
.upperline {
text-transform: uppercase;
text-decoration: underline;
}
</style>
</head>
<body></body>
<script>
// init jsPsych
var jsPsych = initJsPsych({
override_safe_mode: true,
on_finish: function() {
// get current time
var timestamp = Date.now();
// gather and save all data locally
var all_data = jsPsych.data.get();
all_data.localSave('csv', file_pattern_data + "_" + timestamp + ".csv");
}
});
// make random subject id
var subject_id = jsPsych.randomization.randomID(15);
var study_id = 'nback'
// append study metadata to output data
jsPsych.data.addProperties({
subject_id: subject_id,
study_id: study_id
});
// make filename pattern
var file_pattern_data = subject_id + "_" + study_id + "_data_";
var response_times = [];
var startTime = 0;
// Function to handle space bar press
function handleSpaceBarPress(event) {
if (event.key === " " || event.keyCode === 32) {
response_times.push(jsPsych.getTotalTime() - startTime);
}
}
var record_button_presses = function() {
// Add event listener for keydown event
document.addEventListener("keydown", handleSpaceBarPress);
}
var video_trial = {
type: jsPsychVideoKeyboardResponse,
stimulus: [
'src/media/gardening_25fps.mp4'
],
choices: "NO_KEYS",
response_ends_trial: false,
trial_ends_after_video: true
};
var video_trial_with_rsp = {
type: jsPsychVideoKeyboardResponse,
stimulus: [
'src/media/gardening_25fps.mp4'
],
choices: [" "],
response_ends_trial: false,
trial_ends_after_video: true,
on_load: function() {
startTime = jsPsych.getTotalTime();
record_button_presses();
},
on_finish: function(data){
data.response_times = response_times;
}
};
// create timeline
var timeline = [];
// force browser into full screen mode
var enter_fullscreen = {
type: jsPsychFullscreen,
fullscreen_mode: true
};
timeline.push(enter_fullscreen);
// welcome message
var welcome = {
type: jsPsychHtmlKeyboardResponse,
choices: ' ',
post_trial_gap: 500,
stimulus: '<strong>Welcome to the Event Boundaries MiA for Psych 45!</strong> <br /><br />This demo experiment will take about 10 minutes to complete. Please complete all in one sitting. <br /><br />For this study, <strong>please use</strong> a laptop or desktop computer (not a mobile phone or tablet). Also, please use either <u>Chrome or Firefox</u>. <br /><br />Once you begin, <strong>DO NOT</strong> refresh the browser, as the study will reset and you will lose your progress. <br /><br />Press the <strong class="upperline">spacebar</strong> on your keyboard to move onto the instructions. <br /><br /><u>(if you encounter any technical difficulties, please contact TA Shawn Schwartz: <a href="mailto:stschwartz@stanford.edu?Subject=[Psych45]:%20MiA%20Task%20Demo%20Issue" target="_blank">stschwartz [at] stanford [dot] edu</a>)</u>'
};
timeline.push(welcome);
// check browser and ensure user is not on mobile device
var check_browser_and_device = {
type: jsPsychBrowserCheck,
inclusion_function: (data) => {
return (data.browser == 'chrome' || data.browser == 'firefox') && data.mobile === false
},
exclusion_message: () => {
if (data.mobile) {
return '<p>You must use a desktop/laptop computer to participate in this experiment.</p>';
} else if (data.browser !== 'chrome' || data.browser !== 'firefox') {
return '<p>You must use either Chrome or Firefox as your browser to complete this experiment.</p>';
}
}
};
timeline.push(check_browser_and_device);
// check browser window size
var check_window_size = {
type: jsPsychBrowserCheck,
minimum_width: 1000,
minimum_height: 600
};
timeline.push(check_window_size);
// instructions
var instructions_1 = {
type: jsPsychHtmlKeyboardResponse,
choices: 'b',
post_trial_gap: 500,
stimulus: 'In this study, you will watch a 5 minute video twice. During the first viewing, you will simply be asked to watch the video and <strong>will not be asked</strong> to make any responses.<br /><br />During the second viewing, <strong>your goal will be to identify whenever one meaningful unit of activity ends and another begins</strong>; you will press the <strong class="upperline">SPACEBAR</strong> to mark these boundaries.<br /><br />Now, press the <strong class="upperline">b</strong> on your keyboard to start the video. Again, during this first part of the study, please <strong>do NOT</strong> make any responses.'
}
timeline.push(instructions_1);
var instructions_2 = {
type: jsPsychHtmlKeyboardResponse,
choices: 'b',
post_trial_gap: 500,
stimulus: '<br />Now that you have familiarized yourself with the video, we will ask you to watch it once more. Again, <strong>your goal is to identify whenever one meaningful unit of activity ends and another begins</strong>; importantly, press the <strong class="upperline">spacebar</strong> to mark these boundaries <strong>while watching the video</strong>.<br /><br />Now, press the <strong class="upperline">b</strong> key on your keyboard to begin.'
}
timeline.push(video_trial);
timeline.push(instructions_2);
timeline.push(video_trial_with_rsp);
var download_data = {
type: jsPsychHtmlKeyboardResponse,
choices: 'd',
post_trial_gap: 1000,
stimulus: '<br /><br /><center>Thank you for completing the Event Boundary demo study. <br /><br /><strong><u>IMPORTANTLY:</u></strong> Please press the <strong class="upperline">d</strong> key on your keyboard to <strong>download your data file</strong>. <br /><br />Please submit this data file that was just downloaded to your computer via the instructions on Canvas.</center>',
on_finish: function() {
setTimeout(function() {
document.querySelector('body').innerHTML = "<br /><br /><center><strong>Data successfully downloaded!</strong><br /><br />Thank you!</center>";
}, 750);
}
}
timeline.push(download_data);
// exit full screen mode
var exit_fullscreen = {
type: jsPsychFullscreen,
fullscreen_mode: false,
delay_after: 0
};
timeline.push(exit_fullscreen);
// execute experiment
jsPsych.run(timeline);
</script>
</html>