-
Notifications
You must be signed in to change notification settings - Fork 0
/
tournamentStatsFunctions.js
1479 lines (1251 loc) · 51.4 KB
/
tournamentStatsFunctions.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
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
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Make an api call to Riot server \\
function api_call(url) {
var url2 = url;
var options = {'method':'get', 'muteHttpExceptions': true};
var response = UrlFetchApp.fetch(url2, options);
if (response.getResponseCode() === 200) {
return JSON.parse(response.getContentText());
} else if (response.getResponseCode() === 429 || response.getResponseCode() === 504) {
while (response.getResponseCode() === 429 || response.getResponseCode() === 504) {
var responseHeader = response.getHeaders();
var timeoutFor = 0 + (responseHeader['Retry-After']);
Utilities.sleep((timeoutFor*1000));
var response = UrlFetchApp.fetch(url, options);
if (response.getResponseCode() === 200) {
return JSON.parse(response.getContentText());
} else if (response.getResponseCode() != 429 && response.getResponseCode() != 504){
console.log("In Loop Error: " + response.getResponseCode());
return "Error";
}
}
} else {
console.log ("Out of Loop Error: " + response.getResponseCode());
return "Error";
}
}
// Custom Menu
function onOpen(){
SpreadsheetApp.getUi()
.createMenu("Cam's Custom Codes")
.addItem('Post Game','createPostGame')
.addToUi();
}
// Returns champ name from champ id \\
function champ_names(champ_id, champ_api_list_fulli) {
var champ_api_list_full = champ_api_list_fulli
var champ_api_list_simple = Object.entries(champ_api_list_full.data);
var champID = champ_id;
var champs_array = [];
var small_array = ["", ""];
for (var i = 0; i < champ_api_list_simple.length; i++) {
small_array[0] = champ_api_list_simple[i][1]["key"];
if (champ_api_list_simple[i][1]["id"] === "MonkeyKing") {
small_array[1] = "Wukong";
} else {
small_array[1] = champ_api_list_simple[i][1]["id"];
}
champs_array.push(small_array);
small_array = ["", ""];
}
for (var i = 0; i < champs_array.length; i++) {
if (champs_array[i][0].toString() === champID.toString()) return champs_array[i][1];
}
return "None";
}
// Create Counting Array \\
function getCountingArray(arrayCName) {
var kills_list = arrayCName;
kills_list.sort();
var kill_list_f = [];
var current_kill = "";
var current_kill_count = 0;
var game_count = 1;
var split_kills = [];
for (var t = 0; t < kills_list.length; t++) {
split_kills = kills_list[t].split("|");
if (t === 0) {
current_kill = split_kills[0];
current_kill_count = parseFloat(split_kills[1]);
} else if (t === ((kills_list.length)-1)) {
if (split_kills[0] === current_kill) {
game_count += 1;
current_kill_count += parseFloat(split_kills[1]);
} else {
kill_list_f.push(current_kill_count + "|" + current_kill + "|" + game_count);
current_kill = split_kills[0];
game_count = 1;
}
kill_list_f.push(current_kill_count + "|" + current_kill + "|" + game_count);
} else if (split_kills[0] === current_kill) {
game_count += 1;
current_kill_count += parseFloat(split_kills[1]);
} else {
kill_list_f.push(current_kill_count + "|" + current_kill + "|" + game_count);
current_kill = split_kills[0];
current_kill_count = parseFloat(split_kills[1]);
game_count = 1;
}
}
kill_list_f.sort();
kill_list_f.reverse();
return kill_list_f;
}
// Create Team Pick/Ban Counting Array \\
function getPBCountingArray(arrayPBName) {
var pb_list = arrayPBName;
pb_list.sort();
var pb_list_f = [];
var current_team = "";
var current_pb = "";
var current_pb_count = 1;
var split_pb = [];
for (var i = 0; i < pb_list.length; i++) {
split_pb = pb_list[i].split("|");
if (i === 0) { // First entry
current_team = split_pb[0];
current_pb = split_pb[1];
} else if (i === ((pb_list.length)-1)) { // Last entry
if (split_pb[0] === current_team) { // Same team
if (split_pb[1] === current_pb) { // Same champ
current_pb_count += 1;
pb_list_f.push(current_team + "|" + current_pb_count + "|" + current_pb);
} else { // Diff champ
pb_list_f.push(current_team + "|" + current_pb_count + "|" + current_pb);
current_pb = split_pb[1];
current_pb_count = 1;
pb_list_f.push(current_team + "|" + current_pb_count + "|" + current_pb);
}
} else { // Diff team
pb_list_f.push(current_team + "|" + current_pb_count + "|" + current_pb);
current_team = split_pb[0]
current_pb = split_pb[1];
current_pb_count = 1;
pb_list_f.push(current_team + "|" + current_pb_count + "|" + current_pb);
}
} else if (split_pb[0] === current_team) { // Same team
if (split_pb[1] === current_pb) { // Same champ
current_pb_count += 1;
} else { // Diff champ
pb_list_f.push(current_team + "|" + current_pb_count + "|" + current_pb);
current_pb = split_pb[1];
current_pb_count = 1;
}
} else { // Diff team
pb_list_f.push(current_team + "|" + current_pb_count + "|" + current_pb);
current_team = split_pb[0];
current_team_count = 1;
current_pb = split_pb[1];
current_pb_count = 1;
}
}
pb_list_f.sort();
pb_list_f.reverse();
return pb_list_f;
}
// Create Ban List Counting Array \\
function getBanCountingArray(arrayBName) {
var fb_list = arrayBName;
var fb_list_f = [];
fb_list.sort();
var fb_counter = 1;
var fb_list_f = []
var current_fb = "";
for (var t = 0; t < fb_list.length; t++) {
if (t === 0) { // First
current_fb = fb_list[0];
} else if (t === ((fb_list.length)-1)) { // Last
if (fb_list[t] === current_fb) {
fb_counter += 1;
} else {
fb_list_f.push(fb_counter + "|" + current_fb);
current_fb = fb_list[t];
fb_counter = 1;
}
fb_list_f.push(fb_counter + "|" + current_fb);
} else if (fb_list[t] === current_fb) { // Same
fb_counter += 1;
} else { // Different
fb_list_f.push(fb_counter + "|" + current_fb);
current_fb = fb_list[t];
fb_counter = 1;
}
}
fb_list_f.sort();
fb_list_f.reverse();
// Ban FINAL ARRAY SORTER
fb_list_f.sort(function(a,b){
if(parseFloat(a.split("|")[0]) === parseFloat(b.split("|")[0])) {
return parseFloat(b.split("|")[0]) - parseFloat(a.split("|")[0]);
} else if(parseFloat(a.split("|")[0]) > parseFloat(b.split("|")[0])) {
return -1;
}
return 1;
});
return fb_list_f;
}
// Create Team Series Score and Points Array \\
function createTeamPointsArray(arrayINPUT) {
var series_array = arrayINPUT;
var split_array = "";
var output_array = [];
var current_team = "";
var current_wins = 0;
var current_losses = 0;
var current_points = 0;
var total_wins = 0;
var total_losses = 0;
for (var t = 0; t < series_array.length; t++) {
split_array = series_array[t].split("|")
if (t === 0) { // First
current_team = split_array[0];
total_wins = parseInt(split_array[1])
total_losses = parseInt(split_array[2])
if (split_array[1] > split_array[2]) {
current_wins = 1;
current_losses = 0;
} else {
current_wins = 0;
current_losses = 1;
}
if (split_array[1] === "2" && split_array[2] === "0") {
current_points = 6;
} else if (split_array[1] === "2" && split_array[2] === "1") {
current_points = 5;
} else if (split_array[1] === "1" && split_array[2] === "2") {
current_points = 3;
} else if (split_array[1] === "0" && split_array[2] === "2") {
current_points = 2;
} else if (split_array[2] === "1" && split_array[3] === "1") {
current_points = 1;
} else if (split_array[2] === "0" && split_array[3] === "2") {
current_points = 0;
}
} else if (t === ((series_array.length)-1)) { // Last
if (split_array[0] === current_team) { // Same team
total_wins += parseInt(split_array[1])
total_losses += parseInt(split_array[2])
if (split_array[1] > split_array[2]) {
current_wins += 1;
} else {
current_losses += 1;
}
if (split_array[1] === "2" && split_array[2] === "0") {
current_points += 6;
} else if (split_array[1] === "2" && split_array[2] === "1") {
current_points += 5;
} else if (split_array[1] === "1" && split_array[2] === "2") {
current_points += 3;
} else if (split_array[1] === "0" && split_array[2] === "2") {
current_points += 2;
} else if (split_array[2] === "1" && split_array[3] === "1") {
current_points += 1;
} else if (split_array[2] === "0" && split_array[3] === "2") {
current_points += 0;
}
} else { // Diff team
output_array.push(current_team + "|" + current_wins + "-" + current_losses + "|" + current_points + "|" + total_wins + "-" + total_losses);
current_team = split_array[0];
total_wins = parseInt(split_array[1])
total_losses = parseInt(split_array[2])
if (split_array[1] > split_array[2]) {
current_wins = 1;
current_losses = 0;
} else {
current_wins = 0;
current_losses = 1;
}
if (split_array[1] === "2" && split_array[2] === "0") {
current_points = 6;
} else if (split_array[1] === "2" && split_array[2] === "1") {
current_points = 5;
} else if (split_array[1] === "1" && split_array[2] === "2") {
current_points = 3;
} else if (split_array[1] === "0" && split_array[2] === "2") {
current_points = 2;
} else if (split_array[2] === "1" && split_array[3] === "1") {
current_points = 1;
} else if (split_array[2] === "0" && split_array[3] === "2") {
current_points = 0;
}
}
output_array.push(current_team + "|" + current_wins + "-" + current_losses + "|" + current_points + "|" + total_wins + "-" + total_losses);
} else if (split_array[0] === current_team) { // Same team
total_wins += parseInt(split_array[1])
total_losses += parseInt(split_array[2])
if (split_array[1] > split_array[2]) {
current_wins += 1;
} else {
current_losses += 1;
}
if (split_array[1] === "2" && split_array[2] === "0") {
current_points += 6;
} else if (split_array[1] === "2" && split_array[2] === "1") {
current_points += 5;
} else if (split_array[1] === "1" && split_array[2] === "2") {
current_points += 3;
} else if (split_array[1] === "0" && split_array[2] === "2") {
current_points += 2;
} else if (split_array[2] === "1" && split_array[3] === "1") {
current_points += 1;
} else if (split_array[2] === "0" && split_array[3] === "2") {
current_points += 0;
}
} else { // Diff team
output_array.push(current_team + "|" + current_wins + "-" + current_losses + "|" + current_points + "|" + total_wins + "-" + total_losses);
current_team = split_array[0];
total_wins = parseInt(split_array[1])
total_losses = parseInt(split_array[2])
if (split_array[1] > split_array[2]) {
current_wins = 1;
current_losses = 0;
} else {
current_wins = 0;
current_losses = 1;
}
if (split_array[1] === "2" && split_array[2] === "0") {
current_points = 6;
} else if (split_array[1] === "2" && split_array[2] === "1") {
current_points = 5;
} else if (split_array[1] === "1" && split_array[2] === "2") {
current_points = 3;
} else if (split_array[1] === "0" && split_array[2] === "2") {
current_points = 2;
} else if (split_array[2] === "1" && split_array[3] === "1") {
current_points = 1;
} else if (split_array[2] === "0" && split_array[3] === "2") {
current_points = 0;
}
}
}
output_array.sort();
// Ban FINAL ARRAY SORTER
output_array.sort(function(a,b){
if(parseFloat(a.split("|")[1]) === parseFloat(b.split("|")[1])) {
return parseFloat(b.split("|")[2]) - parseFloat(a.split("|")[2]);
} else if(parseFloat(a.split("|")[1]) > parseFloat(b.split("|")[1])) {
return -1;
}
return 1;
});
return output_array;
}
// Create Sorted Array \\
function getSortedArray(arraySName) {
var kill_list_f = arraySName;
var outputLIST = [];
// KILL FINAL ARRAY MAKER
for (var i = 0; i < kill_list_f.length; i++) {
var kills_split2 = kill_list_f[i].split("|");
var avg_kills = (parseFloat(kills_split2[0])/parseFloat(kills_split2[2])).toFixed(2);
outputLIST.push(avg_kills + "|" + kills_split2[1] + "|" + kills_split2[2]);
}
// KILL FINAL ARRAY SORTER
outputLIST.sort(function(a,b){
if(parseFloat(a.split("|")[0]) === parseFloat(b.split("|")[0])) {
return parseFloat(b.split("|")[2]) - parseFloat(a.split("|")[2]);
} else if (parseFloat(a.split("|")[0]) > parseFloat(b.split("|")[0])) {
return -1;
}
return 1;
});
return outputLIST;
}
// Create Sorted Not Averages Array \\
function getSortedNAArray(arraySNAName) {
var kill_list_f = arraySNAName;
// KILL FINAL ARRAY MAKER
for (var i = 0; i < kill_list_f.length; i++) {
var kills_split2 = kill_list_f[i].split("|");
kill_list_f[i] = kills_split2[0] + "|" + kills_split2[1] + "|" + kills_split2[2];
}
// KILL FINAL ARRAY SORTER
kill_list_f.sort(function(a,b){
if(parseFloat(a.split("|")[0]) === parseFloat(b.split("|")[0])) {
return parseFloat(b.split("|")[2]) - parseFloat(a.split("|")[2]);
} else if(parseFloat(a.split("|")[0]) > parseFloat(b.split("|")[0])) {
return -1;
}
return 1;
});
return kill_list_f;
}
// Create Sorted Team Pick/Ban Array \\
function getSortedTPBArray(arraySTPBName, user_input) {
var pb_list_f = arraySTPBName;
if (user_input === "PLAT") {
var outputF = [[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]];
} else if (user_input === "GOLD") {
var outputF = [[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]];
} else if (user_input === "DIA") {
var outputF = [[],[],[],[],[],[],[],[]];
}
var current_team = "";
var team_count = 0;
// PB FINAL ARRAY MAKER
for (var i = 0; i < pb_list_f.length; i++) {
var pb_split = pb_list_f[i].split("|");
if (i === 0) {
current_team = pb_split[0];
outputF[team_count].push(current_team);
outputF[team_count].push(pb_split[2] + "|" + pb_split[1]);
} else if (pb_split[0] === current_team) {
outputF[team_count].push(pb_split[2] + "|" + pb_split[1]);
} else {
current_team = pb_split[0];
team_count += 1;
outputF[team_count].push(current_team);
outputF[team_count].push(pb_split[2] + "|" + pb_split[1]);
}
}
return outputF;
}
// Output Team Pick/Ban Arrays \\
function createPickOutput(arrayOPName, userInput, type) {
var pick_list = arrayOPName;
var league_picked = userInput;
var pbType = type;
if (league_picked === "PLAT") var teamSheet = "https://docs.google.com/spreadsheets/d/1lQ1ObK2DR70OYYC1gUt2qkBJX24RxNBTXA01dWCiwX4/";
if (league_picked === "GOLD") var teamSheet = "https://docs.google.com/spreadsheets/d/1TkUyieTa1Ngl66gOwQTpkMi-OdZOHo68uQI6weGcXvA/";
if (league_picked === "DIA") var teamSheet = "https://docs.google.com/spreadsheets/d/1Zi4P6-oikiZ8p7DJBVIQJ22DB3e-CgNX_8djFbdpvlk/";
for (var i = 0; i < pick_list.length; i++) {
var currentTeam = SpreadsheetApp.openByUrl(teamSheet).getSheetByName(pick_list[i][0]);
var input_list = ["", ""];
var output_list = [];
var counter = 0;
for (var o = 0; o < pick_list[i].length; o++) {
var pick_list_split = pick_list[i][o].split("|");
if (counter < 6 && o != 0 && pick_list_split[0] != "NO BAN") {
counter += 1;
input_list[0] = pick_list_split[0];
input_list[1] = pick_list_split[1];
output_list.push(input_list);
input_list = ["", ""];
}
}
try {
if (pbType === "PICK") {
currentTeam.getRange("R3:S8").setValues(output_list);
} else if (pbType === "BAN") {
currentTeam.getRange("O3:P8").setValues(output_list);
}
} catch (err) {
if (pbType === "PICK") {
currentTeam.getRange("R3:S8").setValue(["Not Enough Games"]);
} else if (pbType === "BAN") {
currentTeam.getRange("O3:P8").setValue(["Not Enough Games"]);
}
}
}
}
// Create Output Array \\
function getFinalArray(arrayName) {
var kill_list_f = arrayName;
var total_games = 1;
var counter = 0;
var fkillList = [];
for (var i = 0; i < kill_list_f.length; i++) {
var kill_list_fs = kill_list_f[i].split("|");
if (parseFloat(kill_list_fs[2]) >= (total_games*.5) && counter < 10) {
kill_list_fs[1] = getSummonerName(kill_list_fs[1]);
fkillList.push(kill_list_fs);
counter++
}
}
return fkillList;
}
// Create Team Output Array \\
function getCCCFinalArray(arrayCOName, league, div) {
var kill_list_f = arrayCOName;
var counter = 0;
var fkillList = [];
if (league === "PLAT") {
if (div === "A") {
var teamList = getPlatInfernalTeams();
} else {
var teamList = getPlatHextechTeams();
}
} else if (league === "GOLD"){
if (div === "A") {
var teamList = getGoldCloudTeams();
} else if (div === "B"){
var teamList = getGoldMountainTeams();
} else {
var teamList = getGoldOceanTeams();
}
}
for (var i = 0; i < kill_list_f.length; i++) {
var kill_list_fs = kill_list_f[i].split("|");
if (counter < 10 && teamList.indexOf(kill_list_fs[2]) != -1) {
kill_list_fs.pop();
fkillList.push(kill_list_fs);
counter++
}
}
return fkillList;
}
// Create Team Stat Output Array \\
function getCCCSFinalArray(arrayCOName, league, div) {
var kill_list_f = arrayCOName;
var counter = 0;
var fkillList = [];
if (league === "PLAT") {
if (div === "A") {
var teamList = getPlatInfernalTeams();
} else {
var teamList = getPlatHextechTeams();
}
} else if (league === "GOLD"){
if (div === "A") {
var teamList = getGoldCloudTeams();
} else if (div === "B"){
var teamList = getGoldMountainTeams();
} else if (div === "C") {
var teamList = getGoldOceanTeams();
}
} else if (league === "DIA"){
var teamList = getDiaTeams();
} else if (league === "EGG"){
var teamList = getEggTeams();
} else if (league === "DUCKLING"){
var teamList = getDucklingTeams();
}
for (var i = 0; i < kill_list_f.length; i++) {
if (counter < 10 && teamList.indexOf(kill_list_f[i][0]) != -1) {
fkillList.push(kill_list_f[i]);
counter++
}
}
return fkillList;
}
// Create Champion Output Array \\
function getCFinalArray(arrayCOName, special) {
var kill_list_f = arrayCOName;
var current_special = special;
var counter = 0;
var fkillList = [];
for (var i = 0; i < kill_list_f.length; i++) {
var kill_list_fs = kill_list_f[i].split("|");
if (counter < 10 && kill_list_fs[1] != "NO BAN") {
if (current_special === "FB") kill_list_fs[1] = getSummonerName(kill_list_fs[1]);
fkillList.push(kill_list_fs);
counter++
}
}
return fkillList;
}
// Create Champ Counter Array \\
function getChampCounterArray(arrayCCName) {
var game_list = arrayCCName;
var champ_list = [];
// CHAMPS PICKED COUNTER
game_list.sort();
var count_champ = 0;
var current_champ = "";
var current_kills = 0;
var current_deaths = 0;
var current_assists = 0;
var current_losses = 0;
var current_wins = 0;
var game_count = 0;
var split_array = [];
var picked_champs = [];
for (var m = 0; m < game_list.length; m++) {
split_array = game_list[m].split("|");
split_kda = split_array[2].split("/");
if (m === 0) { // First Game
current_champ = split_array[0];
count_champ = 1;
current_kills += parseFloat(split_kda[0]);
current_deaths += parseFloat(split_kda[1]);
current_assists += parseFloat(split_kda[2]);
if (split_array[1] === "L") {
current_losses += 1;
} else {
current_wins += 1;
}
} else if (m === ((game_list.length)-1)) { // Last Game
if (split_array[0] === current_champ) {
count_champ += 1;
if (split_array[1] === "L") {
current_losses += 1;
} else {
current_wins += 1;
}
current_kills += parseFloat(split_kda[0]);
current_deaths += parseFloat(split_kda[1]);
current_assists += parseFloat(split_kda[2]);
} else {
champ_list.push(count_champ + "|" + current_champ + "|" + current_wins + "/" + current_losses + "|" + current_kills +
"/" + current_deaths + "/" + current_assists);
current_champ = split_array[0];
count_champ = 1;
current_kills = parseFloat(split_kda[0]);
current_deaths = parseFloat(split_kda[1]);
current_assists = parseFloat(split_kda[2]);
if (split_array[1] === "L") {
current_losses = 1;
current_wins = 0;
} else {
current_wins = 1;
current_losses = 0;
}
}
champ_list.push(count_champ + "|" + current_champ + "|" + current_wins + "/" + current_losses + "|" + current_kills +
"/" + current_deaths + "/" + current_assists);
} else if (split_array[0] === current_champ) { // Matching champ
count_champ += 1;
current_kills += parseFloat(split_kda[0]);
current_deaths += parseFloat(split_kda[1]);
current_assists += parseFloat(split_kda[2]);
if (split_array[1] === "L") {
current_losses += 1;
} else {
current_wins += 1;
}
} else { // Not matching champ
champ_list.push(count_champ + "|" + current_champ + "|" + current_wins + "/" + current_losses + "|" + current_kills +
"/" + current_deaths + "/" + current_assists);
current_champ = split_array[0];
count_champ = 1;
current_kills = parseFloat(split_kda[0]);
current_deaths = parseFloat(split_kda[1]);
current_assists = parseFloat(split_kda[2]);
if (split_array[1] === "L") {
current_losses = 1;
current_wins = 0;
} else {
current_wins = 1;
current_losses = 0;
}
}
}
champ_list.sort();
return champ_list;
}
// Create Sorted Champ Array \\
function getChampSortedArray(arrayCSName) {
var champ_list = arrayCSName;
var picked_champs = [];
for (var j = 0; j < champ_list.length; j++) {
var champs_split = champ_list[j].split("|");
var win_loss_split = champs_split[2].split("/");
var win_loss = Math.floor(parseFloat(win_loss_split[0])/(parseFloat(win_loss_split[0])+parseFloat(win_loss_split[1]))*100) + "% (" + win_loss_split[0] + "-" + win_loss_split[1] + ")";
champs_split[2] = win_loss;
var kda_split = champs_split[3].split("/");
var total_games = parseFloat(champs_split[0]);
var avg_kda = (parseFloat(kda_split[0])/total_games).toFixed(2) + "/" + (parseFloat(kda_split[1])/total_games).toFixed(2) + "/" + (parseFloat(kda_split[2])/total_games).toFixed(2)
champs_split[3] = avg_kda;
if (champs_split[0] === "1") {
picked_champs.push("1|" + champs_split[2] + "|" + champs_split[1] + "|" + champs_split[3]);
} else {
picked_champs.push(champs_split[0] + "|" + champs_split[2] + "|" + champs_split[1] + "|" + champs_split[3])
}
}
// CHAMP FINAL ARRAY SORTER
picked_champs.sort(function(a,b){
if(parseFloat(a.split("|")[0]) === parseFloat(b.split("|")[0])) {
return parseFloat(b.split("|")[1]) - parseFloat(a.split("|")[1]);
} else if(parseFloat(a.split("|")[0]) > parseFloat(b.split("|")[0])) {
return -1;
}
return 1;
});
return picked_champs;
}
function matchpb(picked, banned, game_num) {
var output_array = [];
for (var i = 0; i < picked.length; i++) {
var pickedC = picked[i].split("|");
for (var o = 0; o < banned.length; o++) {
var bannedC = banned[o].split("|");
if (pickedC[2] === bannedC[1]) {
var pickban = (((parseInt(pickedC[0]) + parseInt(bannedC[0]))/game_num)*100).toFixed(2)
var output = [pickban, pickedC[0], bannedC[0], pickedC[2], pickedC[1], pickedC[3]]
o = banned.length;
output_array.push(output)
}
}
}
// CHAMP FINAL ARRAY SORTER
output_array.sort(function(a,b){
if(parseFloat(a[0]) === parseFloat(b[0])) {
return parseFloat(b[1]) - parseFloat(a[1]);
} else if(parseFloat(a[0]) > parseFloat(b[0])) {
return -1;
}
return 1;
});
return output_array;
}
// Create Player Champ Counter Array \\
function getPlayerChampCounterArray(arrayCCName) {
var game_list = arrayCCName;
var champ_list = [];
// CHAMPS PICKED COUNTER
game_list.sort();
var count_champ = 0;
var current_player = "";
var current_champ = "";
var current_losses = 0;
var current_wins = 0;
var split_array = [];
for (var m = 0; m < game_list.length; m++) {
split_array = game_list[m].split("|");
if (m === 0) { // First Game
current_player = split_array[0];
current_champ = split_array[1];
count_champ = 1;
if (split_array[2] === "L") {
current_losses += 1;
} else {
current_wins += 1;
}
} else if (m === ((game_list.length)-1)) { // Last Game
if (split_array[0] === current_player && split_array[1] === current_champ) { // Same player + same champ
count_champ += 1;
if (split_array[2] === "L") {
current_losses += 1;
} else {
current_wins += 1;
}
} else {
champ_list.push(current_player + "|" + count_champ + "|" + current_champ + "|" + current_wins + "|" + current_losses);
current_player = split_array[0];
current_champ = split_array[1];
count_champ = 1;
if (split_array[2] === "L") {
current_losses = 1;
current_wins = 0;
} else {
current_wins = 1;
current_losses = 0;
}
}
champ_list.push(current_player + "|" + count_champ + "|" + current_champ + "|" + current_wins + "|" + current_losses);
} else if (split_array[0] === current_player && split_array[1] === current_champ) { // Matching player + champ
count_champ += 1;
if (split_array[2] === "L") {
current_losses += 1;
} else {
current_wins += 1;
}
} else { // Not matching player or champ
champ_list.push(current_player + "|" + count_champ + "|" + current_champ + "|" + current_wins + "|" + current_losses);
current_player = split_array[0];
current_champ = split_array[1];
count_champ = 1;
if (split_array[2] === "L") {
current_losses = 1;
current_wins = 0;
} else {
current_wins = 1;
current_losses = 0;
}
}
}
// CHAMP FINAL ARRAY SORTER
champ_list.sort();
champ_list.reverse();
return champ_list;
}
// Create Player Champ Sorted Array \\
function getPlayerChampSortedArray(arrayCCName) {
var game_list = arrayCCName;
var champ_list = [];
// CHAMPS PICKED COUNTER
var count_champ = 0;
var all_players = []
var current_player = ["","",""];
var current_losses = 0;
var current_wins = 0;
var split_array = [];
var currentWR = "";
for (var m = 0; m < game_list.length; m++) {
split_array = game_list[m].split("|");
if (m === 0) { // First Game
current_player[0] = split_array[0];
current_player.push(split_array[1]+"x "+split_array[2]+" ("+split_array[3]+"-"+split_array[4]+")");
count_champ = 1;
current_wins += parseInt(split_array[3]);
current_losses += parseInt(split_array[4]);
} else if (m === ((game_list.length)-1)) { // Last Game
if (split_array[0] === current_player[0]) { // Same player
current_player.push(split_array[1]+"x "+split_array[2]+" ("+split_array[3]+"-"+split_array[4]+")");
count_champ += 1;
current_wins += parseInt(split_array[3]);
current_losses += parseInt(split_array[4]);
current_player[1] = count_champ;
currentWR = ((current_wins/(current_wins+current_losses))*100).toFixed(0);
current_player[2] = currentWR+"% ("+current_wins+"-"+current_losses+")"
current_player[0] = (current_player[0]);
} else { // Diff player
current_player[0] = (current_player[0]);
current_player[1] = count_champ;
currentWR = ((current_wins/(current_wins+current_losses))*100).toFixed(0);
current_player[2] = currentWR+"% ("+split_array[3]+"-"+split_array[4]+")"
all_players.push(current_player);
current_player[0] = (current_player[0]);
current_wins = parseInt(split_array[3]);
current_losses = parseInt(split_array[4]);
currentWR = ((current_wins/(current_wins+current_losses))*100).toFixed(0);
current_player = [split_array[0], 1, currentWR+"% ("+current_wins+"-"+current_losses+")",split_array[1]+"x "+split_array[2]+" ("+split_array[3]+"-"+split_array[4]+")"];
}
all_players.push(current_player);
} else if (split_array[0] === current_player[0]) { // Matching player
count_champ += 1;
current_player.push(split_array[1]+"x "+split_array[2]+" ("+split_array[3]+"-"+split_array[4]+")");
current_wins += parseInt(split_array[3]);
current_losses += parseInt(split_array[4]);
} else { // Diff player
current_player[1] = count_champ;
currentWR = ((current_wins/(current_wins+current_losses))*100).toFixed(0);
current_player[2] = currentWR+"% ("+current_wins+"-"+current_losses+")"
current_player[0] = (current_player[0]);
all_players.push(current_player);
current_player = [split_array[0],"",""];
current_player.push(split_array[1]+"x "+split_array[2]+" ("+split_array[3]+"-"+split_array[4]+")");
count_champ = 1;
current_wins = parseInt(split_array[3]);
current_losses = parseInt(split_array[4]);
}
}
// CHAMP FINAL ARRAY SORTER
all_players.sort(function(a,b){
if(parseFloat(a[1]) === parseFloat(b[1])) {
return parseFloat(b[2]) - parseFloat(a[2]);
} else if(parseFloat(a[1]) > parseFloat(b[1])) {
return -1;
}
return 1;
});
return all_players;
}
// Create Champ Counter Array \\
function getTeamSeriesDatesCounter(arayINPUT) {
var game_list = arayINPUT;
var champ_list = [];
// CHAMPS PICKED COUNTER
game_list.sort();
var current_date = "";
var current_team = "";
var current_losses = 0;
var current_wins = 0;
var current_ffs = 0;
var split_array = [];
for (var m = 0; m < game_list.length; m++) {
split_array = game_list[m].split("|");
if (m === 0) { // First Game
current_date = split_array[0];
current_team = split_array[1]
if (split_array[2] === "L") {
current_losses += 1;
} else if (split_array[2] === "W"){
current_wins += 1;
} else {
current_ffs += 1;
}
} else if (m === ((game_list.length)-1)) { // Last Game
if (split_array[0] === current_date) { // Same date
if (split_array[1] === current_team) { // Same date + team
if (split_array[2] === "L") {
current_losses += 1;
} else if (split_array[2] === "W"){
current_wins += 1;
} else {