-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfoldySheetUpdate.js
509 lines (424 loc) · 25.9 KB
/
foldySheetUpdate.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
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
function foldySheet() {
var foldyURL = "https://docs.google.com/spreadsheets/d/1ZDcmwqvkcCdEvAhpJp9iD73x6uI0CF4-plzTc54oN84/";
var primASheet = SpreadsheetApp.openByUrl(foldyURL).getSheetByName("Groups");
var chancesFullV = primASheet.getRange(11, 2, primASheet.getLastRow()-10, primASheet.getLastColumn()-3).getValues();
var chancesFullC = primASheet.getRange(11, 2, primASheet.getLastRow()-10, primASheet.getLastColumn()-3).getBackgroundObjects();
var last_col = primASheet.getLastColumn();
var current_standings = primASheet.getRange("F2:G9").getValues();
for (var i in chancesFullC) {
for (var j in chancesFullC[i]) {
if (chancesFullC[i][j].asRgbColor().asHexString() === "#00ff00") { // Win
chancesFullV[i][j] = chancesFullV[i][j] + "|W"
} else {
chancesFullV[i][j] = chancesFullV[i][j] + "|L"
}
}
var currentChanceV = chancesFullV[i];
for (var m = 0; m < current_standings.length; m++) {
var current_wl = current_standings[m][1].split("-");
for (var b = 0; b < current_wl[0]; b++) {
currentChanceV.push(current_standings[m][0] + "|W");
}
for (var b = 0; b < current_wl[1]; b++) {
currentChanceV.push(current_standings[m][0] + "|L");
}
}
var teamWL_f = getTeamWLCounterArray(currentChanceV);
teamWL_f = getTeamWLSortedArray(teamWL_f);
var outputCell = parseInt(i)+11;
var team1 = teamWL_f[0].split("|");
var team2 = teamWL_f[1].split("|");
var team3 = teamWL_f[2].split("|");
var team4 = teamWL_f[3].split("|");
var team5 = teamWL_f[4].split("|");
var team6 = teamWL_f[5].split("|");
var team7 = teamWL_f[6].split("|");
var team8 = teamWL_f[7].split("|");
if (team1[0] === team2[0] && team2[0] === team3[0] && team3[0] === team4[0] && team4[0] === team5[0] && team5[0] === team6[0] && team6[0] === team7[0] && team7[0] === team8[0]) {
// 8 TIED
primASheet.getRange(outputCell, last_col, 1, 8).setBackground("#B7B7B7");
} else if (team1[0] === team2[0] && team2[0] === team3[0] && team3[0] === team4[0] && team4[0] === team5[0] && team5[0] != team6[0]){
// FIRST 5 TIED ; LAST 3 OUT
primASheet.getRange(outputCell, last_col, 1, 5).setBackground("#B7B7B7");
primASheet.getRange(outputCell, last_col+5, 1, 3).setBackground("#ff0000");
} else if (team2[0] === team3[0] && team3[0] === team4[0] && team4[0] === team5[0] && team5[0] != team6[0]){
// FIRST 1 IN ; 2-5 TIED ; LAST 3 OUT
primASheet.getRange(outputCell, last_col, 1, 1).setBackground("#00ff00");
primASheet.getRange(outputCell, last_col+1, 1, 4).setBackground("#B7B7B7");
primASheet.getRange(outputCell, last_col+5, 1, 3).setBackground("#ff0000");
} else if (team2[0] === team3[0] && team3[0] === team4[0] && team4[0] === team5[0] && team5[0] === team6[0] && team6[0] === team7[0] && team7[0] === team8[0]){
// FIRST 1 IN ; LAST 7 TIED
primASheet.getRange(outputCell, last_col).setBackground("#00ff00");
primASheet.getRange(outputCell, last_col+1, 1, 7).setBackground("#B7B7B7");
} else if (team3[0] === team4[0] && team4[0] === team5[0] && team5[0] === team6[0] && team6[0] === team7[0] && team7[0] === team8[0]){
// FIRST 2 IN ; LAST 6 TIED
primASheet.getRange(outputCell, last_col, 1, 2).setBackground("#00ff00");
primASheet.getRange(outputCell, last_col+2, 1, 6).setBackground("#B7B7B7");
} else if (team3[0] === team4[0] && team4[0] === team5[0] && team5[0] != team6[0]){
// FIRST 2 IN ; 3-5 TIED ; 6-8 OUT
primASheet.getRange(outputCell, last_col, 1, 2).setBackground("#00ff00");
primASheet.getRange(outputCell, last_col+2, 1, 3).setBackground("#B7B7B7");
primASheet.getRange(outputCell, last_col+5, 1, 3).setBackground("#ff0000");
}
else if (team4[0] === team5[0] && team5[0] === team6[0] && team6[0] === team7[0] && team7[0] === team8[0]){
// FIRST 3 IN ; LAST 5 TIED
primASheet.getRange(outputCell, last_col, 1, 3).setBackground("#00ff00");
primASheet.getRange(outputCell, last_col+3, 1, 5).setBackground("#B7B7B7");
} else if (team4[0] === team5[0] && team5[0] === team6[0] && team6[0] != team7[0]){
// FIRST 3 IN ; LAST 4-6 TIED ; 7-8 OUT
primASheet.getRange(outputCell, last_col, 1, 3).setBackground("#00ff00");
primASheet.getRange(outputCell, last_col+3, 1, 3).setBackground("#B7B7B7");
primASheet.getRange(outputCell, last_col+6, 1, 2).setBackground("#ff0000");
} else if (team4[0] === team5[0] && team5[0] === team6[0] && team6[0] === team7[0] && team7[0] != team8[0]){
// FIRST 3 IN ; LAST 4-7 TIED ; 8 OUT
primASheet.getRange(outputCell, last_col, 1, 3).setBackground("#00ff00");
primASheet.getRange(outputCell, last_col+3, 1, 4).setBackground("#B7B7B7");
primASheet.getRange(outputCell, last_col+7, 1, 1).setBackground("#ff0000");
}
else if (team4[0] === team5[0] && team5[0] === team6[0] && team6[0] === team7[0]){
// TEAM 4 - TEAM 7 TIED
primASheet.getRange(outputCell, last_col, 1, 3).setBackground("#00ff00");
primASheet.getRange(outputCell, last_col+4, 1, 3).setBackground("#B7B7B7");
primASheet.getRange(outputCell, last_col+8, 1, 1).setBackground("#ff0000");
} else if (team4[0] === team5[0] && team5[0] === team6[0]){
// TEAM 4 - TEAM 6 TIED
primASheet.getRange(outputCell, last_col, 1, 3).setBackground("#00ff00");
primASheet.getRange(outputCell, last_col+4, 1, 2).setBackground("#B7B7B7");
primASheet.getRange(outputCell, last_col+7, 1, 2).setBackground("#ff0000");
} else if (team4[0] === team5[0]){
// TEAM 4 - TEAM 5 TIED
primASheet.getRange(outputCell, last_col, 1, 3).setBackground("#00ff00");
primASheet.getRange(outputCell, last_col+3, 1, 2).setBackground("#B7B7B7");
primASheet.getRange(outputCell, last_col+5, 1, 3).setBackground("#ff0000");
} else {
// NONE TIED
primASheet.getRange(outputCell, last_col, 1, 4).setBackground("#00ff00");
primASheet.getRange(outputCell, last_col+4, 1, 4).setBackground("#ff0000");
}
var outputStandings = [];
var outputStandings2 = [];
for (var b = 0; b < teamWL_f.length; b++) {
var bSPLIT = teamWL_f[b].split("|");
var bOUTPUT = bSPLIT[0] + "-" + bSPLIT[1] + " | " + bSPLIT[2];
outputStandings.push(bOUTPUT);
}
outputStandings2.push(outputStandings);
primASheet.getRange("M"+outputCell+":T"+outputCell).setValues(outputStandings2);
}
var percentFullV = primASheet.getRange(11, last_col, primASheet.getLastRow()-10, 8).getValues();
var percentFullC = primASheet.getRange(11, last_col, primASheet.getLastRow()-10, 8).getBackgroundObjects();
var fullCounter = [];
for (var i in percentFullC) {
for (var j in percentFullC[i]) {
var percentSPLIT = percentFullV[i][j].split(" | ")
if (percentFullC[i][j].asRgbColor().asHexString() === "#00ff00") { // Win
fullCounter.push(percentSPLIT[1] + "|W")
} else if (percentFullC[i][j].asRgbColor().asHexString() === "#ff0000") { // Loss
fullCounter.push(percentSPLIT[1] + "|L")
} else { // Tie
fullCounter.push(percentSPLIT[1] + "|T")
}
}
}
fullCounter.sort();
var counterAfter = getTeamWLCounterArrayTies(fullCounter);
var counterAfter2 = getTeamWLSortedArrayTies(counterAfter);
var counterOUTPUT2 = [];
for (var i in counterAfter2) {
var counterSPLIT = counterAfter2[i].split("|");
var divider =32;
var outputWINS = ((parseInt(counterSPLIT[0])/divider)*100).toFixed(2) + "%";
var outputLOSSES = ((parseInt(counterSPLIT[1])/divider)*100).toFixed(2)+ "%";
var outputTIES = ((parseInt(counterSPLIT[2])/divider)*100).toFixed(2)+ "%";
var counterOUTPUT = [counterSPLIT[3], outputWINS, outputLOSSES, outputTIES]
counterOUTPUT2.push(counterOUTPUT);
}
primASheet.getRange("B2:E9").setValues(counterOUTPUT2);
}
// #ff0000 RED (OUT)
// #00ff00 GREEN (IN)
// #B7B7B7 GRAY (TIED)
// #696880 DARK GRAY (BYE LOCK)
// #7C6E7F MED GRAY (BYE TIE)
function foldySheetTop6() {
var foldyURL = "https://docs.google.com/spreadsheets/d/16VIMlbqwu0cbd-7UcqZNRO56zhB_DAfTA94mbiBXEWo/";
var primASheet = SpreadsheetApp.openByUrl(foldyURL).getSheetByName("Hextech [P]");
var chancesFullV = primASheet.getRange(11, 2, primASheet.getLastRow()-10, primASheet.getLastColumn()-3).getValues();
var chancesFullC = primASheet.getRange(11, 2, primASheet.getLastRow()-10, primASheet.getLastColumn()-3).getBackgroundObjects();
var last_col = primASheet.getLastColumn();
var current_standings = primASheet.getRange("H2:I9").getValues();
for (var i in chancesFullC) { // Loop through schedule
for (var j in chancesFullC[i]) { // Count future win/loss
if (chancesFullC[i][j].asRgbColor().asHexString() === "#00ff00") { // Win
chancesFullV[i][j] = chancesFullV[i][j] + "|W"
} else {
chancesFullV[i][j] = chancesFullV[i][j] + "|L"
}
}
var currentChanceV = chancesFullV[i];
for (var m = 0; m < current_standings.length; m++) { // Count past win/loss
var current_wl = current_standings[m][1].split("-");
for (var b = 0; b < current_wl[0]; b++) {
currentChanceV.push(current_standings[m][0] + "|W");
}
for (var b = 0; b < current_wl[1]; b++) {
currentChanceV.push(current_standings[m][0] + "|L");
}
}
// Count standings for this scenario
var teamWL_f = getTeamWLCounterArray(currentChanceV);
teamWL_f = getTeamWLSortedArray(teamWL_f);
var outputCell = parseInt(i)+11;
var team1 = teamWL_f[0].split("|");
var team2 = teamWL_f[1].split("|");
var team3 = teamWL_f[2].split("|");
var team4 = teamWL_f[3].split("|");
var team5 = teamWL_f[4].split("|");
var team6 = teamWL_f[5].split("|");
var team7 = teamWL_f[6].split("|");
var team8 = teamWL_f[7].split("|");
// Determine tiebreakers
if (team1[0] === team2[0] && team2[0] === team3[0] && team3[0] === team4[0] && team4[0] === team5[0] && team5[0] === team6[0] && team6[0] === team7[0] && team7[0] === team8[0]) {
// 8 TIED
primASheet.getRange(outputCell, last_col, 1, 8).setBackground("#B7B7B7");
} else if (team1[0] != team2[0] && team2[0] === team3[0] && team3[0] === team4[0] && team4[0] === team5[0] && team5[0] === team6[0] && team6[0] === team7[0] && team7[0] != team8[0]){
// 2-7 TIED
primASheet.getRange(outputCell, last_col, 1, 1).setBackground("#00ff00");
primASheet.getRange(outputCell, last_col+1, 1, 6).setBackground("#B7B7B7");
primASheet.getRange(outputCell, last_col+7, 1, 1).setBackground("#ff0000");
} else if (team1[0] != team2[0] &&team2[0] === team3[0] && team3[0] === team4[0] && team4[0] === team5[0] && team5[0] === team6[0] && team6[0] === team7[0] && team7[0] != team8[0]){
// 2-8 TIED
primASheet.getRange(outputCell, last_col, 1, 1).setBackground("#00ff00");
primASheet.getRange(outputCell, last_col+1, 1, 7).setBackground("#B7B7B7");
} else if (team2[0] != team3[0] && team3[0] === team4[0] && team4[0] === team5[0] && team5[0] === team6[0] && team6[0] === team7[0] && team7[0] != team8[0]){
// 3-7 TIED
primASheet.getRange(outputCell, last_col, 1, 2).setBackground("#00ff00");
primASheet.getRange(outputCell, last_col+2, 1, 5).setBackground("#B7B7B7");
primASheet.getRange(outputCell, last_col+7, 1, 1).setBackground("#ff0000");
} else if (team2[0] != team3[0] && team3[0] === team4[0] && team4[0] === team5[0] && team5[0] === team6[0] && team6[0] === team7[0] && team7[0] === team8[0]){
// 3-8 TIED
primASheet.getRange(outputCell, last_col, 1, 2).setBackground("#00ff00");
primASheet.getRange(outputCell, last_col+2, 1, 6).setBackground("#B7B7B7");
} else if (team3[0] != team4[0] && team4[0] === team5[0] && team5[0] === team6[0] && team6[0] === team7[0] && team7[0] != team8[0]){
// 4-7 TIED
primASheet.getRange(outputCell, last_col, 1, 3).setBackground("#00ff00");
primASheet.getRange(outputCell, last_col+3, 1, 4).setBackground("#B7B7B7");
primASheet.getRange(outputCell, last_col+7, 1, 1).setBackground("#ff0000");
} else if (team3[0] != team4[0] && team4[0] === team5[0] && team5[0] === team6[0] && team6[0] === team7[0] && team7[0] === team8[0]){
// 4-8 TIED
primASheet.getRange(outputCell, last_col, 1, 3).setBackground("#00ff00");
primASheet.getRange(outputCell, last_col+3, 1, 5).setBackground("#B7B7B7");
} else if (team4[0] != team5[0] && team5[0] === team6[0] && team6[0] === team7[0] && team7[0] != team8[0]){
// 5-7 TIED
primASheet.getRange(outputCell, last_col, 1, 4).setBackground("#00ff00");
primASheet.getRange(outputCell, last_col+4, 1, 3).setBackground("#B7B7B7");
primASheet.getRange(outputCell, last_col+7, 1, 1).setBackground("#ff0000");
} else if (team4[0] != team5[0] && team5[0] === team6[0] && team6[0] === team7[0] && team7[0] === team8[0]){
// 5-8 TIED
primASheet.getRange(outputCell, last_col, 1, 4).setBackground("#00ff00");
primASheet.getRange(outputCell, last_col+4, 1, 4).setBackground("#B7B7B7");
} else if (team5[0] != team6[0] && team6[0] === team7[0] && team7[0] != team8[0]){
// 6-7 TIED
primASheet.getRange(outputCell, last_col, 1, 5).setBackground("#00ff00");
primASheet.getRange(outputCell, last_col+5, 1, 2).setBackground("#B7B7B7");
primASheet.getRange(outputCell, last_col+7, 1, 1).setBackground("#ff0000");
} else if (team5[0] != team6[0] && team6[0] === team7[0] && team7[0] === team8[0]){
// 6-8 TIED
primASheet.getRange(outputCell, last_col, 1, 5).setBackground("#00ff00");
primASheet.getRange(outputCell, last_col+5, 1, 3).setBackground("#B7B7B7");
} else {
// NONE TIED
primASheet.getRange(outputCell, last_col, 1, 6).setBackground("#00ff00");
primASheet.getRange(outputCell, last_col+6, 1, 2).setBackground("#ff0000");
}
if (team2[0] != team3[0]){
// BYE LOCK
primASheet.getRange(outputCell, last_col, 1, 2).setBackground("#696880");
} else if (team1[0] === team2[0] && team2[0] === team3[0]){
// BYE TIE 1-3
primASheet.getRange(outputCell, last_col, 1, 3).setBackground("#7C6E7F");
} else if (team2[0] === team3[0] && team3[0] != team4[0]){
// BYE TIE 2-3
primASheet.getRange(outputCell, last_col, 1, 1).setBackground("#696880");
primASheet.getRange(outputCell, last_col+1, 1, 2).setBackground("#7C6E7F");
} else if (team1[0] === team2[0] && team2[0] === team3[0] && team3[0] === team4[0] && team4[0] != team5[0]){
// BYE TIE 1-4
primASheet.getRange(outputCell, last_col, 1, 4).setBackground("#7C6E7F");
} else if (team1[0] != team2[0] && team2[0] === team3[0] && team3[0] === team4[0] && team4[0] != team5[0]){
// BYE TIE 2-4
primASheet.getRange(outputCell, last_col, 1, 1).setBackground("#696880");
primASheet.getRange(outputCell, last_col+1, 1, 3).setBackground("#7C6E7F");
} else if (team1[0] === team2[0] && team2[0] === team3[0] && team3[0] === team4[0] && team4[0] === team5[0] && team5[0] != team6[0]){
// BYE TIE 1-5
primASheet.getRange(outputCell, last_col, 1, 5).setBackground("#7C6E7F");
} else if (team1[0] != team2[0] && team2[0] === team3[0] && team3[0] === team4[0] && team4[0] === team5[0] && team5[0] != team6[0]){
// BYE TIE 2-5
primASheet.getRange(outputCell, last_col, 1, 1).setBackground("#696880");
primASheet.getRange(outputCell, last_col+1, 1, 4).setBackground("#7C6E7F");
} else if (team1[0] === team2[0] && team2[0] === team3[0] && team3[0] === team4[0] && team4[0] === team5[0] && team5[0] === team6[0] && team6[0] != team7[0]){
// BYE TIE 1-6
primASheet.getRange(outputCell, last_col, 1, 6).setBackground("#7C6E7F");
} else if (team1[0] != team2[0] && team2[0] === team3[0] && team3[0] === team4[0] && team4[0] === team5[0] && team5[0] === team6[0] && team6[0] != team7[0]){
// BYE TIE 2-6
primASheet.getRange(outputCell, last_col, 1, 1).setBackground("#696880");
primASheet.getRange(outputCell, last_col+1, 1, 5).setBackground("#7C6E7F");
}
var outputStandings = [];
var outputStandings2 = [];
for (var b = 0; b < teamWL_f.length; b++) {
var bSPLIT = teamWL_f[b].split("|");
var bOUTPUT = bSPLIT[0] + "-" + bSPLIT[1] + " | " + bSPLIT[2];
outputStandings.push(bOUTPUT);
}
outputStandings2.push(outputStandings);
primASheet.getRange("K"+outputCell+":R"+outputCell).setValues(outputStandings2);
}
var percentFullV = primASheet.getRange(11, last_col-7, primASheet.getLastRow()-10, 8).getValues();
var percentFullC = primASheet.getRange(11, last_col-7, primASheet.getLastRow()-10, 8).getBackgroundObjects();
var fullCounter = [];
for (var i in percentFullC) { // Count total win/loss/tie
for (var j in percentFullC[i]) {
var percentSPLIT = percentFullV[i][j].split(" | ")
if (percentFullC[i][j].asRgbColor().asHexString() === "#00ff00") { // Win
fullCounter.push(percentSPLIT[1] + "|W")
} else if (percentFullC[i][j].asRgbColor().asHexString() === "#ff0000") { // Loss
fullCounter.push(percentSPLIT[1] + "|L")
} else if (percentFullC[i][j].asRgbColor().asHexString() === "#696880") { // Bye Lock
fullCounter.push(percentSPLIT[1] + "|BL")
} else if (percentFullC[i][j].asRgbColor().asHexString() === "#7C6E7F") { // Bye Tie
fullCounter.push(percentSPLIT[1] + "|BT")
} else { // Tie
fullCounter.push(percentSPLIT[1] + "|T")
}
}
}
fullCounter.sort();
var counterAfter = getTeamWLCounterArrayTies(fullCounter);
var counterAfter2 = getTeamWLSortedArrayTies(counterAfter);
var counterOUTPUT2 = [];
for (var i in counterAfter2) { // Create output array
var counterSPLIT = counterAfter2[i].split("|");
var divider = 8;
var outputWINS = ((parseInt(counterSPLIT[0])/divider)*100).toFixed(2) + "%";
var outputLOSSES = ((parseInt(counterSPLIT[1])/divider)*100).toFixed(2)+ "%";
var outputTIES = ((parseInt(counterSPLIT[2])/divider)*100).toFixed(2)+ "%";
var outputBL = ((parseInt(counterSPLIT[0])/divider)*100).toFixed(2)+ "%";
var outputBT = ((parseInt(counterSPLIT[2])/divider)*100).toFixed(2)+ "%";
var counterOUTPUT = [counterSPLIT[3], outputWINS, outputLOSSES, outputTIES]
counterOUTPUT2.push(counterOUTPUT);
}
primASheet.getRange("B2:E9").setValues(counterOUTPUT2);
}
function foldySheet6Teams() {
var foldyURL = "https://docs.google.com/spreadsheets/d/1Vyyb82C4fKa0V97OPMbf-JOssIUXY00jyoJlckeHsp0/";
var primASheet = SpreadsheetApp.openByUrl(foldyURL).getSheetByName("VRD");
var chancesFullV = primASheet.getRange(9, 2, primASheet.getLastRow()-8, primASheet.getLastColumn()-3).getValues();
var chancesFullC = primASheet.getRange(9, 2, primASheet.getLastRow()-8, primASheet.getLastColumn()-3).getBackgroundObjects();
var last_col = primASheet.getLastColumn();
var current_standings = primASheet.getRange("F2:G7").getValues();
for (var i in chancesFullC) {
for (var j in chancesFullC[i]) {
if (chancesFullC[i][j].asRgbColor().asHexString() === "#00ff00") { // Win
chancesFullV[i][j] = chancesFullV[i][j] + "|W"
} else {
chancesFullV[i][j] = chancesFullV[i][j] + "|L"
}
}
var currentChanceV = chancesFullV[i];
for (var m = 0; m < current_standings.length; m++) {
var current_wl = current_standings[m][1].split("-");
for (var b = 0; b < current_wl[0]; b++) {
currentChanceV.push(current_standings[m][0] + "|W");
}
for (var b = 0; b < current_wl[1]; b++) {
currentChanceV.push(current_standings[m][0] + "|L");
}
}
var teamWL_f = getTeamWLCounterArray(currentChanceV);
teamWL_f = getTeamWLSortedArray(teamWL_f);
var outputCell = parseInt(i)+9;
var team1 = teamWL_f[0].split("|");
var team2 = teamWL_f[1].split("|");
var team3 = teamWL_f[2].split("|");
var team4 = teamWL_f[3].split("|");
var team5 = teamWL_f[4].split("|");
var team6 = teamWL_f[5].split("|");
if (team1[0] === team2[0] && team2[0] === team3[0] && team3[0] === team4[0] && team4[0] === team5[0] && team5[0] === team6[0]) {
// 1-6 TIED
primASheet.getRange(outputCell, last_col, 1, 6).setBackground("#B7B7B7");
} else if (team1[0] === team2[0] && team2[0] === team3[0] && team3[0] === team4[0] && team4[0] === team5[0] && team5[0] != team6[0]){
// 1-5 TIED ; 6 OUT
primASheet.getRange(outputCell, last_col, 1, 5).setBackground("#B7B7B7");
primASheet.getRange(outputCell, last_col+5, 1, 1).setBackground("#ff0000");
} else if (team1[0] != team2[0] && team2[0] === team3[0] && team3[0] === team4[0] && team4[0] === team5[0] && team5[0] != team6[0]){
// 1 IN ; 2-5 TIED ; 6 OUT
primASheet.getRange(outputCell, last_col, 1, 1).setBackground("#00ff00");
primASheet.getRange(outputCell, last_col+1, 1, 4).setBackground("#B7B7B7");
primASheet.getRange(outputCell, last_col+5, 1, 1).setBackground("#ff0000");
} else if (team1[0] != team2[0] && team2[0] === team3[0] && team3[0] === team4[0] && team4[0] === team5[0] && team5[0] === team6[0]){
// 1 IN ; 2-6 TIED
primASheet.getRange(outputCell, last_col).setBackground("#00ff00");
primASheet.getRange(outputCell, last_col+1, 1, 5).setBackground("#B7B7B7");
} else if (team2[0] != team3[0] && team3[0] === team4[0] && team4[0] === team5[0] && team5[0] === team6[0]){
// 1-2 IN ; 3-6 TIED
primASheet.getRange(outputCell, last_col, 1, 2).setBackground("#00ff00");
primASheet.getRange(outputCell, last_col+2, 1, 4).setBackground("#B7B7B7");
} else if (team2[0] != team3[0] && team3[0] === team4[0] && team4[0] === team5[0] && team5[0] != team6[0]){
// 1-2 IN ; 3-5 TIED ; 6 OUT
primASheet.getRange(outputCell, last_col, 1, 2).setBackground("#00ff00");
primASheet.getRange(outputCell, last_col+2, 1, 3).setBackground("#B7B7B7");
primASheet.getRange(outputCell, last_col+5, 1, 1).setBackground("#ff0000");
} else if (team3[0] != team4[0] && team4[0] === team5[0] && team5[0] === team6[0]){
// 1-3 IN ; 4-6 TIED
primASheet.getRange(outputCell, last_col, 1, 3).setBackground("#00ff00");
primASheet.getRange(outputCell, last_col+3, 1, 3).setBackground("#B7B7B7");
} else if (team3[0] != team4[0] && team4[0] === team5[0] && team5[0] != team6[0]){
// 1-3 IN ; 4-5 TIED ; 6 OUT
primASheet.getRange(outputCell, last_col, 1, 3).setBackground("#00ff00");
primASheet.getRange(outputCell, last_col+3, 1, 2).setBackground("#B7B7B7");
primASheet.getRange(outputCell, last_col+5, 1, 1).setBackground("#ff0000");
} else {
// NONE TIED
primASheet.getRange(outputCell, last_col, 1, 4).setBackground("#00ff00");
primASheet.getRange(outputCell, last_col+4, 1, 2).setBackground("#ff0000");
}
var outputStandings = [];
var outputStandings2 = [];
for (var b = 0; b < teamWL_f.length; b++) {
var bSPLIT = teamWL_f[b].split("|");
var bOUTPUT = bSPLIT[0] + "-" + bSPLIT[1] + " | " + bSPLIT[2];
outputStandings.push(bOUTPUT);
}
outputStandings2.push(outputStandings);
primASheet.getRange("I"+outputCell+":N"+outputCell).setValues(outputStandings2);
}
var percentFullV = primASheet.getRange(9, last_col, primASheet.getLastRow()-8, 6).getValues();
var percentFullC = primASheet.getRange(9, last_col, primASheet.getLastRow()-8, 6).getBackgroundObjects();
var fullCounter = [];
for (var i in percentFullC) {
for (var j in percentFullC[i]) {
var percentSPLIT = percentFullV[i][j].split(" | ")
if (percentFullC[i][j].asRgbColor().asHexString() === "#00ff00") { // Win
fullCounter.push(percentSPLIT[1] + "|W")
} else if (percentFullC[i][j].asRgbColor().asHexString() === "#ff0000") { // Loss
fullCounter.push(percentSPLIT[1] + "|L")
} else { // Tie
fullCounter.push(percentSPLIT[1] + "|T")
}
}
}
fullCounter.sort();
var counterAfter = getTeamWLCounterArrayTies(fullCounter);
var counterAfter2 = getTeamWLSortedArrayTies(counterAfter);
var counterOUTPUT2 = [];
for (var i in counterAfter2) {
var counterSPLIT = counterAfter2[i].split("|");
var divider = 8;
var outputWINS = ((parseInt(counterSPLIT[0])/divider)*100).toFixed(2) + "%";
var outputLOSSES = ((parseInt(counterSPLIT[1])/divider)*100).toFixed(2)+ "%";
var outputTIES = ((parseInt(counterSPLIT[2])/divider)*100).toFixed(2)+ "%";
var counterOUTPUT = [counterSPLIT[3], outputWINS, outputLOSSES, outputTIES]
counterOUTPUT2.push(counterOUTPUT);
}
primASheet.getRange("B2:E7").setValues(counterOUTPUT2);
}