forked from cs480x-22c/a3-Experiment
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
251 lines (210 loc) · 6.93 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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
<!DOCTYPE html>
<html lang="en">
<header>
<title>CS480x Experiment</title>
<script src="https://d3js.org/d3.v4.min.js"></script>
<script src="RandomPlots.js"></script>
<script src="backend.js"></script>
<style>
</style>
</header>
<body>
<h1> CS480x Experiment </h1>
<label id="countID">Progress: 1/25</label><br>
<label id="instructions">Instructions</label><br>
<div id="plot"></div>
<p id = 'error' style="color:red;display:none;">% Difference Must Be In Range [0.01, 100]</p>
<label for = 'numInput'>Estimated %:</label>
<input type='number' id='numInput' min='0.00' max='100.00' name='number' />
<button onclick="nextPlot()">Next</button>
<script>
//----------------------------------------------------------------------- Set-Up
let rpg = new RandomPlots()
const userID = Math.floor(Math.random()*1000000)
const maxPerChart = 5
function rand(min, max) {
return Math.floor(Math.random() * (max-min+1)+min)
}
var r1 = -1
var r2 = -1
var testType = ''
let numPie = 0
function createPie() {
testType = 'Pie'
document.getElementById("instructions").innerHTML = 'Of the two white areas: What % of the larger is the smaller?'
r1 = rand(20, 180)
r2 = rand(20, 150)
if(r1==r2)
r1-=rand(5, 15)
r3 = rand(10, 340 - r2 - r1)
r4 = rand(10, 350 - r3 - r2 - r1)
r5 = 360 - r4 - r3 - r2 - r1
let sequence = [
{'value': r5, 'color': 'hsl(0,0%,50%)'},
{'value': r4, 'color': 'hsl(0,0%,50%)'},
{'value': r1, 'color': 'hsl(0,0%,100%)'},
{'value': r2, 'color': 'hsl(0,0%,100%)'},
{'value': r3, 'color': 'hsl(0,0%,50%)'}
]
numPie++
rpg.createPieChart(sequence)
}
let numBar = 0
function createBar() {
testType = 'Bar'
document.getElementById("instructions").innerHTML = 'Of the two white bars: What % of the larger is the smaller?'
r1 = rand(420, 700)
r2 = 770 - r1
let sequence = [
[rand(10, 700)],
[rand(10, 700)],
[rand(10, 700)],
[r1],
[r2],
[rand(10, 700)]
]
let colors = [
['hsl(0,0%,50%)'],
['hsl(0,0%,50%)'],
['hsl(0,0%,50%)'],
['hsl(0,0%,100%)'],
['hsl(0,0%,100%)'],
['hsl(0,0%,50%)']
]
numBar++
rpg.createBarChart(sequence, colors)
r1 = Math.floor(r1/7)
r2 = Math.floor(r2/7)
}
let numH = 0
function createH() {
testType = 'H'
document.getElementById("instructions").innerHTML = 'What % of the right hue is the left hue?'
r1 = rand(0, 350)
r2 = rand(r1+10, 360)
var r3 = (r2+r1)/2
let sequence = [
['hsl('+r1+',80%,50%)'],
['hsl('+r3+',80%,50%)'],
['hsl('+r2+',80%,50%)']
]
sequence.color = 'hsl(0,0%,50%)'
numH++
rpg.createCircles(sequence)
}
let numS = 0
function createS() {
testType = 'S'
document.getElementById("instructions").innerHTML = 'What % of the right saturation is the left saturation?'
r1 = rand(0, 90)
r2 = rand(r1+10, 100)
var r3 = (r2+r1)/2
let sequence = [
['hsl(30,'+r1+'%,50%)'],
['hsl(30,'+r3+'%,50%)'],
['hsl(30,'+r2+'%,50%)']
]
numS++
rpg.createCircles(sequence)
}
let numL = 0
function createL() {
testType = 'L'
document.getElementById("instructions").innerHTML = 'What % of the right luminance is the left luminance?'
r1 = rand(0, 90)
r2 = rand(r1+10, 100)
var r3 = (r2+r1)/2
let sequence = [
['hsl(150,80%,'+r1+'%)'],
['hsl(150,80%,'+r3+'%)'],
['hsl(150,80%,'+r2+'%)']
]
numL++
rpg.createCircles(sequence)
}
function nextTest() { //messy, but can't think of how to do pseudo rand that hits all charts 5 times
var cont = true;
while(cont) {
switch(rand(0, 4)) {
case 0:
createBar()
cont = false
break
case 1:
createPie()
cont = false
break
case 2:
createH()
cont = false
break
case 3:
createS()
cont = false
break
case 4:
createL()
cont = false
break
}
}
}
//---------------------------------------------------------------------- Sending Data
function sendData(payload) {
var formBody = [];
for (var property in details) {
var encodedKey = encodeURIComponent(property);
var encodedValue = encodeURIComponent(details[property]);
formBody.push(encodedKey + "=" + encodedValue);
}
formBody = formBody.join("&");
fetch('https://docs.google.com/forms/u/4/d/e/1FAIpQLSe9BLtXqwfV94_f-feQM6vsAeIYTcbPXhwGF2-WQy-RVgPFcQ/formResponse', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
},
body: formBody
})
}
var details = {
'entry.1362470865': 'userID',
'entry.1174877292': 'testType',
'entry.357989325': 'true percentage',
'entry.138102301': 'response percentage'
}
//---------------------------------------------------------------------- Button Press/Next Graph Gen
let s = 0
let idx = 1
function nextPlot() {
s = document.getElementById('numInput').value
if(s >= 0.01 && s <= 100.00) { //if s is valid, passes to sheets and gens next graph
//Write to sheets
var trueDiff = Math.floor(100*(Math.min(r1, r2)/Math.max(r1, r2)))
details['entry.1362470865'] = userID,
details['entry.1174877292'] = testType,
details['entry.357989325'] = trueDiff,
details['entry.138102301'] = s
sendData(details);
//Update UI
document.getElementById('error').style.display = 'none'
document.getElementById('numInput').value = "";
nextTest();
//Josh's Super-Lazy Indexing Extrodinaire
idx += 1
//Uodate label
document.getElementById('countID').innerHTML = 'Progress: ' + idx + "/25";
//End condition for survey
if(idx==maxPerChart*5+1) { //if index maxes out, clears page and thanks user
document.write('THANK YOU!')
}
} else {
document.getElementById('error').style.display = 'block'
}
}
//-------------------------------------------------------------------------- Nada mas.
</script>
<script>
nextTest()
</script>
</body>
</html>