-
Notifications
You must be signed in to change notification settings - Fork 0
/
observationForm.js
437 lines (426 loc) · 13.6 KB
/
observationForm.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
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
var utils = require('./utils');
var TBA = require('./TBA');
/********************
* Types of inputs *
- null (no input)
- dropdown [requires data]
- short_text
- long_text
- multiple_choice [requires data]
- checkbox [requires data]
- number
- slider [requires data]
********************/
var rankingStructure = {
place: {
name: "Place",
data: null
},
team: {
name: "<span class='no-mobile'>Team </span>#",
data: "team"
},
points: {
name: "Points",
data: "points"
},
image: {
name: "Image",
data: "image"
}
}
var tableStructure = {
team: {
name: "<span class='no-mobile'>Team </span>#",
data: "team"
},
more: {
name: "More Info",
data: {
user: {
name: "User",
data: "user"
},
match: {
name: "Match Number",
data: "match"
},
auto_cross_line: {
name: "[Auto] Crossed auto line",
data: "auto_cross_line"
},
auto_scale_cubes: {
name: "[Auto] Bot put cubes on scale",
data: "auto_scale_cubes"
},
auto_switch_cubes: {
name: "[Auto] Bot put cubes on switch",
data: "auto_switch_cubes"
},
auto_comments: {
name: "[Auto] Extra comments",
data: "auto_comments"
},
teleop_scale_cubes: {
name: "[Teleop] Number of cubes on scale",
data: "teleop_scale_cubes"
},
teleop_switch_cubes: {
name: "[Teleop] Number of cubes on switch",
data: "teleop_switch_cubes"
},
teleop_exchange_cubes: {
name: "[Teleop] Number of cubes put in the exchange",
data: "teleop_exchange_cubes"
},
teleop_cubes_dropped: {
name: "[Teleop] Number of cubes dropped",
data: "teleop_cubes_dropped"
},
teleop_robot_died: {
name: "[Teleop] Robot died",
data: "teleop_robot_died"
},
teleop_time_robot_died: {
name: "[Teleop] How long robot was dead",
data: "teleop_time_robot_died"
},
driver_comments: {
name: "[Driver] Comments",
data: "driver_comments"
},
time_on_defense: {
name: "[Defense] Percent of time on defense",
data: "time_on_defense"
},
speed: {
name: "[Bot] Speed compared to our robot",
data: "speed"
},
endgame_successful_climb: {
name: "[Endgame] Successful climb",
data: "endgame_successful_climb"
},
endgame_help_others_climb: {
name: "[Endgame] Helped other robots with climb",
data: "endgame_help_others_climb"
},
endgame_comments: {
name: "[Endgame] Extra comments",
data: "endgame_comments"
}
}
}
}
var observationFormSchema = {
user: {
type: String,
input: null
},
competition: {
type: String,
input: "dropdown",
placeholder: "Select a competition",
title: "Current competition",
subtitle: "If you're at a practice match, select \"Practice Match\""
},
match: {
type: String,
input: "number",
placeholder: "Match number only",
title: "Match Number",
subtitle: "This is the number of the match that you are observing"
},
team: {
type: String,
input: "number",
placeholder: "Team number only",
title: "Team Number",
subtitle: "This is the team number that you are observing"
},
auto_cross_line: {
type: String,
input: "multiple_choice",
data: {
"yes": "Yes",
"no": "No"
},
title: "[Auto] Crossed auto line?",
subtitle: "Did the bot cross the auto line during auto?"
},
auto_scale_cubes: {
type: String,
input: "multiple_choice",
data: {
"yes": "Yes",
"no": "No",
"attempted": "Attempted and failed"
},
title: "[Auto] Did the bot put cubes on scale?",
subtitle: "Did the bot put cubes on the scale during auto?"
},
auto_switch_cubes: {
type: String,
input: "multiple_choice",
data: {
"yes": "Yes",
"no": "No",
"attempted": "Attempted and failed"
},
title: "[Auto] Did the bot put cubes on switch?",
subtitle: "Did the bot put cubes on the switch during auto?"
},
auto_comments: {
type: String,
input: "long_text",
title: "[Auto] Any extra comments about auto?",
subtitle: "Put anything that would be noteworthy about auto here."
},
teleop_scale_cubes: {
type: String,
input: "number",
placeholder: "Number only",
title: "[Teleop] Number of cubes on scale",
subtitle: "Put the number of cubes they put on the scale here"
},
teleop_switch_cubes: {
type: String,
input: "number",
placeholder: "Number only",
title: "[Teleop] Number of cubes on switch",
subtitle: "Put the number of cubes they put on the switch here"
},
teleop_exchange_cubes: {
type: String,
input: "number",
placeholder: "Number only",
title: "[Teleop] Number of cubes put in the exchange",
subtitle: "Put the number of cubes they put int the exchange/vault here"
},
teleop_cubes_dropped: {
type: String,
input: "number",
placeholder: "Number only",
title: "[Teleop] Number of cubes dropped",
subtitle: "Put the number of cubes that the robot dropped here"
},
teleop_robot_died: {
type: String,
input: "multiple_choice",
data: {
"yes": "Yes",
"no": "No"
},
title: "[Teleop] Did the robot die?",
subtitle: "If they did, note the time of death for the next question"
},
teleop_time_robot_died: {
type: String,
input: "number",
placeholder: "Format: number of seconds only",
title: "[Teleop] Amount of time that robot was dead",
subtitle: "If the robot didn't die, leave this blank"
},
driver_comments: {
type: String,
input: "long_text",
title: "[Driver] Comments about the driver",
subtitle: "Put comments about how much the driver is in control of the robot here. How skilled is the driver?"
},
time_on_defense: {
type: String,
input: "slider",
data: {
"min": 0,
"max": 100
},
title: "[Defense] Percent of time on defense",
subtitle: "Approximate percent of time on defense"
},
speed: {
type: String,
input: "dropdown",
data: {
"slow": "Slow (lower than 8 ft/second)",
"medium": "Medium (8 ft/second to 15 ft/second)",
"fast": "Fast (greater than 15 ft/second)",
},
placeholder: "Select one",
title: "[Bot] Speed compared to our robot (16 ft/second)",
subtitle: "Approximate this if you can"
},
endgame_successful_climb: {
type: String,
input: "multiple_choice",
data: {
"yes": "Yes",
"no": "No",
"attempted": "Attempted and failed"
},
title: "[Endgame] Successful climb?",
subtitle: "Did the robot climb successfully?"
},
endgame_help_others_climb: {
type: String,
input: "multiple_choice",
data: {
"yes": "Yes",
"no": "No",
"attempted": "Attempted and failed"
},
title: "[Endgame] Helped other robots with climb with a bar?",
subtitle: "Did the robot help other robots climb successfully?"
},
endgame_comments: {
type: String,
input: "long_text",
title: "[Endgame] Any extra comments about the end of the game?",
subtitle: "Put anything that would be noteworthy about the end of the game here."
}
}
function getObservationFormStructure() {
var form = {};
for (var key in observationFormSchema) {
if ("data" in observationFormSchema[key]) {
form[key] = {
input: observationFormSchema[key].input,
placeholder: observationFormSchema[key].placeholder,
data: observationFormSchema[key].data,
title: observationFormSchema[key].title,
subtitle: observationFormSchema[key].subtitle
}
} else if (observationFormSchema[key].input != null) {
form[key] = {
input: observationFormSchema[key].input,
placeholder: observationFormSchema[key].placeholder,
title: observationFormSchema[key].title,
subtitle: observationFormSchema[key].subtitle
}
}
}
return form;
}
function getObservationFormSchema() {
var schema = {};
for (var key in observationFormSchema) {
schema[key] = {
type: observationFormSchema[key].type
};
}
return schema;
}
function getObservationFormHandlebarsHelper(structure, options) {
var id = 0;
var finalString = '<form method="post" action="/scout/new">\n<div class="container">\n<div class="row">';
for (var category in structure) {
if (category == "events") continue;
finalString += '<p>';
finalString += '<b>' + structure[category].title + '</b>\n<br>\n' + structure[category].subtitle + '\n';
finalString += '</p>';
if (category == "competition") {
finalString += '<select name="competition">\n';
finalString += '<option value="" disabled ' + (utils.getCurrentEvent() == null ? 'selected' : '') + '>Choose event from list</option>\n';
for (var event in structure.events) {
finalString += '<option value="' + structure.events[event]["key"] + '"' + (structure.events[event]["current"] ? ' selected' : '') + '>' + structure.events[event]["name"] + '</option>\n';
}
finalString += '</select>\n';
} else {
if (structure[category].input == "dropdown") {
finalString += '<select name="' + category + '">\n';
finalString += '<option value="" disabled selected>' + structure[category].placeholder + '</option>\n';
for (var option in structure[category].data) {
finalString += '<option value="' + option + '">' + (structure[category].data)[option] + '</option>\n';
}
finalString += '</select>\n';
} else if (structure[category].input == "multiple_choice") {
for (var option in structure[category].data) {
finalString += '<p>\n';
finalString += '<input class="with-gap" name="' + category + '" value="' + option + '" type="radio" id="' + option + '_' + id + '" />\n';
finalString += '<label for="' + option + '_' + (id ++) + '">' + (structure[category].data)[option] + '</label>\n';
finalString += '</p>\n';
}
} else if (structure[category].input == "long_text") {
finalString += '<div class="input-field">\n';
finalString += '<textarea name="' + category + '" class="materialize-textarea"></textarea>\n';
finalString += '<label for="' + category + '">Message</label>\n';
finalString += '</div>\n';
} else if (structure[category].input == "short_text") {
finalString += '<div class="input-field">\n';
finalString += '<input placeholder="' + structure[category].placeholder + '" name="' + category + '" type="text">\n';
finalString += '</div>\n';
} else if (structure[category].input == "checkbox") {
finalString += '<select name="' + category + '" multiple>\n';
finalString += '<option value="" disabled selected>' + structure[category].placeholder + '</option>\n';
for (var option in structure[category].data) {
finalString += '<option value="' + option + '">' + (structure[category].data)[option] + '</option>\n';
}
finalString += '</select>\n';
} else if (structure[category].input == "number") {
finalString += '<div class="input-field">\n';
finalString += '<input class="validate" placeholder="' + structure[category].placeholder + '" name="' + category + '" type="number">\n';
finalString += '</div>\n';
} else if (structure[category].input == "slider") {
finalString += '<p class="range-field">';
finalString += '<input type="range" name="' + category + '" min="' + (structure[category].data)["min"] + '" max="' + (structure[category].data)["max"] + '" />';
finalString += '</p>';
}
}
finalString += '<br>';
}
finalString += '</div>\n</div>\n<div class="center">\n<button class="btn waves-effect waves-light green" type="submit" name="action">Submit</button>\n</div>\n</form>';
return finalString;
}
function getTableHandlebarsHelper(structure, options) {
var finalString = "<table class='bordered'>\n<thead>\n";
for (var category in tableStructure) finalString += "<th>" + tableStructure[category]["name"] + "</th>\n";
for (var observation in structure) {
finalString += "<tr>";
for (var category in tableStructure) {
var data = tableStructure[category]["data"];
if (typeof data == 'object') {
finalString += "<td>";
for (var subcategory in data) {
var data_subcategory = tableStructure[category]["data"][subcategory]["data"];
var display = structure[observation][data_subcategory];
if (display == null || display == "" || display == "undefined" || display == "NaN") continue;
if ("data" in observationFormSchema[subcategory] && observationFormSchema[subcategory]["input"] !== "slider") display = observationFormSchema[subcategory]["data"][display];
finalString += "<b>" + tableStructure[category]["data"][subcategory]["name"] + ": </b>" + display + "</b><br>";
}
finalString += "</td>";
} else {
finalString += "<td>" + structure[observation][data] + "</td>";
}
}
finalString += "</tr>";
}
finalString += "</thead>\n";
finalString += "</table>";
return finalString;
}
function getRankingHandlebarsHelper(structure, options) {
var finalString = "<table class='bordered'>\n<thead>\n";
for (var category in rankingStructure) finalString += "<th" + (category == "image" ? " class='no-mobile'" : '') + ">" + rankingStructure[category]["name"] + "</th>\n";
for (var observation in structure) {
finalString += "<tr>";
for (var category in rankingStructure) {
if (category == "place") {
finalString += "<td>" + (parseInt(observation) + 1) + "</td>";
continue;
}
var data = rankingStructure[category]["data"];
if (category == "image") finalString += "<td class='no-mobile'>" + (structure[observation][data] == null ? "none" : "<a href='" + structure[observation][data] + "' target='_blank'><img src='" + structure[observation][data] + "' style='height: 200px'></img></a>") + "</td>";
else finalString += "<td>" + structure[observation][data] + "</td>";
}
finalString += "</tr>";
}
finalString += "</thead>\n";
finalString += "</table>";
return finalString;
}
module.exports = {
getObservationFormSchema: getObservationFormSchema,
getObservationFormStructure: getObservationFormStructure,
getObservationFormHandlebarsHelper: getObservationFormHandlebarsHelper,
getTableHandlebarsHelper: getTableHandlebarsHelper,
getRankingHandlebarsHelper: getRankingHandlebarsHelper
};