forked from openexp/openexp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreactionTimeTask.html
167 lines (149 loc) · 6.07 KB
/
reactionTimeTask.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
161
162
163
164
165
166
167
<!doctype html>
<html>
<head>
<title>OpenEXP</title>
<script type="text/javascript" src="js/jquery.min.js" onload="window.$ = window.jQuery = module.exports;"></script>
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script src="externals/jspsych/jspsych.js"></script>
<script src="externals/jspsych/plugins/jspsych-text.js"></script>
<script src="externals/jspsych/plugins/jspsych-single-stim.js"></script>
<!-- Bootstrap core CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="jspsych/css/jspsych.css" rel="stylesheet" type="text/css"></link>
</head>
<body style="background-color:#d3d3d3">
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="index.html">
<img id="logo" alt="Brand" src="img/headerlogofront.png" height="25px">
</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="active"><a href="index.html">OpenEXP<span class="sr-only">(current)</span></a></li>
<li><a href="#">EEG</a></li>
<li><a href="sandbox.html">Sandbox</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Experiments <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="reactionTimeTask.html">Reaction Time Task</a></li>
<li><a href="#">Memory Study - Pictures</a></li>
<li><a href="#">Language Study - Words</a></li>
<li role="separator" class="divider"></li>
<li><a href="#">Separated link</a></li>
<li role="separator" class="divider"></li>
<li><a href="#">One more separated link</a></li>
</ul>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><a href="#">Need Help?</a></li>
<form class="navbar-form navbar-right" role="search">
<div class="form-group">
<input type="text" class="form-control" name="username" placeholder="Username">
</div>
<div class="form-group">
<input type="text" class="form-control" name="password" placeholder="Password">
</div>
<button type="submit" class="btn btn-default">Sign In</button>
</form>
</div>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
<div class="row spacer" style="margin-top:100px"></div>
<div id="jspsych-target"></div>
</body>
<script>
/* define welcome message block */
var welcome_block = {
type: "text",
text: "Welcome to the experiment. Press any key to begin."
};
/* define instructions block */
var instructions_block = {
type: "text",
text: "<p>In this experiment, a circle will appear in the center " +
"of the screen.</p><p>If the circle is <strong>blue</strong>, " +
"press the letter F on the keyboard as fast as you can.</p>" +
"<p>If the circle is <strong>orange</strong>, do not press " +
"any key.</p>" +
"<div class='left center-content'><img src='img/blue.png'></img>" +
"<p class='small'><strong>Press the F key</strong></p></div>" +
"<div class='right center-content'><img src='img/orange.png'></img>" +
"<p class='small'><strong>Do not press a key</strong></p></div>" +
"<p>Press any key to begin.</p>",
timing_post_trial: 2000
};
/* define test block */
var test_stimuli = [
{
image: "img/blue.png",
data: { response: 'go' }
},
{
image: "img/orange.png",
data: { response: 'no-go' }
}
];
var all_trials = jsPsych.randomization.repeat(test_stimuli, 10, true);
var post_trial_gap = function() {
return Math.floor( Math.random() * 1500 ) + 750;
}
//var post_trial_gap = 2500
var encoding_block = {
type: "single-stim",
stimuli: all_trials.image,
choices: ['F'],
data: all_trials.data,
timing_response: 1000,
timing_post_trial: post_trial_gap
};
/* define debrief block */
function getAverageResponseTime() {
var trials = jsPsych.data.getTrialsOfType('single-stim');
var sum_rt = 0;
var valid_trial_count = 0;
for (var i = 0; i < trials.length; i++) {
if (trials[i].response == 'go' && trials[i].rt > -1) {
sum_rt += trials[i].rt;
valid_trial_count++;
}
}
return Math.floor(sum_rt / valid_trial_count);
}
var debrief_block = {
type: "text",
text: function() {
return "<p>Your average response time was <strong>" +
getAverageResponseTime() + "ms</strong>. Press " +
"any key to complete the experiment. Thank you!</p>";
}
};
/* create experiment definition array */
var experiment = [];
experiment.push(welcome_block);
experiment.push(instructions_block);
experiment.push(encoding_block);
experiment.push(debrief_block);
/* start the experiment */
jsPsych.init({
experiment_structure: experiment,
display_element: $('#jspsych-target'),
on_finish: function() {
jsPsych.data.displayData();
}
});
</script>
</html>