-
Notifications
You must be signed in to change notification settings - Fork 0
/
rankings.php
352 lines (317 loc) · 12 KB
/
rankings.php
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
<title>rankings</title>
<html lang="en">
<style>
th:first-child, td:first-child
{
position:sticky;
left:0px;
background-color:grey;
}
thead th
{
position:sticky;
top:0;
background-color:grey;
}
</style>
<?php include('navbar.php'); ?>
<body class="bg-body">
<div class="container row-offcanvas row-offcanvas-left">
<div class="well column col-lg-12 col-sm-12 col-xs-12" id="content">
<div class="row pt-3">
<div class="float-right">
<button type="button" id="downloadTable" class="btn btn-primary">Download Table As CSV</button>
</div>
</div>
<div class="row pt-3 pb-3 mb-3">
<div class='overflow-auto'>
<table id='fullDataTable' class='table sortable table-striped'>
<thead style="position: sticky;top: 0">
<tr>
<th col='scope' style='z-index:2' class='table-secondary' >Team</th>
<th col='scope'>Rank</th>
<th col='scope'>Weighted Score</th>
<th col='scope'>Avg Points</th>
<th col='scope'>Max Points</th>
<th col='scope'>Avg Auto Pieces</th>
<th col='scope'>Max Auto Pieces</th>
<th col='scope'>Auto Dock %</th>
<th col='scope'>Auto Engage %</th>
<th col='scope'>Avg Teleop Pieces</th>
<th col='scope'>Max Teleop Pieces</th>
<th col='scope'>Max Teleop Cones</th>
<th col='scope'>Max Teleop Cubes</th>
<th col='scope'>Teleop Park %</th>
<th col='scope'>Teleop Dock %</th>
<th col='scope'>Teleop Engage %</th>
<th col='scope'>Organization Level</th>
<th col='scope'># Batteries</th>
<th col='scope'># Chargers</th>
<th col='scope'>Language</th>
<th col='scope'>Drive Train</th>
<th col='scope'>Auto Path</th>
<th col='scope'>Frame Dimensions</th>
<th col='scope'>Pit Comments</th>
<th col='scope'>Scout Flagged Matches</th>
<th col='scope'>Avg Strike Rating (0-5)</th>
<th col='scope'>Strike Comments</th>
<th col='scope'>Strike Vibes</th>
</tr>
</thead>
<tbody id="dataTable">
</tbody>
</table>
</div>
</div>
</div>
</div>
</body>
<?php include("footer.php"); ?>
<script type="text/javascript" src="js/matchDataProcessor.js?cache=10"></script>
<script>
var matchDataLookUp = {};
var pitDataLookUp = {};
var rankingLookUp = {}
var strikeLookup = {};
var teamList = [];
function safeDataLookup(key, obj) {
if (key in obj) {
return obj[key];
}
return {};
}
function safeLookup(key, obj) {
if (key in obj) {
return obj[key];
}
return 0;
}
function getTeamList() {
var matchTeamSet = new Set(Object.keys(matchDataLookUp));
var teamListSet = new Set(Array.from(teamList, x => `${x}`));
return Array.from(new Set([...matchTeamSet, ...teamListSet]));
}
function reDrawTable() {
$('#dataTable').html('');
var teams = getTeamList()
for (var i = 0; i != teams.length; i++) {
var team = teams[i];
var matchData = safeDataLookup(team, matchDataLookUp);
var pitData = safeDataLookup(team, pitDataLookUp);
var strikeData = safeDataLookup(team, strikeLookup);
var rows = [
`<tr>`,
` <td style='z-index:2' class='table-secondary' scope='row' sorttable_customkey='${team}'><a href='./teamData.php?team=${team}'>${team}</a></td>`,
` <td scope='row'>${safeLookup(`frc${team}`, rankingLookUp)}</td>`,
` <td scope='row'>${safeLookup('weightedScore', matchData)}</td>`,
` <td scope='row'>${safeLookup('avgPoints', matchData)}</td>`,
` <td scope='row'>${safeLookup('maxPoints', matchData)}</td>`,
` <td scope='row'>${safeLookup('avgAutoPieces', matchData)}</td>`,
` <td scope='row'>${safeLookup('maxAutoPieces', matchData)}</td>`,
` <td scope='row'>${safeLookup('avgAutoDock', matchData)}%</td>`,
` <td scope='row'>${safeLookup('avgAutoEngage', matchData)}%</td>`,
` <td scope='row'>${safeLookup('avgTeleopPieces', matchData)}</td>`,
` <td scope='row'>${safeLookup('maxTeleopPieces', matchData)}</td>`,
` <td scope='row'>${safeLookup('maxTeleopCones', matchData)}</td>`,
` <td scope='row'>${safeLookup('maxTeleopCubes', matchData)}</td>`,
` <td scope='row'>${safeLookup('avgTeleopPark', matchData)}%</td>`,
` <td scope='row'>${safeLookup('avgTeleopDock', matchData)}%</td>`,
` <td scope='row'>${safeLookup('avgTeleopEngage', matchData)}%</td>`,
` <td scope='row'>${safeLookup('disorganized', pitData)}</td>`,
` <td scope='row'>${safeLookup('numBatteries', pitData)}</td>`,
` <td scope='row'>${safeLookup('chargedBatteries', pitData)}</td>`,
` <td scope='row'>${safeLookup('codeLanguage', pitData)}</td>`,
` <td scope='row'>${safeLookup('drivetrainType', pitData)}</td>`,
` <td scope='row'>${safeLookup('autoPath', pitData)}</td>`,
` <td scope='row'>${safeLookup('framePerimeterDimensions', pitData)}</td>`,
` <td scope='row'>${safeLookup('pitComments', pitData)}</td>`,
` <td scope='row'>${safeLookup('problematicMatchCount', matchData)}</td>`,
` <td scope='row'>${safeLookup('rating', strikeData)}</td>`,
` <td scope='row'>${safeLookup('strikeComments', strikeData)}</td>`,
` <td scope='row'>${safeLookup('vibes', strikeData)}</td>`,
`</tr>`
].join('');
$('#dataTable').append(rows);
}
var fullTable = document.getElementById('fullDataTable');
sorttable.makeSortable(fullTable);
sorttable.makeSortable(fullTable);
}
function strikeDataToStrikeLookup(data){
for (var i = 0; i != data.length; i++){
var strike = data[i];
var team = strike['strikeTeamNumber'];
strikeLookup[team] = strike
var rating = 0;
if (strike['bumpers'] == 'average') {rating += 3}
if (strike['bumpers'] == 'great') {rating += 5}
if (strike['mechRobustness'] == 'average') {rating += 3}
if (strike['mechRobustness'] == 'good') {rating += 5}
if (strike['elecRobustness'] == 'average') {rating += 3}
if (strike['elecRobustness'] == 'good') {rating += 5}
strikeLookup[team]['rating'] = roundInt(rating/3);
}
}
function pitDataToPitDataLookUp(data) {
for (var i = 0; i != data.length; i++) {
var pit = data[i];
var team = pit['pitTeamNumber'];
pitDataLookUp[team] = pit;
}
}
function matchDataTomatchDataLookUp(data) {
var teamToDataList = {};
for (var i = 0; i != data.length; i++) {
var match = data[i];
if (!(match['teamNumber'] in teamToDataList)) {
teamToDataList[match['teamNumber']] = [];
}
teamToDataList[match['teamNumber']].push(match);
}
// Process data for each team.
for (let team in teamToDataList) {
var matchCount = 0;
var weightedScore = 0;
var totalPoints = 0;
var maxPoints = 0;
var totalAutoPieces = 0;
var maxAutoPieces = 0;
var totalAutoDock = 0;
var totalAutoEngage = 0;
var totalTeleopPiece = 0;
var maxTeleopCones = 0;
var maxTeleopCubes = 0;
var maxTeleopPieces = 0;
var avgTeleopPark = 0;
var avgTeleopDock = 0;
var avgTeleopEngage = 0;
for (var i = 0; i != teamToDataList[team].length; i++) {
var match = teamToDataList[team][i];
matchCount++;
weightedScore += getWeightedScore(match);
totalPoints += getMatchPoints(match);
maxPoints = Math.max(maxPoints, getMatchPoints(match));
totalAutoPieces += getPiecesAuto(match);
maxAutoPieces = Math.max(maxAutoPieces, getPiecesAuto(match));
totalAutoDock += getDockAuto(match) ? 1 : 0;
totalAutoEngage += getEngageAuto(match) ? 1 : 0;
totalTeleopPiece += getPiecesTeleop(match);
maxTeleopCones = Math.max(maxTeleopCones, getConesTeleop(match));
maxTeleopCubes = Math.max(maxTeleopCubes, getCubesTeleop(match));
maxTeleopPieces = Math.max(maxTeleopPieces, getPiecesTeleop(match));
avgTeleopPark += getParkTeleop(match) ? 1 : 0;
avgTeleopDock += getDockTeleop(match) ? 1 : 0;
avgTeleopEngage += getEngageTeleop(match) ? 1 : 0;
}
// Add to matchDataLookUp.
var lookup = {};
lookup['weightedScore'] = roundInt(weightedScore / matchCount);
lookup['avgPoints'] = roundInt(totalPoints / matchCount);
lookup['maxPoints'] = roundInt(maxPoints);
lookup['avgAutoPieces'] = roundInt(totalAutoPieces / matchCount);
lookup['maxAutoPieces'] = roundInt(maxAutoPieces);
lookup['avgAutoDock'] = roundInt((totalAutoDock / matchCount) * 100);
lookup['avgAutoEngage'] = roundInt((totalAutoEngage / matchCount) * 100);
lookup['avgTeleopPieces'] = roundInt(totalTeleopPiece / matchCount);
lookup['maxTeleopPieces'] = maxTeleopPieces;
lookup['maxTeleopCones'] = roundInt(maxTeleopCones);
lookup['maxTeleopCubes'] = roundInt(maxTeleopCubes);
lookup['avgTeleopPark'] = roundInt((avgTeleopPark / matchCount) * 100);
lookup['avgTeleopDock'] = roundInt((avgTeleopDock / matchCount) * 100);
lookup['avgTeleopEngage'] = roundInt((avgTeleopEngage / matchCount) * 100);
lookup['problematicMatchCount'] = getProblematicCannedCommentMatchCount(teamToDataList[team]);
matchDataLookUp[team] = lookup;
}
}
function loadMatchData() {
$.get('readAPI.php', {
'readAllMatchData': 1
}).done(function(data) {
var data = JSON.parse(data);
matchDataTomatchDataLookUp(data);
reDrawTable();
});
}
function loadPitData() {
$.get('readAPI.php', {
'readAllPitScoutData': 1
}).done(function(data) {
var data = JSON.parse(data);
pitDataToPitDataLookUp(data);
reDrawTable();
});
}
function loadRankingData() {
$.get('tbaAPI.php', {
'getRankings': 1
}).done(function(data) {
var data = JSON.parse(data);
rankingLookUp = data;
reDrawTable();
});
}
function loadTeamList() {
$.get('tbaAPI.php', {
'getTeamList': 1
}).done(function(data) {
var data = JSON.parse(data);
teamList = data;
reDrawTable();
});
}
function loadStrikeData(){
$.post("readAPI.php", {
"readAllStrikeScoutData": true
}, function(data) {
var data = JSON.parse(data);
strikeDataToStrikeLookup(data);
reDrawTable();
});
}
function getTableAsCSVString() {
var table_array = [];
var rows = document.getElementsByTagName('tr');
for (var i = 0; i < rows.length; i++) {
var cols = rows[i].querySelectorAll('td,th');
var row_array = []
for (var j = 0; j < cols.length; j++) {
if (j == 0) { // Strip link from team number in col 1
var team_link = cols[j].querySelectorAll('a');
if (team_link.length == 0) {
row_array.push(cols[j].innerHTML);
} else {
row_array.push(team_link[0].innerHTML);
}
} else {
row_array.push(cols[j].innerHTML);
}
}
table_array.push(row_array.join(','));
}
return table_array.join('\n');
}
function downloadTable() {
CSVFile = new Blob([getTableAsCSVString()], {
type: "text/csv"
});
var temp_link = document.createElement('a');
temp_link.download = "rankings.csv";
var url = window.URL.createObjectURL(CSVFile);
temp_link.href = url;
temp_link.style.display = "none";
document.body.appendChild(temp_link);
temp_link.click();
document.body.removeChild(temp_link);
}
$('#downloadTable').on('click', function() {
downloadTable();
});
$(document).ready(function() {
loadMatchData();
loadPitData();
loadTeamList();
loadRankingData();
loadStrikeData();
});
</script>
</html>