-
Notifications
You must be signed in to change notification settings - Fork 1
/
appScouter.js
374 lines (314 loc) · 12.5 KB
/
appScouter.js
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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
document.getElementById('finished-screen').style.display = 'none';
const urlParams = new URLSearchParams(window.location.search);
const Name = urlParams.get('name');
let imageExportUrl = '';
let audio = new Audio('Sel.wav');
let audio2 = new Audio('Rew.wav');
document.querySelector('#screen1 h2').textContent = 'Hello, ' + Name;
document.querySelector('#finished-text').textContent = 'Great Job, ' + Name;
var timerStarted = false;
document.getElementById('start-btn').addEventListener('click', function () {
audio.play();
if (timerStarted) {
return;
}
timerStarted = true;
window.scrollTo(0, 500);
var timeLeft = 15;
var timerId = setInterval(countdown, 1000);
function countdown() {
if (timeLeft == 0) {
clearTimeout(timerId);
document.getElementById('timer').innerHTML = '0:00 s';
window.scrollTo(500, 1450);
var timeLeft2 = 60+55; // 2 minutes and 15 seconds
audio.play();
var timerId2 = setInterval(countdown2, 1000);
function countdown2() {
if (timeLeft2 == 0) {
clearTimeout(timerId2);
document.getElementById('timer2').innerHTML = '0:00 s';
// Start countdown3
var timeLeft3 = 20; // 20 seconds
audio.play();
window.scrollTo(1450, 2450);
var timerId3 = setInterval(countdown3, 1000);
function countdown3() {
if (timeLeft3 == 0) {
clearTimeout(timerId3);
document.getElementById('timer3').innerHTML = '0:00 s';
} else {
var minutes = Math.floor(timeLeft3 / 60);
var seconds = timeLeft3 % 60;
document.getElementById('timer3').innerHTML = minutes + ':' + (seconds < 10 ? '0' : '') + seconds + ' s';
timeLeft3--;
}
}
} else {
var minutes = Math.floor(timeLeft2 / 60);
var seconds = timeLeft2 % 60;
document.getElementById('timer2').innerHTML = minutes + ':' + (seconds < 10 ? '0' : '') + seconds + ' s';
timeLeft2--;
}
}
} else {
document.getElementById('timer').innerHTML = '0:' + (timeLeft < 10 ? '0' : '') + timeLeft + ' s';
timeLeft--;
}
}
});
const canvas = document.getElementById('drawing-canvas');
const ctx = canvas.getContext('2d');
const exportBtn = document.getElementById('export-btn');
// Set canvas size
if (window.innerWidth <= 850) {
// If the screen width is 850px or less (mobile devices)
canvas.width = 400;
canvas.height = 220;
} else {
// If the screen width is more than 850px (desktop devices)
canvas.width = 600;
canvas.height = 350;
}
// Set stroke color to white
ctx.strokeStyle = 'black';
ctx.lineWidth = 5;
// Load and draw the background image
const backgroundImage = new Image();
backgroundImage.src = 'AutoPatch.png'; // Replace with the path to your image
backgroundImage.onload = function() {
ctx.drawImage(backgroundImage, 0, 0, canvas.width, canvas.height);
};
// Add event listeners for drawing
// Add event listeners for drawing
let isDrawing = false;
let lastX = 0;
let lastY = 0;
canvas.addEventListener('mousedown', startDrawing);
canvas.addEventListener('mousemove', draw);
canvas.addEventListener('mouseup', stopDrawing);
canvas.addEventListener('mouseout', stopDrawing);
// Add event listeners for touch devices
canvas.addEventListener('touchstart', (e) => {
e.preventDefault();
startDrawing(e.touches[0]);
});
canvas.addEventListener('touchmove', (e) => {
e.preventDefault();
draw(e.touches[0]);
});
canvas.addEventListener('touchend', () => {
isDrawing = false;
});
function startDrawing(e) {
isDrawing = true;
let rect = canvas.getBoundingClientRect();
lastX = e.clientX - rect.left;
lastY = e.clientY - rect.top;
}
function draw(e) {
if (!isDrawing) return;
ctx.beginPath();
let rect = canvas.getBoundingClientRect();
let newX = e.clientX - rect.left;
let newY = e.clientY - rect.top;
ctx.moveTo(lastX, lastY);
ctx.lineTo(newX, newY);
ctx.stroke();
[lastX, lastY] = [newX, newY];
}
function stopDrawing() {
isDrawing = false;
}
document.getElementById('undo-btn').addEventListener('click', function() {
const backgroundImage = new Image();
backgroundImage.src = 'AutoPatch.png'; // Replace with the path to your image
backgroundImage.onload = function() {
ctx.drawImage(backgroundImage, 0, 0, canvas.width, canvas.height);
};
});
// Export canvas as JPG
function exportCanvas() {
canvas.toBlob(function(blob) {
const formData = new FormData();
formData.append('image', blob, 'drawing.jpg');
formData.append('key', '3e8d3da8c19972850539b43b1645f089');
fetch('https://api.imgbb.com/1/upload', {
method: 'POST',
mode: 'no-cors',
body: formData
})
.then(response => response.json())
.then(data => {
if (data.success) {
alert('Image URL:', data.data.url);
} else {
alert('Error:', data.status);
}
})
.catch(error => console.error('Error:', error));
}, 'image/jpeg');
}
var avalue = 0;
document.getElementById('minus-btn').addEventListener('click', function() {
avalue--;
document.getElementById('value').textContent = avalue;
});
document.getElementById('plus-btn').addEventListener('click', function() {
avalue++;
document.getElementById('value').textContent = avalue;
});
var svalue = 0;
document.getElementById('sminus-btn').addEventListener('click', function() {
svalue--;
document.getElementById('svalue').textContent = svalue;
});
document.getElementById('splus-btn').addEventListener('click', function() {
svalue++;
document.getElementById('svalue').textContent = svalue;
});
var smvalue = 0;
document.getElementById('smminus-btn').addEventListener('click', function() {
smvalue--;
document.getElementById('unique-smvalue').textContent = smvalue;
});
document.getElementById('smplus-btn').addEventListener('click', function() {
smvalue++;
document.getElementById('unique-smvalue').textContent = smvalue;
});
//TeleOp Code
var atelevalue = 0;
document.getElementById('Ateleminus-btn').addEventListener('click', function() {
atelevalue--;
document.getElementById('Atelevalue').textContent = atelevalue;
});
document.getElementById('Ateleplus-btn').addEventListener('click', function() {
atelevalue++;
document.getElementById('Atelevalue').textContent = atelevalue;
});
var astelevalue = 0;
document.getElementById('Asteleminus-btn').addEventListener('click', function() {
astelevalue--;
document.getElementById('Astelevalue').textContent = astelevalue;
});
document.getElementById('Asteleplus-btn').addEventListener('click', function() {
astelevalue++;
document.getElementById('Astelevalue').textContent = astelevalue;
});
var telesvalue = 0;
document.getElementById('telesminus-btn').addEventListener('click', function() {
telesvalue--;
document.getElementById('telesvalue').textContent = telesvalue;
});
document.getElementById('telesplus-btn').addEventListener('click', function() {
telesvalue++;
document.getElementById('telesvalue').textContent = telesvalue;
});
var telesmvalue = 0;
document.getElementById('telesmminus-btn').addEventListener('click', function() {
telesmvalue--;
document.getElementById('telesmvalue').textContent = telesmvalue;
});
document.getElementById('telesmplus-btn').addEventListener('click', function() {
telesmvalue++;
document.getElementById('telesmvalue').textContent = telesmvalue;
});
document.querySelectorAll('input[type="checkbox"]').forEach(checkbox => {
checkbox.addEventListener('change', function() {
if (this.checked) {
console.log(this.id + ' is selected');
} else {
console.log(this.id + ' is deselected');
}
});
});
//The Submit Button
var option8 = document.getElementById('option8');
var option9 = document.getElementById('option9');
document.getElementById('finish-btn').addEventListener('click', function() {
audio2.play();
document.getElementById('finished-screen').style.display = 'flex';
const canvas = document.getElementById('drawing-canvas'); // Please set the ID of the canvas.
const imageExportUrl = canvas.toDataURL('image/jpeg');
const teamNumber = document.getElementById('teamNumber').value;
const matchNumber = document.getElementById('matchNumber').value;
const outFed = document.getElementById('outsideFed').value;
const AampShots = document.getElementById('value').textContent;
const AspeaShots = document.getElementById('svalue').textContent;
const AspeaShotsm = document.getElementById('unique-smvalue').textContent;
const comments = document.getElementById('postGameComments').value;
let Autoaccuracy;
if (AspeaShots === 0) {
Autoaccuracy = 0;
} else {
Autoaccuracy = AspeaShotsm / AspeaShots * 100;
}
// Get the values of the selected checkboxes First Question
const selectedCheckboxes = ['Feeder', 'Speaker', 'Amp', 'Defense'].map(optionId => {
const checkbox = document.getElementById(optionId);
return checkbox && checkbox.checked ? checkbox.id : null;
}).filter(id => id !== null);
const selectedCheckboxesText = selectedCheckboxes.join(', ');
console.log('Selected checkboxes:', selectedCheckboxesText);
// Get the values of the selected checkboxes Second Question
const selectedCheckboxesfeedloc = ['At Speaker', 'At Amp', 'Mid Field'].map(optionId => {
const checkbox = document.getElementById(optionId);
return checkbox && checkbox.checked ? checkbox.id : null;
}).filter(id => id !== null);
const selectedCheckboxesTextfeedloc = selectedCheckboxesfeedloc.join(', ');
console.log('Selected checkboxes:', selectedCheckboxesTextfeedloc);
const TnotesFeed = document.getElementById('Atelevalue').textContent;
const TampShots = document.getElementById('Astelevalue').textContent;
const TspeaShots = document.getElementById('telesvalue').textContent;
const TspeaShotsm = document.getElementById('telesmvalue').textContent;
let Teleaccuracy;
if (TspeaShots === 0) {
Teleaccuracy = 0;
} else {
Teleaccuracy = TspeaShotsm / TspeaShots * 100;
}
const selectedChainOption = document.querySelector('input[name="bchainOption"]:checked').value;
const selectedoptionparking = document.querySelector('input[name="parkingOption"]:checked').value;
const selectedTrap = document.querySelector('input[name="Trapoption"]:checked').value;
const selectedConncetion = document.querySelector('input[name="Connectionoption"]:checked').value;
const spreadsheetId = "1hLxcEQfwCAWkJCXtx-dX6rr3dxPdVrgIvb3E0rkq50A"; // Please set the Spreadsheet ID.
const avgTime = 135/Number(TspeaShots);
let climb = 0;
if (option8.checked || option9.checked) {
climb = 1;
} else {
climb = 0;
}
const body = {
arguments: { range: 'Sheet1', valueInputOption: 'USER_ENTERED' },
body: { values: [[matchNumber, teamNumber, imageExportUrl, AampShots, AspeaShots, AspeaShotsm, Autoaccuracy, selectedCheckboxesText, selectedCheckboxesTextfeedloc, TnotesFeed, TampShots, TspeaShots, TspeaShotsm, Teleaccuracy, selectedChainOption, selectedoptionparking, selectedTrap, selectedConncetion, outFed, comments, Name]] },
};
const url = `https://script.google.com/macros/s/AKfycbwJyak6u9oImeFbOLzgKsP5mOh7DvLFvobWI2uaTjs3uUiFALTqUcAy5Bsm1TrYEUTW/exec`;
fetch(url, {
method: 'POST',
mode: 'no-cors',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(body)
})
.then(response => response.text())
.then(text => console.log(text))
.catch(error => console.error('Error:', error));
const body2 = {
arguments: { range: 'Sheet1', valueInputOption: 'USER_ENTERED' },
body: { values: [[teamNumber, AspeaShotsm, AspeaShots, TspeaShotsm , TspeaShots, climb, Autoaccuracy, Teleaccuracy, avgTime]] },
};
const url2 = `https://script.google.com/macros/s/AKfycby28PBsdPCy4wXomEPfI65qoDWanZVE6pJRV39xHEmmovGRyrfQ5GBTeeu3Y3PjxjMJ_g/exec`;
fetch(url2, {
method: 'POST',
mode: 'no-cors',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(body2)
})
.then(response => response.text())
.then(text => console.log(text))
.catch(error => console.error('Error:', error));
});