forked from NickRSearcy/cause-affect-static
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexp.coffee
214 lines (187 loc) · 7.74 KB
/
exp.coffee
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
show_slide = (slide_obj, proceed=true, clear=true) ->
_.defaults(slide_obj,{
template: ->
h1 "hello default template"
p "replace me"
function: ->
console.log("we have executed a default slide function for slide #{slide_obj.name | 'unnamed slide'}")
})
if clear
$("#content").empty()
$("#content").append(coffeecup.render(slide_obj.template, personal: @exp.personal, valence: @exp.valence, chemical: @exp.chemical))
slide_obj.function()
@proceed = ->
current_slide = @exp.slides[@exp.slide_index]
if @exp.slide_index > -1 and current_slide["close"]
current_slide.close()
num_slides = @exp.slides.length
@exp.slide_index = _.min([@exp.slide_index+1,num_slides-1])
show_slide(@exp.slides[@exp.slide_index])
intro_template = ->
# p "this is a test"
h1 -> "Informed consent"
p -> "Please read over the following informed consent agreement."
div ".panel.panel-default", ->
div ".panel-heading", ->
h3 ".panel-title", "Informed Consent: Studies of Concept Learning On-line"
div ".panel-body", style:"height:200px;overflow:auto", ->
a = $.get({
url: "consent.md"
async: false
})
markdownit().render(a.responseText)
h1 -> "Introduction"
p -> "In a moment you will be asked to read a brief scenario. You will then be asked to make a few judgments based on this scenario."
p -> "Please pay close attention and answer to the best of your abilities."
intro =
name: "introduction"
template: intro_template
instructions =
name: "instructions"
training_template = ->
div ".panel.panel-default", ->
div ".panel-heading", ->
h3 ".panel-title", "Description"
div ".panel-body", ->
p "Imagine you learn that #{window.exp.personal} a rare gene which, when activated, results in an increase in #{window.exp.valence}. You learn about research investigating the effect of an experimental drug on the activation of this gene."
p "Of course, the gene may only be activated in persons who possess the gene. Of those who have the gene, the gene may sometimes be activated without the drug. Also, some drugs may have a large effect on gene activation, some may have a small effect, and others, no effect. Thus, a group of people who did not recieve the drug were also checked to see if they had activated the same gene as those who did recieve the drug."
for c,i in window.exp.chemical
div ".panel.panel-default", ->
div ".panel-heading", ->
h3 ".panel-title", "Chemical ##{i+1}"
div ".panel-body", ->
table ".table.table-bordered", ->
tr ->
td ""
td -> strong -> "Gene activated"
td -> strong -> "Gene not activated"
tr ->
td -> strong -> "Recieved drug"
td -> "#{c[0]}"
td -> "#{100-c[0]}"
tr ->
td -> strong -> "Did not recieve drug"
td -> "#{c[1]}"
td -> "#{100-c[1]}"
p -> "In the experimental group, the gene was found to be activated in #{c[0]} out of 100 subjects. In the control group, the gene was found to be activated in #{c[1]} out of 100 subjects."
p -> "Using the slider below, evaluate these results. The 0 indicates that the drug <strong>never causes</strong> the gene to be activated and the 10 indicates that it <strong>always causes</strong> the gene to be activated."
div ".slider-label", align:"center", ->
span "Evaluation:"
input ".slider", type:"text", id:"input-#{i}", style:"border:0; font-weight: bold;", c:"#{c}"
div align:"center", style:"text-align: center; width:100%", ->
div ".container-fluid", ->
div ".row", ->
div ".col-sm-1", -> "<b>never</b>"
div ".col-sm-8", -> div "#slider-#{i}", ""
div ".col-sm-1", -> "<b>always</b>"
training_function = ->
for c,i in window.exp.chemical
# console.log("we can at least say slider-#{i}")
$("#slider-#{i}").slider({
value: 5,
min: 0,
max: 10,
step: 1,
slide: (event, ui) ->
index = event.target.id.split("-")[1]
$("#input-#{index}").val( ui.value ) })
training_close = ->
input = []
for i in _.range(10)
input.push({
c: $("#input-#{i}").attr("c")
value: $("#input-#{i}").val()
})
window.exp.training_input = input
training =
name: "training"
template: training_template
function: training_function
close: training_close
survey_template = ->
div ".panel.panel-default", ->
div ".panel-heading", ->
h3 ".panel-title", -> "Validation"
small "required"
div ".panel-body", ->
p -> "Select the number that corresponds to 'the experimental drug <em>never causes</em> the gene to be activated'."
p ->
select ".form-control", id:"q0", ->
for i in _.range(11)
if i==5
option selected="selected", -> "#{i}"
else
option -> "#{i}"
p -> "Select the number that corresponds to 'the experimental drug <em>never causes</em> the gene to be activated'."
p ->
select ".form-control", id:"q1", ->
for i in _.range(11)
if i==5
option selected="selected", -> "#{i}"
else
option -> "#{i}"
div ".panel.panel-default", ->
div ".panel-heading", ->
h3 ".panel-title", -> "Improve our experiment"
div ".panel-body", ->
p -> "How clear did you find the instructions for the experiment?"
p ->
select ".form-control", id:"q2", ->
for i in _.range(11)
if i==5
option selected="selected", -> "#{i}"
else
option -> "#{i}"
p -> "Let us know if you have any other questions or comments."
p ->
textarea ".form-control", id:"q3", rows="3", ->
survey_close = ->
input = []
for i in _.range(4)
input.push({
q: "q#{i}"
value: $("#q#{i}").val()
})
window.exp.survey_input = input
window.turk.submit(window.exp)
survey =
name: "survey"
template: survey_template
close: survey_close
preview_template = ->
div ".panel.panel-default", ->
div ".panel-heading", ->
h3 ".panel-title", -> "Preview"
div ".panel-body", ->
p "Hello, this is a quick experiment that measures how people make evaluations in different contexts. The experiment is expected to last about 4 minutes and the reward has been calculated to provide the equivalent of $10/hour."
preview =
name: "preview"
template: preview_template
# attach exp to window, it'll be what we use to keep track of experiment data.
@exp = {}
@exp.slide_index = -1 # start at -1 so that the first slide shown is at 0
@exp.slides = [
intro,
training,
survey,
]
_.extend(@exp,turk)
# in order to generate the desired query string do the following in a browser console where the Qurl package is loaded
# u = Qurl.create(); u.query("personal", '["you have","there is","someone has"]'); u.query("valence", '["sadness", "happiness", "doubt"]')
querystring = Qurl.create().query()
_.defaults(querystring,{
personal: '["you have","there is","someone has"]',
valence: '["unhappiness", "skill in stenography", "happiness", "pagally", "sadness", "positivity", "contentment", "pessimism", "gloominess", "centeredness", "doubt"]',
chemical: '[[10, 10], [40, 10], [40, 40], [60, 10], [60, 40], [60, 60], [90, 10], [90, 40], [90, 60], [90, 90]]'
})
for key, value of querystring
new_value = JSON.parse(value)
querystring[key] = new_value
@exp.valence_conditions = querystring.valence
@exp.valence = _.sample(@exp.valence_conditions)
@exp.personal_conditions = querystring.personal
@exp.personal = _.sample(@exp.personal_conditions)
@exp.chemical = _.shuffle(querystring.chemical)
if @exp.previewMode
@exp.slides = [preview]
@proceed()