-
Notifications
You must be signed in to change notification settings - Fork 0
/
predictions.php
169 lines (143 loc) · 6.33 KB
/
predictions.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
<html>
<?php
include("header.php") ?>
<script src="js/bootstrap.min.js"></script>
<body>
<?php include("navBar.php") ?>
<div class="container row-offcanvas row-offcanvas-left">
<div class="well column col-lg-12 col-sm-12 col-xs-12" id="content">
<h1>Predictions</h1>
<div class="input-group mb-3">
<input id="eventCode" type="text" class="form-control" placeholder="eventCode" aria-label="eventCode">
<button id="loadEvent" type="button" class="btn btn-primary">Load Event</button>
<div class="row">
<div id="tableWrapper" class="">
<table id="matchResults" class="table table-striped table-hover">
<thead>
<tr id="matchResultsTableKeys">
<tr>
<th colspan="1">Match</th>
<th colspan="3">Alliance</th>
<th colspan="1">Predicted OPR Score</th>
<th colspan="1">Predicted Data Score</th>
<th colspan="1">Real Score</th>
</tr>
</tr>
</thead>
<tbody id="matchResultsTableData">
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</body>
<style>
table th, table tr{
font-size: 12px;
}
</style>
<script>
$(document).ready(function() {
var scoutingData = null;
var lastEventOPRs = null;
var matchInfo = null;
var teamList = null;
var procMatchData = [];
function getSimpleMatchList(complexMatchList){
var out = [];
for(let mi in complexMatchList){
var match = complexMatchList[mi];
if (match["comp_level"] == "qm"){
var currMatch = {};
currMatch["match_number"] = match["match_number"];
currMatch["red_teams"] = match["alliances"]["red"]["team_keys"];
currMatch["blue_teams"] = match["alliances"]["blue"]["team_keys"];
currMatch["red_score"] = match["score_breakdown"]["red"]["totalPoints"];
currMatch["red_cargo_rp"] = match["score_breakdown"]["red"]["cargoBonusRankingPoint"];
currMatch["red_endgame_rp"] = match["score_breakdown"]["red"]["hangarBonusRankingPoint"];
currMatch["blue_score"] = match["score_breakdown"]["blue"]["totalPoints"];
currMatch["blue_cargo_rp"] = match["score_breakdown"]["blue"]["cargoBonusRankingPoint"];
currMatch["blue_endgame_rp"] = match["score_breakdown"]["blue"]["hangarBonusRankingPoint"];
}
}
return out;
}
function predictMatches(simpleMatchlist, scoutingData, lastEventOPRS){
var oprPrediction = {};
var dataPrediction = {};
for (let mi in simpleMatchList){
var match = simpleMatchList[mi];
oprPred = {'red_score' : 0, 'blue_score' : 0, 'red_cargo_rp': 0, 'blue_cargo_rp': 0, 'red_endgame_rp': 0, 'blue_endgame_rp': 0 };
dataPred = {'red_score' : 0, 'blue_score' : 0, 'red_cargo_rp': 0, 'blue_cargo_rp': 0, 'red_endgame_rp': 0, 'blue_endgame_rp': 0 };
for (let i in match["red_teams"]){
var team = match["red_teams"][i];
// OPR Pred
oprPred['red_score'] += lastEventOPRS[team]['totalPoints'];
oprPred['red_cargo_rp'] += lastEventOPRS[team]['matchCargoTotal'];
oprPred['red_endgame_rp'] += lastEventOPRS[team]['endgamePoints'];
// Data Pred
dataPred['red_score'] += scoutingData[team]['totalPoints'];
dataPred['red_cargo_rp'] += scoutingData[team]['ballsScored'];
dataPred['red_endgame_rp'] += scoutingData[team]['endgamePoints'];
}
for (let i in match["blue_teams"]){
var team = match["blue_teams"][i];
// OPR Pred
oprPred['blue_score'] += lastEventOPRS[team]['totalPoints'];
oprPred['blue_cargo_rp'] += lastEventOPRS[team]['matchCargoTotal'];
oprPred['blue_endgame_rp'] += lastEventOPRS[team]['endgamePoints'];
// Data Pred
dataPred['blue_score'] += scoutingData[team]['totalPoints'];
dataPred['blue_cargo_rp'] += scoutingData[team]['ballsScored'];
dataPred['blue_endgame_rp'] += scoutingData[team]['endgamePoints'];
}
oprPred["red_cargo_rp"] = oprPred["red_cargo_rp"] >= 20;
oprPred["blue_cargo_rp"] = oprPred["blue_cargo_rp"] >= 20;
dataPred["red_cargo_rp"] = dataPred["red_cargo_rp"] >= 20;
dataPred["blue_cargo_rp"] = dataPred["blue_cargo_rp"] >= 20;
oprPred["red_endgame_rp"] = oprPred["red_endgame_rp"] >= 16;
oprPred["blue_endgame_rp"] = oprPred["blue_endgame_rp"] >= 16;
dataPred["red_endgame_rp"] = dataPred["red_endgame_rp"] >= 16;
dataPred["blue_endgame_rp"] = dataPred["blue_endgame_rp"] >= 16;
oprPrediction[match["match_number"]] = oprPred;
dataPrediction[match["match_number"]] = dataPred;
}
var out = {}
out["oprPrediction"] = oprPrediction;
out["dataPrediction"] = dataPrediction;
return out;
}
function displayMatchPredictions(ma
function processPredictions(){
if ((scoutingData != null) && (lastEventOPRs != null) && (matchInfo != null) && (teamList != null)){
var simpleMatchList = getSimpleMatchList(matchInfo['response']);
var matchPrediction = predictMatches(simpleMatchList, scoutingData, lastEventOPRS);
}
}
$.get( "readAPI.php", {getAllAverageData : 1}).done( function( data ) {
// Get Scouting Data
scoutingData = JSON.parse(data)['response'];
processPredictions();
});
$("#loadEvent").click(function(){
$.get( "tbaAPI.php", {lastEventOPRS: 1, eventcode: $("#eventCode").val()}).done( function( data ) {
// Get Last Event OPRs for team
lastEventOPRs = JSON.parse(data);
processPredictions();
});
$.get( "tbaAPI.php", {getMatchList: 1, eventcode: $("#eventCode").val()}).done( function( data ) {
// Get Matches
matchInfo = JSON.parse(data);
processPredictions();
});
$.get( "tbaAPI.php", {getTeamList: 1, eventcode: $("#eventCode").val()}).done( function( data ) {
// Get Team List
teamList = JSON.parse(data);
processPredictions();
});
});
}
</script>
<?php include("footer.php") ?>