-
Notifications
You must be signed in to change notification settings - Fork 0
/
databaseLibrary.php
1713 lines (1468 loc) · 43.3 KB
/
databaseLibrary.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
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
<?php
include("databaseName.php");
require_once('tbaAPI.php');
require_once("qualRankGen.php");
//Input- runQuery, establishes connection with server, runs query, closes connection.
//Output- queryOutput, data to/from the tables in phpMyAdmin databases.
function runQuery($queryString)
{
global $servername;
global $username;
global $password;
global $dbname;
global $pitScoutTable;
global $matchScoutTable;
global $betTable;
global $leadScoutTable;
global $pickListTable;
global $eloRanking;
//Establish Connection
try {
$conn = connectToDB();
} catch (Exception $e) {
error_log("CREATING DB");
createDB();
$conn = connectToDB();
}
try {
$statement = $conn->prepare($queryString);
} catch (PDOException $e) {
error_log($e->getMessage());
error_log($e->getCode());
if ($e->getCode() == "42S02") {
error_log("CREATING TABLES");
createTables();
}
$statement = $conn->prepare($queryString);
}
if (!$statement->execute()) {
die("Failed!");
}
try {
return $statement->fetchAll();
} catch (Exception $e) {
return;
}
}
function createDB()
{
global $dbname;
$connection = connectToServer();
$statement = $connection->prepare('CREATE DATABASE IF NOT EXISTS ' . $dbname);
if (!$statement->execute()) {
throw new Exception("constructDatabase Error: CREATE DATABASE query failed.");
}
}
function connectToServer()
{
global $servername;
global $username;
global $password;
global $dbname;
global $charset;
$dsn = "mysql:host=" . $servername . ";charset=" . $charset;
$opt = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => false
];
return (new PDO($dsn, $username, $password, $opt));
}
function connectToDB()
{
global $servername;
global $username;
global $password;
global $dbname;
global $charset;
$dsn = "mysql:host=" . $servername . ";dbname=" . $dbname . ";charset=" . $charset;
$opt = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => false
];
return (new PDO($dsn, $username, $password, $opt));
}
function createTBATable($tbaTableName)
{
$conn = connectToDB();
global $dbname;
$query = "CREATE TABLE " . $dbname . "." . $tbaTableName . " (
requestURI VARCHAR(100) NOT NULL PRIMARY KEY,
expiryTime BIGINT NOT NULL,
response MEDIUMTEXT NOT NULL
)";
$statement = $conn->prepare($query);
if (!$statement->execute()) {
throw new Exception("createTBATable Error: CREATE TABLE tbatable query failed.");
}
}
function createTables()
{
global $servername;
global $username;
global $password;
global $dbname;
global $pitScoutTable;
global $matchScoutTable;
global $betTable;
global $pickListTable;
global $leadScoutTable;
global $$sorting_items;
global $eloRanking;
global $sortablePickTable;
$conn = connectToDB();
$query = "CREATE TABLE " . $dbname . "." . $leadScoutTable . " (
matchkey VARCHAR(60) NOT NULL,
teamrank MEDIUMTEXT NOT NULL
)";
$statement = $conn->prepare($query);
if (!$statement->execute()) {
throw new Exception("constructDatabase Error: CREATE TABLE leadScoutTable query failed.");
}
$query = "CREATE TABLE " . $dbname . "." . $pitScoutTable . " (
teamNumber VARCHAR(50) NOT NULL PRIMARY KEY,
teamName VARCHAR(60) NOT NULL,
numBatteries VARCHAR(20) NOT NULL,
chargedBatteries VARCHAR(20) NOT NULL,
codeLanguage VARCHAR(10) NOT NULL,
pitComments LONGTEXT NOT NULL,
climbHelp LONGTEXT NOT NULL
)";
$statemennt = $conn->prepare($query);
if (!$statemennt->execute()) {
throw new Exception("constructDatabase Error: CREATE TABLE pitScoutTable query failed.");
}
$query = "CREATE TABLE " . $dbname . "." . $matchScoutTable . " (
user VARCHAR(20) NOT NULL,
ID VARCHAR(8) NOT NULL PRIMARY KEY,
matchNum INT(11) NOT NULL,
teamNum INT(11) NOT NULL,
allianceColor TEXT NOT NULL,
autoPath LONGTEXT NOT NULL,
crossLineA INT(11) NOT NULL,
upperGoal INT(11) NOT NULL,
upperGoalMiss INT(11) NOT NULL,
lowerGoal INT(11) NOT NULL,
lowerGoalMiss INT(11) NOT NULL,
upperGoalT INT(11) NOT NULL,
upperGoalMissT INT(11) NOT NULL,
lowerGoalT INT(11) NOT NULL,
lowerGoalMissT INT(11) NOT NULL,
climb TINYINT(4) NOT NULL,
climbTwo TINYINT(4) NOT NULL,
climbThree TINYINT(4) NOT NULL,
climbFour TINYINT(4) NOT NULL,
issues LONGTEXT NOT NULL,
defenseBot INT(11) NOT NULL,
defenseComments LONGTEXT NOT NULL,
matchComments LONGTEXT NOT NULL,
penalties INT(11) NOT NULL,
cycleCount LONGTEXT NOT NULL,
teleopPath LONGTEXT NOT NULL,
doNotPick INT(11) NOT NULL
)";
$statement = $conn->prepare($query);
if (!$statement->execute()) {
throw new Exception("constructDatabase Error: CREATE TABLE matchScoutTable query failed.");
}
$query = "CREATE TABLE " . $dbname . "." . $betTable . " (
matchNum INT(11) NOT NULL,
RedScorePredict TEXT NOT NULL,
BlueScorePredict TEXT NOT NULL,
TotalAutoRed TEXT NOT NULL,
TotalAutoBlue TEXT NOT NULL,
Winner TEXT NOT NULL,
name TEXT NOT NULL,
ID VARCHAR(50) NOT NULL PRIMARY KEY
)";
$statement = $conn->prepare($query);
if (!$statement->execute()) {
throw new Exception("constructDatabase Error: CREATE TABLE Bet Table query failed.");
}
$query = "CREATE TABLE " . $dbname . "." . $sortablePickTable . " (
allTeams LONGTEXT NOT NULL,
attackTeams LONGTEXT NOT NULL,
defenseTeams LONGTEXT NOT NULL,
dnpTeams LONGTEXT NOT NULL
)";
$statement = $conn->prepare($query);
if (!$statement->execute()) {
throw new Exception("constructDatabase Error: CREATE TABLE Sortable Pick query failed.");
}
$query = "CREATE TABLE " . $dbname . "." . $pickListTable . " (
team1 VARCHAR(50) NOT NULL,
team2 VARCHAR(50) NOT NULL,
equal VARCHAR(50) NOT NULL
)";
$statement = $conn->prepare($query);
if (!$statement->execute()) {
throw new Exception("constructDatabase Error: CREATE TABLE pickList Table query failed.");
}
$query = "CREATE TABLE " . $dbname . "." . $eloRanking . " (
team VARCHAR(50) NOT NULL PRIMARY KEY,
eloScore INT(11) NOT NULL
)";
$statement = $conn->prepare($query);
if (!$statement->execute()) {
throw new Exception("constructDatabase Error: CREATE TABLE elo Table query failed.");
}
}
//Input- pitScoutInput, Data from pit scout form is assigned to columns in 17template_pitscout.
//Output- queryString and "Success" statement, data put in columns.
function pitScoutInput($teamNumber, $teamName, $numBatteries, $chargedBatteries, $codeLanguage, $pitComments, $climbHelp)
{
global $pitScoutTable;
$queryString = "REPLACE INTO `" . $pitScoutTable . "` (`teamNumber`, `teamName`, `numBatteries`,`chargedBatteries`, `codeLanguage`, `pitComments`, `climbHelp`)";
$queryString = $queryString . ' VALUES ("' . $teamNumber . '", "' . $teamName . '", "' . $numBatteries . '", "' . $chargedBatteries . '", "' . $codeLanguage . '", "' . $pitComments . '", "' . $climbHelp . '")';
$queryOutput = runQuery($queryString);
}
function leadScoutInput($matchKey, $teamRank)
{
global $servername;
global $username;
global $password;
global $dbname;
global $leadScoutTable;
$data = array();
$data["matchkey"] = $matchKey;
$data["teamrank"] = $teamRank;
$conn = connectToDB();
$sql = "INSERT INTO " . $leadScoutTable . "(matchkey, teamrank) VALUES(:matchkey, :teamrank)";
$prepared_statement = $conn->prepare($sql);
$prepared_statement->execute($data);
}
function betInput($matchNum, $RedScorePredict, $BlueScorePredict, $TotalAutoRed, $TotalAutoBlue, $Winner, $name, $ID)
{
global $betTable;
$queryString = "REPLACE INTO `" . $betTable . "` (`matchNum`, `RedScorePredict`, `BlueScorePredict`,`TotalAutoRed`, `TotalAutoBlue`, `Winner`, `name`, `ID`)";
$queryString = $queryString . ' VALUES ("' . $matchNum . '", "' . $RedScorePredict . '", "' . $BlueScorePredict . '", "' . $TotalAutoRed . '", "' . $TotalAutoBlue . '", "' . $Winner . '", "' . $name . '", "' . $ID . '")';
$queryOutput = runQuery($queryString);
}
function sortableInput($allTeams, $attackTeams, $defenseTeams, $dnpTeams)
{
global $sortablePickTable;
$queryString = "REPLACE INTO `" . $sortablePickTable . "` (`allTeams`, `attackTeams`, `defenseTeams`,`TotalAutoRed`, `dnpTeams`)";
$queryString = $queryString . ' VALUES ("' . $allTeams . '", "' . $attackTeams . '", "' . $defenseTeams . '", "' . $dnpTeams . '")';
$queryOutput = runQuery($queryString);
}
function pickListInput($team1, $team2, $equal)
{
global $pickListTable;
$queryString = "REPLACE INTO `" . $pickListTable . "` (`team1`, `team2`, `equal`)";
$queryString = $queryString . ' VALUES ("' . $team1 . '", "' . $team2 . '", "' . $equal . '")';
$queryOutput = runQuery($queryString);
updateElo($team1, $team2, $equal);
}
function eloInput($team, $eloScore)
{
global $eloRanking;
$queryString = "REPLACE INTO `" . $eloRanking . "` (`team`, `eloScore`)";
$queryString = $queryString . ' VALUES ("' . $team . '", "' . $eloScore . '")';
$queryOutput = runQuery($queryString);
}
function matchInput(
$user,
$ID,
$matchNum,
$teamNum,
$allianceColor,
$autoPath,
$crossLineA,
$upperGoal,
$upperGoalMiss,
$lowerGoal,
$lowerGoalMiss,
$upperGoalT,
$upperGoalMissT,
$lowerGoalT,
$lowerGoalMissT,
$climb,
$climbTwo,
$climbThree,
$climbFour,
$issues,
$defenseBot,
$defenseComments,
$matchComments,
$penalties,
$cycleCount,
$teleopPath,
$doNotPick
) {
global $servername;
global $username;
global $password;
global $dbname;
global $matchScoutTable;
$queryString = "REPLACE INTO `" . $matchScoutTable . '`( `user`,
`ID`,
`matchNum`,
`teamNum`,
`allianceColor`,
`autoPath`,
`crossLineA`,
`upperGoal`,
`upperGoalMiss`,
`lowerGoal`,
`lowerGoalMiss`,
`upperGoalT`,
`upperGoalMissT`,
`lowerGoalT`,
`lowerGoalMissT`,
`climb`,
`climbTwo`,
`climbThree`,
`climbFour`,
`issues`,
`defenseBot`,
`defenseComments`,
`matchComments`,
`penalties`,
`cycleCount`,
`teleopPath`,
`doNotPick`)
VALUES ( "' . $user . '",
"' . $ID . '",
"' . $matchNum . '",
"' . $teamNum . '",
"' . $allianceColor . '",
"' . $autoPath . '",
"' . $crossLineA . '",
"' . $upperGoal . '",
"' . $upperGoalMiss . '",
"' . $lowerGoal . '",
"' . $lowerGoalMiss . '",
"' . $upperGoalT . '",
"' . $upperGoalMissT . '",
"' . $lowerGoalT . '",
"' . $lowerGoalMissT . '",
"' . $climb . '",
"' . $climbTwo . '",
"' . $climbThree . '",
"' . $climbFour . '",
"' . $issues . '",
"' . $defenseBot . '",
"' . $defenseComments . '",
"' . $matchComments . '",
"' . $penalties . '",
"' . $cycleCount . '",
"' . $teleopPath . '",
"' . $doNotPick . '")';
$queryOutput = runQuery($queryString);
}
//Input- getTeamList, accesses match scout table and gets team numbers from it.
//Output- array, list of teams in teamNumber column of pitscout table.
function getElo($teamNumber)
{
global $eloRanking;
$qs1 = "SELECT eloScore FROM `" . $eloRanking . "` WHERE team = " . $teamNumber . "";
$result = runQuery($qs1);
$teams = array();
foreach ($result as $row_key => $row) {
if (!in_array($row["eloScore"], $teams)) {
array_push($teams, $row["eloScore"]);
}
}
return ($teams[0]);
}
function eloChange($teamNumber, $eloScore)
{
global $eloRanking;
$qs1 = "UPDATE `" . $eloRanking . "` SET eloScore = " . $eloScore . " WHERE team = " . $teamNumber;
$result = runQuery($qs1);
}
function getTeamList($min = -1, $max = 1000)
{
global $matchScoutTable;
$queryStringTwo = "SELECT `teamNum` FROM `" . $matchScoutTable . "` WHERE matchNum >= " . $min . " AND matchNum <= " . $max . "";
$resultTwo = runQuery($queryStringTwo);
$teams = array();
foreach ($resultTwo as $row_key => $row) {
if (!in_array($row["teamNum"], $teams)) {
array_push($teams, $row["teamNum"]);
}
}
return ($teams);
}
function getUserList()
{
global $betTable;
$queryStringTwo = "SELECT `name` FROM `" . $betTable . "`";
$resultTwo = runQuery($queryStringTwo);
$names = array();
foreach ($resultTwo as $row_key => $row) {
if (!in_array($row["name"], $names)) {
array_push($names, $row["name"]);
}
}
return ($names);
}
function getAllTeamAverageData()
{
global $servername;
global $username;
global $password;
global $dbname;
global $matchScoutTable;
$qs = "SELECT * FROM `" . $matchScoutTable . "`";
$result = runQuery($qs);
$teamData = array();
$teamList = array();
foreach ($result as $row_key => $row) {
$teamNum = $row["teamNum"];
if (!isset($teamList[$teamNum])) {
$teamList[$teamNum] = 1;
$teamData[$teamNum] = array();
$teamData[$teamNum]['matchCount'] = 0;
$teamData[$teamNum]['ballsScored'] = 0;
$teamData[$teamNum]['autoPoints'] = 0;
$teamData[$teamNum]['teleopPoints'] = 0;
$teamData[$teamNum]['endgamePoints'] = 0;
$teamData[$teamNum]['totalPoints'] = 0;
}
$autoPoints = (($row['crossLineA'] == 1) ? 2 : 0) + ($row['upperGoal'] * 4) + ($row['lowerGoal'] * 2);
$teleopPoints = ($row['upperGoalT'] * 2) + ($row['lowerGoalT'] * 1);
$endgamePoints = 0;
if ($row['climb']) {
$endgamePoints = 4;
} else if ($row['climbTwo']) {
$endgamePoints = 6;
} else if ($row['climbThree']) {
$endgamePoints = 10;
} else if ($row['climbFour']) {
$endgamePoints = 15;
}
$totalPoints = $autoPoints + $teleopPoints + $endgamePoints;
$ballsScored = $row['upperGoal'] + $row['lowerGoal'] + $row['upperGoalT'] + $row['lowerGoalT'];
$teamData[$teamNum]['matchCount'] += 1;
$teamData[$teamNum]['ballsScored'] += $ballsScored;
$teamData[$teamNum]['autoPoints'] += $autoPoints;
$teamData[$teamNum]['teleopPoints'] += $teleopPoints;
$teamData[$teamNum]['endgamePoints'] += $endgamePoints;
$teamData[$teamNum]['totalPoints'] += $totalPoints;
}
foreach ($teamList as $team => $teamRow) {
$teamData[$team]['ballsScored'] = $teamData[$team]['ballsScored'] / $teamData[$team]['matchCount'];
$teamData[$team]['autoPoints'] = $teamData[$team]['autoPoints'] / $teamData[$team]['matchCount'];
$teamData[$team]['teleopPoints'] = $teamData[$team]['teleopPoints'] / $teamData[$team]['matchCount'];
$teamData[$team]['endgamePoints'] = $teamData[$team]['endgamePoints'] / $teamData[$team]['matchCount'];
$teamData[$team]['totalPoints'] = $teamData[$team]['totalPoints'] / $teamData[$team]['matchCount'];
}
return $teamData;
}
function getTeamData($teamNumber, $min = -1, $max = 1000)
{
global $servername;
global $username;
global $password;
global $dbname;
global $pitScoutTable;
global $matchScoutTable;
global $leadScoutTable;
$qs1 = "SELECT * FROM `" . $pitScoutTable . "` WHERE teamNumber = " . $teamNumber . "";
$qs2 = "SELECT * FROM `" . $matchScoutTable . "` WHERE teamNum = " . $teamNumber . " AND matchNum >= " . $min . " AND matchNum <= " . $max . "";
//echo "<script>console.log('".$qs2."');</script>";
// $qs3 = "SELECT * FROM `" . $leadScoutTable . "`";
$result = runQuery($qs1);
$result2 = runQuery($qs2);
// $result3 = runQuery($qs3);
$teamData = array();
$pitExists = False;
if ($result != FALSE) {
// output data of each row
foreach ($result as $row_key => $row) {
array_push($teamData, $row["teamNumber"], $row["teamName"], $row["numBatteries"], $row["chargedBatteries"], $row["codeLanguage"], $row["pitComments"], $row["climbHelp"], array(), array());
$pitExists = True;
}
}
if (!$pitExists) {
array_push($teamData, $teamNumber, 'NA', 'NA', 'NA', 'NA', 'NA', 'NA', array(), array());
}
if ($result2 != FALSE) {
foreach ($result2 as $row_key => $row) {
array_push($teamData[8], array(
$row["user"], $row["ID"], $row["matchNum"],
$row["teamNum"], $row["allianceColor"], $row["autoPath"],
$row["crossLineA"], $row["upperGoal"], $row["upperGoalMiss"],
$row["lowerGoal"], $row["lowerGoalMiss"], $row["upperGoalT"],
$row["upperGoalMissT"], $row["lowerGoalT"], $row["lowerGoalMissT"],
$row["climb"], $row["climbTwo"], $row["climbThree"], $row["climbFour"], $row["issues"], $row["defenseBot"],
$row["defenseComments"], $row["matchComments"], $row["penalties"], $row["cycleCount"], $row["teleopPath"], $row["doNotPick"]
));
}
}
return ($teamData);
}
function getBetData($user)
{
global $servername;
global $username;
global $password;
global $dbname;
global $betTable;
$qs1 = "SELECT * FROM " . $betTable . " WHERE name = '" . $user . "'";
$result = runQuery($qs1);
$betData = array();
if ($result != FALSE) {
foreach ($result as $row_key => $row) {
array_push($betData, array(
$row["matchNum"], $row["RedScorePredict"], $row["BlueScorePredict"],
$row["TotalAutoRed"], $row["TotalAutoBlue"], $row["Winner"],
$row["name"], $row["ID"]
));
}
}
return ($betData);
}
// The functions below output data per match
// These are used in graphs in the Match Strategy and Team Data Pages
function getEvent()
{
return ("2022cabl_qm");
}
function getYourTeam()
{
return ("frc3476");
}
function getEventRaw()
{
$event = getEvent();
$event = substr($event, 0, -3);
return $event;
}
function getAutoUpperGoal($teamNumber)
{
$teamData = getTeamData($teamNumber);
$matchN = matchNum($teamNumber);
$cubeGraphT = array();
for ($i = 0; $i != sizeof($teamData[8]); $i++) {
$cubeGraphT[$teamData[8][$i][2]] = $teamData[8][$i][7];
}
$out = array();
for ($i = 0; $i != sizeof($matchN); $i++) {
array_push($out, $cubeGraphT[$matchN[$i]]);
}
return ($out);
}
function getAutoLowerGoal($teamNumber)
{
$teamData = getTeamData($teamNumber);
$matchN = matchNum($teamNumber);
$cubeGraphT = array();
for ($i = 0; $i != sizeof($teamData[8]); $i++) {
$cubeGraphT[$teamData[8][$i][2]] = $teamData[8][$i][9];
}
$out = array();
for ($i = 0; $i != sizeof($matchN); $i++) {
array_push($out, $cubeGraphT[$matchN[$i]]);
}
return ($out);
}
function getAutoUpperGoalMiss($teamNumber)
{
$teamData = getTeamData($teamNumber);
$matchN = matchNum($teamNumber);
$cubeGraphT = array();
for ($i = 0; $i != sizeof($teamData[8]); $i++) {
$cubeGraphT[$teamData[8][$i][2]] = $teamData[8][$i][8];
}
$out = array();
for ($i = 0; $i != sizeof($matchN); $i++) {
array_push($out, $cubeGraphT[$matchN[$i]]);
}
return ($out);
}
function Standardize($teamNumber)
{
$teamData = getTeamData($teamNumber);
$matchN = matchNum($teamNumber);
$cubeGraphT = array();
for ($i = 0; $i != sizeof($teamData[8]); $i++) {
$cubeGraphT[$teamData[8][$i][2]] = 20;
}
$out = array();
for ($i = 0; $i != sizeof($matchN); $i++) {
array_push($out, $cubeGraphT[$matchN[$i]]);
}
return ($out);
}
function getTeleopUpperGoal($teamNumber)
{
$teamData = getTeamData($teamNumber);
$matchN = matchNum($teamNumber);
$cubeGraphT = array();
for ($i = 0; $i != sizeof($teamData[8]); $i++) {
$cubeGraphT[$teamData[8][$i][2]] = $teamData[8][$i][11];
}
$out = array();
for ($i = 0; $i != sizeof($matchN); $i++) {
array_push($out, $cubeGraphT[$matchN[$i]]);
}
return ($out);
}
function getTeleopLowerGoal($teamNumber)
{
$teamData = getTeamData($teamNumber);
$matchN = matchNum($teamNumber);
$cubeGraphT = array();
if ($teamData[8] != null) {
for ($i = 0; $i != sizeof($teamData[8]); $i++) {
$cubeGraphT[$teamData[8][$i][2]] = $teamData[8][$i][13];
}
}
$out = array();
for ($i = 0; $i != sizeof($matchN); $i++) {
array_push($out, $cubeGraphT[$matchN[$i]]);
}
return ($out);
}
function getTeleopUpperGoalMiss($teamNumber)
{
$teamData = getTeamData($teamNumber);
$matchN = matchNum($teamNumber);
$cubeGraphT = array();
for ($i = 0; $i != sizeof($teamData[8]); $i++) {
$cubeGraphT[$teamData[8][$i][2]] = $teamData[8][$i][12];
}
$out = array();
for ($i = 0; $i != sizeof($matchN); $i++) {
array_push($out, $cubeGraphT[$matchN[$i]]);
}
return ($out);
}
function getLowerGoal($teamNumber)
{
$teamData = getTeamData($teamNumber);
$matchN = matchNum($teamNumber);
$cubeGraphT = array();
for ($i = 0; $i != sizeof($teamData[8]); $i++) {
$cubeGraphT[$teamData[8][$i][2]] = $teamData[8][$i][9] + $teamData[8][$i][13];
}
$out = array();
for ($i = 0; $i != sizeof($matchN); $i++) {
array_push($out, $cubeGraphT[$matchN[$i]]);
}
return ($out);
}
function getClimb($teamNumber)
{
$teamData = getTeamData($teamNumber);
$matchN = matchNum($teamNumber);
$cubeGraphT = array();
for ($i = 0; $i != sizeof($teamData[8]); $i++) {
$cubeGraphT[$teamData[8][$i][2]] = $teamData[8][$i][15] + 2 * $teamData[8][$i][16] + 3 * $teamData[8][$i][17] + 4 * $teamData[8][$i][18];
}
$out = array();
for ($i = 0; $i != sizeof($matchN); $i++) {
array_push($out, $cubeGraphT[$matchN[$i]]);
}
return ($out);
}
function getUpperShotPercentage($teamNumber)
{
$teamData = getTeamData($teamNumber);
$matchN = matchNum($teamNumber);
$cubeGraphT = array();
for ($i = 0; $i != sizeof($teamData[8]); $i++) {
if ((($teamData[8][$i][12]) + (($teamData[8][$i][11]) + ($teamData[8][$i][7]) + ($teamData[8][$i][8]))) != 0) {
$cubeGraphT[$teamData[8][$i][2]] = (100 * ((($teamData[8][$i][11]) + ($teamData[8][$i][7])) / (($teamData[8][$i][12]) + (($teamData[8][$i][11]) + ($teamData[8][$i][7]) + ($teamData[8][$i][8])))));
} else {
$cubeGraphT[$teamData[8][$i][2]] = 0;
}
}
$out = array();
for ($i = 0; $i != sizeof($matchN); $i++) {
array_push($out, $cubeGraphT[$matchN[$i]]);
}
return ($out);
}
function getScore($teamNumber)
{
$teamData = getTeamData($teamNumber);
$matchN = matchNum($teamNumber);
$cubeGraphT = array();
if ($teamData[8] != null) {
for ($i = 0; $i != sizeof($teamData[8]); $i++) {
$cubeGraphT[$teamData[8][$i][2]] = ((4 * ($teamData[8][$i][7])) + (2 * ($teamData[8][$i][9])) + (2 * ($teamData[8][$i][11])) + ($teamData[8][$i][13]) + (4 * ($teamData[8][$i][15])) + (6 * ($teamData[8][$i][16])) + (10 * ($teamData[8][$i][17])) + (15 * ($teamData[8][$i][18])) + (5 * ($teamData[8][$i][6])));
}
}
$out = array();
for ($i = 0; $i != sizeof($matchN); $i++) {
array_push($out, $cubeGraphT[$matchN[$i]]);
}
return ($out);
}
// The functions below are Averages
function getAvgUpperShotPercentage($teamNumber, $min = -1, $max = 1000)
{
$teamData = getTeamData($teamNumber, $min, $max);
$upperGoalCount = 0;
$upperGoalMissCount = 0;
if ($teamData[8] != null) {
for ($i = 0; $i != sizeof($teamData[8]); $i++) {
$upperGoalCount = $upperGoalCount + $teamData[8][$i][11] + $teamData[8][$i][7];
}
for ($i = 0; $i != sizeof($teamData[8]); $i++) {
$upperGoalMissCount = $upperGoalMissCount + $teamData[8][$i][8] + $teamData[8][$i][12];
}
if (($upperGoalCount + $upperGoalMissCount) == 0) {
return (0);
}
}
return (round((100 * ($upperGoalCount / ($upperGoalCount + $upperGoalMissCount))), 3));
}
function getAvgUpperGoalT($teamNumber, $min = -1, $max = 1000)
{
$teamData = getTeamData($teamNumber, $min, $max);
$upperGoalCountT = 0;
$matchCount = 0;
if ($teamData[8] != null) {
for ($i = 0; $i != sizeof($teamData[8]); $i++) {
$upperGoalCountT = $upperGoalCountT + $teamData[8][$i][11];
$matchCount++;
}
}
return (round(($upperGoalCountT / $matchCount), 3));
}
function getAvgLowerGoalT($teamNumber, $min = -1, $max = 1000)
{
$teamData = getTeamData($teamNumber, $min, $max);
$lowerGoalCountT = 0;
$matchCount = 0;
if ($teamData[8] != null) {
for ($i = 0; $i != sizeof($teamData[8]); $i++) {
$lowerGoalCountT = $lowerGoalCountT + $teamData[8][$i][13];
$matchCount++;
}
}
return ($lowerGoalCountT / $matchCount);
}
function getAvgUpperGoal($teamNumber, $min = -1, $max = 1000)
{
$teamData = getTeamData($teamNumber, $min, $max);
$upperGoalCount = 0;
$matchCount = 0;
for ($i = 0; $i != sizeof($teamData[8]); $i++) {
$upperGoalCount = $upperGoalCount + $teamData[8][$i][7];
$matchCount++;
}
return (round(($upperGoalCount / $matchCount), 3));
}
function getAvgLowerGoal($teamNumber, $min = -1, $max = 1000)
{
$teamData = getTeamData($teamNumber, $min, $max);
$lowerGoalCount = 0;
$matchCount = 0;
for ($i = 0; $i != sizeof($teamData[8]); $i++) {
$lowerGoalCount = $lowerGoalCount + $teamData[8][$i][9];
$matchCount++;
}
return ($lowerGoalCount / $matchCount);
}
function getAvgClimb($teamNumber, $min = -1, $max = 1000)
{
$teamData = getTeamData($teamNumber, $min, $max);
$climbSum = 0;
$matchCount = 0;
for ($i = 0; $i != sizeof($teamData[8]); $i++) {
$climbSum += $teamData[8][$i][15];
$climbSum += $teamData[8][$i][16];
$climbSum += $teamData[8][$i][17];
$climbSum += $teamData[8][$i][18];
$matchCount++;
}
return ($climbSum / $matchCount);
}
function getAvgPenalties($teamNumber)
{
$teamData = getTeamData($teamNumber);
$penalCount = 0;
$matchCount = 0;
if ($teamData[8] != null) {
for ($i = 0; $i != sizeof($teamData[8]); $i++) {
$penalCount = $penalCount + $teamData[8][$i][23];
$matchCount++;
}
}
return ($penalCount / $matchCount);
}
function getAvgScore($teamNumber, $min = -1, $max = 1000)
{
$teamData = getTeamData($teamNumber, $min, $max);
$matchCount = 0;
$Score = 0;
if ($teamData[8] != null) {
for ($i = 0; $i != sizeof($teamData[8]); $i++) {
$Score = $Score + ((4 * ($teamData[8][$i][7])) + (2 * ($teamData[8][$i][9])) + (2 * ($teamData[8][$i][11])) + ($teamData[8][$i][13]) + (4 * ($teamData[8][$i][15])) + (6 * ($teamData[8][$i][16])) + (10 * ($teamData[8][$i][17])) + (15 * ($teamData[8][$i][18])) + (2 * ($teamData[8][$i][6])));
$matchCount++;
}
}
return ($Score / $matchCount);
}
// Get Max
function getMaxUpperGoalT($teamNumber, $min = -1, $max = 1000)
{
$teamData = getTeamData($teamNumber, $min, $max);
$maxUpperGoalT = 0;
for ($i = 0; $i != sizeof($teamData[8]); $i++) {
if ($maxUpperGoalT < $teamData[8][$i][11]) {
$maxUpperGoalT = $teamData[8][$i][11];
}
}
return ($maxUpperGoalT);
}
function getMaxLowerGoalT($teamNumber, $min = -1, $max = 1000)
{
$teamData = getTeamData($teamNumber, $min, $max);
$maxLowerGoalT = 0;
for ($i = 0; $i != sizeof($teamData[8]); $i++) {
if ($maxLowerGoalT < $teamData[8][$i][13]) {
$maxLowerGoalT = $teamData[8][$i][13];
}
}
return ($maxLowerGoalT);
}
function getMaxUpperGoal($teamNumber, $min = -1, $max = 1000)
{
$teamData = getTeamData($teamNumber, $min, $max);
$maxUpperGoal = 0;
for ($i = 0; $i != sizeof($teamData[8]); $i++) {
if ($maxUpperGoal < $teamData[8][$i][7]) {
$maxUpperGoal = $teamData[8][$i][7];
}
}
return ($maxUpperGoal);
}
function getMaxLowerGoal($teamNumber, $min = -1, $max = 1000)
{
$teamData = getTeamData($teamNumber, $min, $max);
$maxLowerGoal = 0;
for ($i = 0; $i != sizeof($teamData[8]); $i++) {
if ($maxLowerGoal < $teamData[8][$i][9]) {
$maxLowerGoal = $teamData[8][$i][9];
}
}
return ($maxLowerGoal);
}
// Get Alls
function matchNum($teamNumber)
{
$teamData = getTeamData($teamNumber);
$matchNum = array();
if ($teamData[8] != null) {
for ($i = 0; $i != sizeof($teamData[8]); $i++) {
array_push($matchNum, $teamData[8][$i][2]);
}
}
sort($matchNum);
return ($matchNum);
}
function getAllMatchData()
{
global $matchScoutTable;
$qs1 = "SELECT * FROM `" . $matchScoutTable . "`";
return runQuery($qs1);
}
function getRawLeadScoutData()
{
global $leadScoutTable;
$qs1 = "SELECT * FROM `" . $leadScoutTable . "`";
return runQuery($qs1);
}