-
Notifications
You must be signed in to change notification settings - Fork 0
/
scout.html
881 lines (787 loc) · 34.3 KB
/
scout.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
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
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>ViperScout</title>
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Montserrat">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css?family=Open+Sans:400italic,400,600italic,600,700italic,700,800italic,800">
<link rel="stylesheet" type="text/css" href="./styles.css">
<script type="text/javascript" src="dist/sorttable.js"></script>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-133390567-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-133390567-1');
</script>
</head>
<body class="w3-padding-64">
<div class="w3-top w3-bar w3-black w3-hide-small">
<a href="#" class="w3-bar-item w3-button" id="home_button">Scout</a>
<a href="index.html" class="w3-bar-item w3-button">ViperScout</a>
<a href="all.html" class="w3-bar-item w3-button">All regionals/districts</a>
<a href="prediction.html" class="w3-bar-item w3-button">Match Prediction</a>
<a href="#" class="w3-bar-item w3-button w3-mobile w3-right viper-black-hover" id="questions_button">
<i class="fa fa-question-circle" alt="Questions?"></i>
</a>
</div>
<!-- Navbar on small screens (Hidden on medium and large screens) -->
<div class="w3-top w3-light-grey w3-hide-large w3-hide-medium" id="myNavbar">
<div class="w3-bar w3-center w3-large">
<a href="#" class="w3-bar-item w3-button w3-grey" style="width:25% !important" id="home_button"><i class="fa fa-home" alt="Home"></i></a>
<a href="all.html" class="w3-bar-item w3-button w3-light-grey" style="width:25% !important">All</a>
<a href="prediction.html" class="w3-bar-item w3-button w3-light-grey" style="width:25% !important">Predict</a>
</div>
</div>
<!-- Page Content -->
<div class="w3-padding-large" id="main">
<!-- Questions pop-up -->
<div id="questions_alert" class="w3-justify w3-panel grey-no-hover w3-display-container w3-animate-opacity">
<span id="getStartedClose" class="w3-button w3-xlarge red-hover w3-display-topright">×</span>
<h3>Getting Started</h3>
<p>Use the search-bar below and start typing a name, location, or code for a regional or district event.
After finding your event, click the row to open up the stats page</p>
<p>OPR on this site is generated by summing up all columns EXCEPT penalties. OPRP is OPR with penalties subtracted,
which is an attempt to penalize teams that are committing lots of fouls.</p>
<p>The OPR you see here WILL be different from thebluealliance.com as TBA only uses final scores for its' OPR calculations,
which has penalties baked in</p>
</div>
<header class="w3-container viper-black-no-hover">
<center><h5 id="predict_tab">Click Here for Next Match Prediction</h5></center>
</header>
<p></p>
<!-- Container for the item content viewer -->
<div class="w3-justify w3-card w3-white" id="scout_details">
<header class="w3-container viper-black-no-hover">
<center><h3><span id="scout_details_name"></span></h3></center>
</header>
<!-- OPR table -->
<table class="sortable w3-card w3-table w3-striped w3-hoverable" id="team_table">
<!--Generated items will go here-->
</table>
</div>
<!-- Container for the item content viewer -->
<div class="w3-justify w3-card w3-white" id="team_details" style="display: none;">
<header class="w3-container viper-black-no-hover">
<h3><span id="team_details_name"></span></h3>
</header>
<div class="w3-half w3-padding">
<canvas id="shot_chart" responsive="true" aspectRatio="1"></canvas>
</div>
<div class="w3-half w3-padding">
<canvas id="pickup_chart" responsive="true" aspectRatio="1"></canvas>
</div>
</div>
<!-- Container for the item content viewer -->
<div class="w3-justify w3-card w3-white" id="scout_predict" style="display: none;">
<div class="w3-container w3-center" id="detail_header">
</div>
<div class="w3-row w3-margin-top w3-margin-bottom" id="alliance-tabs" style="display:none">
<button class="w3-half w3-red w3-button" onclick="switchTab('red')">Red</button>
<button class="w3-half w3-blue w3-button" onclick="switchTab('blue')">Blue</button>
</div>
<div class="w3-justify w3-text-black w3-margin-bottom" id="detail_container">
</div>
<div class="w3-row w3-margin-top" id="blue_shot_charts" style="display: none;">
<div class="w3-third w3-padding">
<canvas id="blue_1_shot" responsive="true" aspectRatio="1"></canvas>
</div>
<div class="w3-third w3-padding">
<canvas id="blue_2_shot" responsive="true" aspectRatio="1"></canvas>
</div>
<div class="w3-third w3-padding">
<canvas id="blue_3_shot" responsive="true" aspectRatio="1"></canvas>
</div>
</div>
<div class="w3-row w3-margin-top" id="blue_pickup_charts" style="display: none;">
<div class="w3-third w3-padding">
<canvas id="blue_1_pickup" responsive="true" aspectRatio="1"></canvas>
</div>
<div class="w3-third w3-padding">
<canvas id="blue_2_pickup" responsive="true" aspectRatio="1"></canvas>
</div>
<div class="w3-third w3-padding">
<canvas id="blue_3_pickup" responsive="true" aspectRatio="1"></canvas>
</div>
</div>
<div class="w3-row w3-margin-top" id="red_shot_charts" style="display: none;">
<div class="w3-third w3-padding">
<canvas id="red_1_shot" responsive="true" aspectRatio="1"></canvas>
</div>
<div class="w3-third w3-padding">
<canvas id="red_2_shot" responsive="true" aspectRatio="1"></canvas>
</div>
<div class="w3-third w3-padding">
<canvas id="red_3_shot" responsive="true" aspectRatio="1"></canvas>
</div>
</div>
<div class="w3-row w3-margin-top" id="red_pickup_charts" style="display: none;">
<div class="w3-third w3-padding">
<canvas id="red_1_pickup" responsive="true" aspectRatio="1"></canvas>
</div>
<div class="w3-third w3-padding">
<canvas id="red_2_pickup" responsive="true" aspectRatio="1"></canvas>
</div>
<div class="w3-third w3-padding">
<canvas id="red_3_pickup" responsive="true" aspectRatio="1"></canvas>
</div>
</div>
</div>
<!-- END PAGE CONTENT -->
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/js-cookie@2/src/js.cookie.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.18.0/axios.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjs/5.6.0/math.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.3/Chart.bundle.js"></script>
<script type="text/javascript" src="dist/scripts.js"></script>
<script src="https://www.gstatic.com/firebasejs/5.9.1/firebase.js"></script>
<script src="./dist/bundle.js"></script>
</body>
<script id="opr-header-table" type="text/template">
<thead class="viper-grey">
<td>Team</td>
<td>Pickups</td>
<td>[P] Fender</td>
<td>[P] H.Player</td>
<td>[P] Trench</td>
<td>[P] Truss</td>
<td>[P] Opponent</td>
<td>Shots</td>
<td>Shot misses</td>
<td>[S] Fender</td>
<td>[S] Initiation</td>
<td>[S] Trench</td>
<td>[S] Fortune</td>
<td>[S] Full</td>
<td>[S] Cleared</td>
</thead>
</script>
<script id="opr-template-table-entry" type="text/template">
<tr class="table_entry" >
<td class="table_entry_team" id="{{team}}">{{team}}</td>
<td>{{pickups}}</td>
<td>{{p_fender}}</td>
<td>{{p_player}}</td>
<td>{{p_trench}}</td>
<td>{{p_truss}}</td>
<td>{{p_opp}}</td>
<td>{{shots}}</td>
<td>{{shots_missed}}</td>
<td>{{s_fender}}</td>
<td>{{s_initiation}}</td>
<td>{{s_trench}}</td>
<td>{{s_fortune}}</td>
<td>{{s_full}}</td>
<td>{{s_clear}}</td>
</tr>
</script>
<script id="template-detail" type="text/template">
<h3>Match {{match}} in {{regional}}</h3>
</script>
<script id="template-detail-last" type="text/template">
<h4>Next match unavailable. Last match official score was blue: {{blue}}, red: {{red}}</h4>
</script>
<script type="text/javascript">
var tba = new TBA();
var colors = [ 'blue', 'red' ];
let event = '2019txaus';
$('#scout_details_name').html(event);
$('#home_button').on('click', function() {
$('#scout_details').show();
$('#team_details').hide();
$('#scout_predict').hide();
});
$('#getStartedClose').on('click', function() {
$('#questions_alert').hide();
Cookies.set('getStartedClose', true, { expires: 365 });
});
$('#questions_button').on('click', function() {
$("#questions_alert").show();
});
function calcStats(match, new_match) {
// Setup header
var detailTemplate = document.getElementById("template-detail");
var detailLastTemplate = document.getElementById("template-detail-last");
var detailTemplateHtml = detailTemplate.innerHTML;
var detailLastTemplateHtml = detailLastTemplate.innerHTML;
detailTemplateHtml = detailTemplateHtml.replace(/{{match}}/g, match.comp_level.toUpperCase()+match.match_number)
.replace(/{{regional}}/g, match.event_key);
if (!new_match) {
detailLastTemplateHtml = detailLastTemplateHtml.replace(/{{red}}/g, match.alliances.red.score)
.replace(/{{blue}}/g, match.alliances.blue.score);
document.getElementById("detail_header").innerHTML = detailTemplateHtml + detailLastTemplateHtml;
} else {
document.getElementById("detail_header").innerHTML += detailTemplateHtml;
}
for (var color in colors) {
var teamDataset = [{
data: [],
backgroundColor: chartColors.grey,
label: 'Start'
},{
data: [],
backgroundColor: chartColors.yellow,
label: 'Auto'
},{
data: [],
backgroundColor: chartColors.purple,
label: 'Teleop'
},{
data: [],
backgroundColor: chartColors.red,
label: 'Climb'
},{
data: [],
backgroundColor: chartColors.pink,
label: 'Level?'
}];
var autoDataset = [{
data: [],
backgroundColor: chartColors.blue,
label: 'Low'
},{
data: [],
backgroundColor: chartColors.green,
label: 'Outer'
},{
data: [],
backgroundColor: chartColors.orange,
label: 'Inner'
}];
var teleopDataset = [{
data: [],
backgroundColor: chartColors.blue,
label: 'Low'
},{
data: [],
backgroundColor: chartColors.green,
label: 'Outer'
},{
data: [],
backgroundColor: chartColors.orange,
label: 'Inner'
}];
var teams = [ match.alliances[colors[color]].team_keys[0].replace('frc',''),
match.alliances[colors[color]].team_keys[1].replace('frc',''),
match.alliances[colors[color]].team_keys[2].replace('frc','') ];
// Setup cargo table
var autoTemplate = document.getElementById("template-auto");
var autoHeader = document.getElementById("header-template-auto");
var autoTemplateHtml = autoTemplate.innerHTML;
var autoHeaderHtml = autoHeader.innerHTML;
autoHeaderHtml = autoHeaderHtml.replace(/{{color}}/g, colors[color]);
var autoHtml = autoHeaderHtml;
// Setup rocket table
var teleopTemplate = document.getElementById("template-teleop");
var teleopHeader = document.getElementById("header-template-teleop");
var teleopTemplateHtml = teleopTemplate.innerHTML;
var teleopHeaderHtml = teleopHeader.innerHTML;
teleopHeaderHtml = teleopHeaderHtml.replace(/{{color}}/g, colors[color]);
var teleopHtml = teleopHeaderHtml;
// Setup rocket table
var overallTemplate = document.getElementById("template-overall");
var overallHeader = document.getElementById("header-template-overall");
var overallTemplateHtml = overallTemplate.innerHTML;
var overallHeaderHtml = overallHeader.innerHTML;
overallHeaderHtml = overallHeaderHtml.replace(/{{color}}/g, colors[color]);
var overallHtml = overallHeaderHtml;
var score = 0;
for (var team in teams) {
var result;
if (!(teams[team] in results)) {
result = {
'autoCellsInner': 0,
'autoCellsOuter': 0,
'autoCellsBottom': 0,
'teleopCellsInner': 0,
'teleopCellsOuter': 0,
'teleopCellsBottom': 0,
'move': 0,
'climb': 0,
'rung_level': 0,
'opr': 0,
'oprp': 0
};
} else {
result = results[teams[team]];
}
score += result.oprp;
autoHtml += autoTemplateHtml.replace(/{{team}}/g, teams[team])
.replace(/{{auto_low}}/g, result.autoCellsBottom.toFixed(1))
.replace(/{{auto_outer}}/g, result.autoCellsOuter.toFixed(1))
.replace(/{{auto_inner}}/g, result.autoCellsInner.toFixed(1));
teleopHtml += teleopTemplateHtml.replace(/{{team}}/g, teams[team])
.replace(/{{teleop_low}}/g, result.teleopCellsBottom.toFixed(1))
.replace(/{{teleop_outer}}/g, result.teleopCellsOuter.toFixed(1))
.replace(/{{teleop_inner}}/g, result.teleopCellsInner.toFixed(1));
overallHtml += overallTemplateHtml.replace(/{{team}}/g, teams[team])
.replace(/{{oprp}}/g, result.oprp.toFixed(1))
.replace(/{{start}}/g, result.move.toFixed(1))
.replace(/{{end}}/g, result.climb.toFixed(1))
.replace(/{{rung_level}}/g, result.rung_level.toFixed(1))
.replace(/{{auto}}/g,
(result.autoCellsBottom +
result.autoCellsInner +
result.autoCellsOuter).toFixed(1))
.replace(/{{teleop}}/g,
(result.teleopCellsInner +
result.teleopCellsOuter +
result.teleopCellsBottom).toFixed(1));
teamDataset[0].data.push(result.move.toFixed(1));
teamDataset[1].data.push((result.autoCellsBottom +
result.autoCellsInner +
result.autoCellsOuter).toFixed(1));
teamDataset[2].data.push((result.teleopCellsInner +
result.teleopCellsOuter +
result.teleopCellsBottom).toFixed(1));
teamDataset[3].data.push(result.climb.toFixed(1));
teamDataset[4].data.push(result.rung_level.toFixed(1));
autoDataset[0].data.push(result.autoCellsBottom.toFixed(1));
autoDataset[1].data.push(result.autoCellsOuter.toFixed(1));
autoDataset[2].data.push(result.autoCellsInner.toFixed(1));
teleopDataset[0].data.push(result.teleopCellsBottom.toFixed(1));
teleopDataset[1].data.push(result.teleopCellsOuter.toFixed(1));
teleopDataset[2].data.push(result.teleopCellsInner.toFixed(1));
}
// Fill div
var detailDiv = document.getElementById("div-template");
var detailDivHtml = detailDiv.innerHTML;
detailDivHtml = detailDivHtml.replace(/{{color}}/g, colors[color])
.replace(/{{score}}/g, score.toFixed(0));
document.getElementById("detail_container").innerHTML += detailDivHtml;
document.getElementById(colors[color] + "-auto").innerHTML = autoHtml;
sorttable.makeSortable(document.getElementById(colors[color] + "-auto"));
document.getElementById(colors[color] + "-teleop").innerHTML = teleopHtml;
sorttable.makeSortable(document.getElementById(colors[color] + "-teleop"));
document.getElementById(colors[color] + "-overall").innerHTML = overallHtml;
sorttable.makeSortable(document.getElementById(colors[color] + "-overall"));
var overallChartData = {
type: 'bar',
data: {
labels: teams,
datasets: teamDataset
},
options: {
title: {
display: true,
text: 'Overall'
},
scales: {
xAxes: [{ stacked: true }],
yAxes: [{
ticks: {
suggestedMax: 25,
beginAtZero: true
},
stacked: true
}]
}
}
};
var chart = new Chart(html_charts[colors[color]].overall, overallChartData);
var autoChartData = {
type: 'bar',
data: {
labels: teams,
datasets: autoDataset
},
options: {
title: {
display: true,
text: 'Auto Cells'
},
scales: {
xAxes: [{ stacked: true }],
yAxes: [{
ticks: {
suggestedMax: 10,
beginAtZero: true
},
stacked: true
}]
}
}
};
var chart = new Chart(html_charts[colors[color]].auto, autoChartData);
var teleopChartData = {
type: 'bar',
data: {
labels: teams,
datasets: teleopDataset
},
options: {
title: {
display: true,
text: 'Teleop Cells'
},
scales: {
xAxes: [{ stacked: true }],
yAxes: [{
ticks: {
suggestedMax: 10,
beginAtZero: true
},
stacked: true
}]
}
}
};
var chart = new Chart(html_charts[colors[color]].teleop, teleopChartData);
document.getElementById('alliance-tabs').style.display = 'block';
}
}
function lookupTeam(team) {
tba.getOverallTeamNextMatch(team, function(result_new) {
if (!result_new) {
tba.getOverallTeamLastMatch(team, function(result_last) {
if (result_last)
calcStats(result_last, false);
});
} else {
calcStats(result_new, true);
}
});
}
$('#predict_tab').on('click', function() {
lookupTeam(6800);
$('#scout_details').hide();
$('#team_details').hide();
$('#scout_predict').show();
});
// Initialize Firebase
// TODO: Replace with your project's customized code snippet
var config = {
apiKey: "AIzaSyBCkRFpZZGvysBQm7uEGTgKuKn9kHESLgY",
authDomain: "viperbotsvalor.firebaseapp.com",
databaseURL: "https://viperbotsvalor.firebaseio.com",
projectId: "viperbotsvalor",
storageBucket: "viperbotsvalor.appspot.com",
messagingSenderId: "551998214691",
appId: "1:551998214691:web:eb630dd0b63ca8420cd796"
};
firebase.initializeApp(config);
let teamStats = {}
let bounding_box_shot = {
fender: {
x_min: 210,
x_max: 255,
y_min: 0,
y_max: 150
},
initiation: {
x_min: 170,
x_max: 210,
y_min: 0,
y_max: 125
},
trench: {
x_min: 100,
x_max: 170,
y_min: 0,
y_max: 70
},
fortune: {
x_min: 80,
x_max: 100,
y_min: 0,
y_max: 70
},
full: {
x_min: 0,
x_max: 80,
y_min: 0,
y_max: 100
}
}
let bounding_box_pickup = {
fender: {
x_min: 185,
x_max: 255,
y_min: 0,
y_max: 125
},
human_player: {
x_min: 0,
x_max: 70,
y_min: 0,
y_max: 125
},
trench: {
x_min: 60,
x_max: 185,
y_min: 0,
y_max: 70
},
truss: {
x_min: 60,
x_max: 185,
y_min: 70,
y_max: 200
},
opponent: {
x_min: 185,
x_max: 255,
y_min: 125,
y_max: 255
}
}
var chartColors = {
red: 'rgb(255, 0, 0, 0.4)',
pink: 'rgb(255, 99, 132, 0.4)',
orange: 'rgb(255, 159, 64, 0.4)',
dark_orange: 'rgb(255, 109, 64, 0.4)',
light_orange: 'rgb(255, 209, 64, 0.4)',
yellow: 'rgb(255, 205, 86, 0.4)',
green: 'rgb(75, 192, 192, 0.4)',
blue: 'rgb(54, 162, 235, 0.4)',
purple: 'rgb(153, 102, 255, 0.4)',
grey: 'rgb(201, 203, 207, 0.4)'
};
function findZone(x, y, map) {
for (let item in map) {
if (x >= map[item].x_min &&
x <= map[item].x_max &&
y >= map[item].y_min &&
y <= map[item].y_max)
return item;
}
return 'none';
}
function parseEvent(team, alliance, event) {
let deltaX = parseInt(event.x);
let deltaY = parseInt(event.y);
let result = parseInt(event.result);
// Invert if blue alliance
if (alliance === 'blue') {
deltaX = 255 - deltaX;
deltaY = 255 - deltaY;
}
// Return if event is invalid
if (deltaX === 0 && deltaY === 0 || deltaX === 255 && deltaY === 255)
return;
// Find zone
let zone = findZone(deltaX, deltaY, bounding_box_shot);
if (event.result === 5)
zone = findZone(deltaX, deltaY, bounding_box_pickup);
// Find auto or teleop
let prefix = parseInt(event.timestamp) <= 16 ? 'auto' : 'teleop';
// Made shot
if (result < 3) {
teamStats[team].shots.made += 1;
let key = result == 0 ? 'CellsInner' : (result == 1 ? 'CellsOuter' : 'CellsBottom');
teamStats[team].sums[prefix + key] += 1;
if (zone !== 'none') {
teamStats[team].shots[zone] += 1;
}
}
// Missed shot
if (result === 3) {
teamStats[team].shots.miss += 1;
if (zone !== 'none') {
teamStats[team].shots[zone + 'Miss'] += 1;
}
}
// Cleared shot
if (result === 4) {
teamStats[team].shots.cleared += 1;
}
// Pickup
if (event.result === 5) {
teamStats[team].pickups.total += 1;
if (zone !== 'none') {
teamStats[team].pickups[zone] += 1;
}
}
}
function analyzeEvent() {
// Cache of the template
var OPRheader = document.getElementById("opr-header-table");
var OPRtemplate = document.getElementById("opr-template-table-entry");
// Get the contents of the template
var OPRHeaderHtml = OPRheader.innerHTML;
var OPRTemplateHtml = OPRtemplate.innerHTML;
// Final HTML variable as empty string
var listHtml = OPRHeaderHtml;
for (var team in teamStats) {
// let shotChart = [];
// for (var shot in teamStats[team].shots) {
// if (!shot.toLowerCase().includes('miss') && !shot.includes('made')) {
// shotChart.push({name: shot, count: teamStats[team].shots[shot]});
// }
// }
// shotChart.sort(function(a, b) {
// return b.count - a.count;
// });
// let shotCount = teamStats[team].shots.made + teamStats[team].shots.miss;
// console.log("Best shot: " + shotChart[0].name + " (" + shotChart[0].count + ")");
listHtml += OPRTemplateHtml.replace(/{{url}}/g, "https://www.thebluealliance.com/team/" + team)
.replace(/{{team}}/g, team)
.replace(/{{pickups}}/g, teamStats[team].pickups.total)
.replace(/{{p_fender}}/g, teamStats[team].pickups.fender)
.replace(/{{p_player}}/g, teamStats[team].pickups.human_player)
.replace(/{{p_trench}}/g, teamStats[team].pickups.trench)
.replace(/{{p_truss}}/g, teamStats[team].pickups.truss)
.replace(/{{p_opp}}/g, teamStats[team].pickups.opponent)
.replace(/{{shots}}/g, teamStats[team].shots.made)
.replace(/{{shots_missed}}/g, teamStats[team].shots.miss)
.replace(/{{s_fender}}/g, teamStats[team].shots.fender)
.replace(/{{s_initiation}}/g, teamStats[team].shots.initiation)
.replace(/{{s_trench}}/g, teamStats[team].shots.trench)
.replace(/{{s_fortune}}/g, teamStats[team].shots.fortune)
.replace(/{{s_full}}/g, teamStats[team].shots.full)
.replace(/{{s_clear}}/g, teamStats[team].shots.cleared)
}
// Replace the HTML of #list with final HTML
document.getElementById("team_table").innerHTML = listHtml;
sorttable.makeSortable(document.getElementById("team_table"));
$('#team_table tr').not(':first').each(function(index, element) {
$(element).on('click', function() {
var team = $(element).find('.table_entry_team').attr('id');
$('#team_details_name').html(team);
var shotDataset = [{
data: [],
backgroundColor: chartColors.green,
label: 'Made'
},{
data: [],
backgroundColor: chartColors.red,
label: 'Missed'
}];
var pickupDataset = [{
data: [],
backgroundColor: chartColors.green,
label: 'Pickup'
}];
let shotLabels = ['Fender','Initiation','Trench','Fortune','Full','Cleared'];
let pickupLabels = ['Fender','Human_player','Trench','Truss','Opponent'];
for (var label in shotLabels) {
let key = shotLabels[label].toLowerCase();
shotDataset[0].data.push(teamStats[team].shots[key]);
shotDataset[1].data.push(teamStats[team].shots[key + 'Miss']);
}
for (var label in pickupLabels) {
let key = pickupLabels[label].toLowerCase();
pickupDataset[0].data.push(teamStats[team].pickups[key]);
}
var shotChartData = {
type: 'bar',
data: {
labels: shotLabels,
datasets: shotDataset
},
options: {
title: {
display: true,
text: 'Shot Breakdown'
},
scales: {
xAxes: [{ stacked: true }],
yAxes: [{
ticks: {
beginAtZero: true
},
stacked: true
}]
}
}
};
var chart = new Chart(document.getElementById('shot_chart').getContext('2d'), shotChartData);
var pickupChartData = {
type: 'bar',
data: {
labels: pickupLabels,
datasets: pickupDataset
},
options: {
title: {
display: true,
text: 'Pickup Breakdown'
},
scales: {
xAxes: [{ stacked: true }],
yAxes: [{
ticks: {
beginAtZero: true
},
stacked: true
}]
}
}
};
var chart = new Chart(document.getElementById('pickup_chart').getContext('2d'), pickupChartData);
$('#scout_details').hide();
$('#team_details').show();
$('#scout_predict').hide();
});
});
}
function genTourneyResults() {
var database = firebase.database();
firebase.database().ref(event).once('value').then(function(snapshot) {
snapshot.forEach(function(child) {
let team = parseInt(child.key);
if (team != 0) {
if (!(team in teamStats)) {
teamStats[team] = {
'matches': 0,
'sums': {
'autoCellsBottom': 0,
'autoCellsInner': 0,
'autoCellsOuter': 0,
'teleopCellsBottom': 0,
'teleopCellsInner': 0,
'teleopCellsOuter': 0,
'move': 0,
'climb': 0,
'penalty': 0,
'rung_level': 0,
'panel': 0
},
'pickups': {
'total': 0,
'fender': 0,
'human_player': 0,
'trench': 0,
'truss': 0,
'opponent': 0
},
'shots': {
'made': 0,
'miss': 0,
'fender': 0,
'fenderMiss': 0,
'initiation': 0,
'initiationMiss': 0,
'trench': 0,
'trenchMiss': 0,
'fortune': 0,
'fortuneMiss': 0,
'full': 0,
'fullMiss': 0,
'cleared': 0
}
};
}
// Iterate through each match for every team
let matches = child.val();
for (let matchStr in matches) {
let match = parseInt(matchStr.replace('match',''));
let alliance = parseInt(matches[matchStr].alliance) === 0 ? 'red' : 'blue';
teamStats[team].matches += 1;
// Iterate through every event in the match
for (let event in matches[matchStr].events) {
parseEvent(team, alliance, matches[matchStr].events[event]);
}
}
}
});
analyzeEvent();
});
}
genTourneyResults();
</script>