-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
229 lines (211 loc) · 8.13 KB
/
index.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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
<!DOCTYPE html>
<!--
This file for github pages
see https://labneurocogdevel.github.io/cardtask
-->
<html>
<head>
<meta charset="UTF-8">
<title>Card Task experiments</title>
<!-- all of this also in ./templates/exp.html -->
<link rel="stylesheet" href="static/css/bootstrap.min.css" type="text/css" />
<link rel="stylesheet" href="static/js/jspsych/css/jspsych.css" type="text/css" />
<link rel="stylesheet" href="static/css/style.css" type="text/css" />
<link id="feedback" rel="stylesheet" href="static/css/feedback.css" type="text/css" />
<style>
.select {background: lightyellow; font-size: larger;}
</style>
<script src="static/lib/jquery-3.4.1.min.js" type="text/javascript"> </script>
<script src="static/lib/underscore-min.js" type="text/javascript"> </script>
<script src="static/lib/backbone-min.js" type="text/javascript"> </script>
<script src="static/lib/d3.v3.min.js" type="text/javascript"> </script>
<script src="static/js/jspsych/jspsych.js" type="text/javascript"></script>
<script src="static/js/jspsych/plugins/jspsych-instructions.js" type="text/javascript"></script>
<script src="static/js/jspsych/plugins/jspsych-html-keyboard-response.js" type="text/javascript"></script>
<script src="static/js/jspsych/plugins/jspsych-survey-text.js" type="text/javascript"></script>
<script src="static/js/jspsych/plugins/jspsych-survey-multi-choice.js" type="text/javascript"></script>
<script src="static/js/utils.js" type="text/javascript"> </script>
<script src="static/js/task.js" type="text/javascript"> </script>
<script type="text/javascript">
// redfine cards for testing
/*
CARDS relevant to testing:
'p11_1D': new Card('❖', 'blue', LOWCOST , CARDWIN, 1),
'p11_1R': new Card('✢', 'red' , HIGHCOST, CARDWIN, 1),
'test_0R': new Card('0', 'red' , HIGHCOST, CARDWIN, 0),
'test_0B': new Card('0', 'blue', LOWCOST , CARDWIN, 0),
*/
fbk={}
fbk['current'] = mkfbk()
// original
function originalfbk() {
return({
type: 'html-keyboard-response',
stimulus: function(trial){
// setup win vs nowin feedback color and message
var prev=jsPsych.data.get().last(1).values()[0]
var msg=(prev.win > 0)?("+"+prev.win):"0";
var color=(prev.win > 0)?"win":"nowin";
var card = CARDS[prev.picked]
return(
"<p class='feedback sym'>" + card.sym +"</p>" +
"<p class='feedback cost'> Paid: -" + prev.cost +"</p>" +
"<p class='feedback " + color + "'>Won: " + msg + "</p>" +
"<p class='feedback net "+color+"'>Net: " +
(prev.win - prev.cost) + "</p>"+
"<p class='feedback'>Total: " + totalPoints() + "</p>"+
"<p class='feedback'><br><b>Push the space bar to see the next pair</b></p>"
)},
// 20200410 - no autoadvance
choices: [SPACE_KEY],
//choices: jsPsych.NO_KEYS,
//trial_duration: FEEDBACKDUR,
})}
fbk['original'] = originalfbk()
// show coins. vanish those that were paid
fbk['coin'] = originalfbk()
fbk['coin'].stimulus= function(trial){
// setup win vs nowin feedback color and message
let prev=jsPsych.data.get().last(1).values()[0];
let msg=(prev.win > 0)?("+"+prev.win):"0";
let color=(prev.win > 0)?"win":"nowin";
let card = CARDS[prev.picked];
return(
"<p class='feedback sym'>" + card.sym +"</p>" +
pictureRep(prev.win, prev.cost) +
"<p class='feedback cost'> Paid: -" + prev.cost +"</p>" +
"<p class='feedback " + color + "'>Won: " + msg + "</p>" +
"<p class='feedback net "+color+"'>Net: " +
(prev.win - prev.cost) + "</p>"+
"<p class='feedback'>Total: " + totalPoints() + "</p>" +
"<p class='feedback'><br><b>Push the space bar to see the next pair</b></p>"
)}
fbk['coin'].on_load = function(trial) {
let prev=jsPsych.data.get().last(1).values()[0]
console.log(prev.win,prev.cost)
if(prev.win-prev.cost>0) {
setTimeout(function(){
$('img.coin').slice(0,prev.cost).attr('src', 'static/images/poof_gold_sm.gif')
},300)
}
}
// change onload to count up points
fbk['cnt'] = originalfbk()
fbk['cnt'].on_load = function(trial) {
let prev=jsPsych.data.get().last(1).values()[0]
let net = (prev.win - prev.cost)
if(net>0) {countWin(net)}
}
// everything together
fbk['everything'] = originalfbk()
fbk['everything'].stimulus= function(trial){
// setup win vs nowin feedback color and message
let prev=jsPsych.data.get().last(1).values()[0];
let msg=(prev.win > 0)?("+"+prev.win):"0";
let color=(prev.win > 0)?"win":"nowin";
let card = CARDS[prev.picked];
return(
"<p class='feedback sym'>" + card.sym +"</p><div class='wallet'>" +
pictureRep(prev.win, prev.cost) +
"</div><p class='feedback cost'> Paid: -" + prev.cost +"</p>" +
"<p class='feedback " + color + "'>Won: " + msg + "</p>" +
"<p class='feedback net "+color+"'>Net: " +
(prev.win - prev.cost) + "</p>"+
"<p class='feedback'>Total: " + totalPoints() + "</p>" +
"<p class='feedback'><br><b>Push the space bar to see the next pair</b></p>"
)}
fbk['everything'].on_load = function(trial) {
let prev=jsPsych.data.get().last(1).values()[0]
let net = (prev.win - prev.cost)
if(net>0) {
countWin(net)
setTimeout(function(){
$('img.coin').slice(0,prev.cost).attr('src', 'static/images/poof_gold_sm.gif')
},300)
}
}
// dummy trial that lasts 0 seconds
function dummy(c){
return({
type: 'html-keyboard-response',
stimulus: '',
trial_duration: 0,
on_finish: function(data) {
data.cost = CARDS[c].cost
data.p = CARDS[c].p
data.win = CARDS[c].score()
data.rt = $('#rt').val();
data.rtpen = calc_rtpen(data.rt, data.win, data.cost);
data.score = data.win - data.cost - data.rtpen;
data.picked = c;
data.color = CARDS[c].color;
data.sym = CARDS[c].sym;
data.side_idx = 1;
}})}
function fulltrial() {
t = mktrial_fixloc("p28_2S", "p11_1H")
t2 = mktrial_fixloc("p11_1I", "p28_2S")
jsPsych.init({timeline: [t, feedback1, feedback2, t2,feedback1, feedback2], display_element: jsp,
on_finish: function() {fulltrial()}
});
}
function fulltrial_old() {
t = mktrial("p11_1I", "p11_1H")
jsPsych.init({timeline: [t, feedback], display_element: jsp});
}
function instruction(){
jsPsych.init({timeline: [instructions], display_element: jsp});
}
function survey(){
jsPsych.init({timeline: [final_thoughts], display_element: jsp});
}
function mkfeedback(c) {
dummycard=dummy(c)
// push fake data and run feedback slide with given card
jsPsych.init({timeline: [dummycard, feedback1, feedback2], display_element: jsp});
}
// play with feedback
function fbk_set(n){
// indicator
$('.fbk').attr('class','fbk')
$('#'+n).attr('class','fbk select')
// change style sheet
$('link[id="feedback"]').attr('href', 'static/css/feedback.css');
if(n == "cnt" || n=="everything") {
$('link[id="feedback"]').attr('href', 'static/css/feedback-cnt.css');
}
feedback = fbk[n]
console.log('updateing feedback', n, feedback)
}
function init(){
$("#feedbacktypes").append(Object.keys(fbk).map(id => `<a class=fbk id=${id} onclick="fbk_set('${id}')">${id}</a> `).join(" "))
fbk_set('current');
//mkfeedback('p11_1H');
fulltrial();
}
</script>
</head>
<body onload="init()">
<div> links:
<a href="https://github.com/LabNeuroCogDevel/cardtask"> repo</a> |
<a href="https://lncdturk.herokuapp.com/"> heroku</a>
</div>
<div> trials:
<a href="#" onclick="fulltrial()"> 2 trials & fbk </a> |
<a href="#" onclick="instruction()">instr</a> |
<a href="#" onclick="survey()">survey</a> |
<a href="#" onclick="fulltrial_old()"> ❖ vs ✢ (old)</a>
<div id="feedbacktypes">fbk settings: </div>
<div> feedback:
<a href="#" onclick="mkfeedback('p11_1I')">I</a> ,
<a href="#" onclick="mkfeedback('p11_1S')">S</a> ,
<a href="#" onclick="mkfeedback('p11_1H')">H</a> ,
<a href="#" onclick="mkfeedback('test_0B')">💣</a>
rt: <input id="rt" type="input" value="1000" size="5" />
</div>
<br><br>
<div>
<div id="jsp"> </div>
</div>
</body>
</html>