-
Notifications
You must be signed in to change notification settings - Fork 0
/
graphView.php
215 lines (187 loc) · 6.94 KB
/
graphView.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
<title>Graph View</title>
<html lang="en">
<?php include('navbar.php');?>
<body class="bg-body">
<div class="container row-offcanvas row-offcanvas-left">
<div class="well column col-lg-12 col-sm-12 col-xs-12" id="content">
<div class="row">
<div class="col-lg-12 col-sm-12 col-xs-12 gx-3">
<div class="card mb-3 mt-3">
<div class="card-header" id="chartHeader">
</div>
<div class="card-body">
<canvas id="dataChart"></canvas>
</div>
</div>
</div>
<div class="col-lg-12 col-sm-12 col-xs-12 gx-3">
<div class="card mb-3 mt-3">
<div class="card-body">
<div class="mb-3">
<label for="selectXAxis" class="form-label">X Axis</label>
<select class="form-select graphSelect" id="selectXAxis" aria-label="Graph X Axis">
</select>
</div>
<div class="mb-3">
<label for="selectYAxis" class="form-label">Y Axis</label>
<select class="form-select graphSelect" id="selectYAxis" aria-label="Graph Y Axis">
</select>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
<?php include("footer.php"); ?>
<script type="text/javascript" src="js/charts.js"></script>
<script type="text/javascript" src="js/matchDataProcessor.js?"></script>
<script>
var teamData = null;
var dataChart = null;
function addSelectOptions(){
var firstTeam = null;
for (const team in teamData){
firstTeam = team;
break;
}
for(const key in teamData[firstTeam]){
$('#selectXAxis').append($(new Option(key, key)));
$('#selectYAxis').append($(new Option(key, key)));
}
}
function getTeamScatterDatasets(xLabel, yLabel){
var data = {};
data['datasets'] = [];
for (const team in teamData){
var scatterData = {};
scatterData['label'] = team;
scatterData['data'] = [{'x': teamData[team][xLabel], 'y': teamData[team][yLabel]}];
data['datasets'].push(scatterData);
}
return data;
}
function drawChart(xLabel, yLabel){
if (dataChart != null){
dataChart.destroy();
}
$('#chartHeader').html(`${xLabel} / ${yLabel}`);
var ctx = document.getElementById('dataChart');
var teamDatasets = getTeamScatterDatasets(xLabel, yLabel);
dataChart = new Chart(ctx, {
type: 'scatter',
data: teamDatasets,
options: {
responsive: true,
plugins: {
title: {
display: true,
text: `${xLabel} / ${yLabel}`,
}
},
elements: {
point: {
radius: 7,
hoverRadius: 8
}
},
scales: {
y: {
title: {
display: true,
text: yLabel
},
},
x: {
title: {
display: true,
text: xLabel
},
}
}
}
});
}
function calculateMatchAverage(matches, func){
var out = 0;
for (var i = 0; i != matches.length; i++){
out += func(matches[i]);
}
return out/matches.length;
}
function calculateMatchMax(matches, func){
var out = 0;
for (var i = 0; i != matches.length; i++){
out = Math.max(func(matches[i]), out);
}
return out;
}
function getMatchAutoPlusEndgamePoints(row){
return getMatchPointsAuto(row) + getTeleopChargeStationPoints(row);
}
function matchDataToTeamData(matchData){
var teamMatchDataLookup = {};
for (var i = 0; i != matchData.length; i++){
var team = matchData[i]['teamNumber'];
if (! (team in teamMatchDataLookup)){
teamMatchDataLookup[team] = [];
}
teamMatchDataLookup[team].push(matchData[i]);
}
var teamToData = {};
for (const team in teamMatchDataLookup){
var matches = teamMatchDataLookup[team];
teamToData[team] = {};
teamToData[team]['Avg Amp Notes Auto'] = calculateMatchAverage(matches, getAmpAuto);
teamToData[team]['Avg Speaker Notes Auto'] = calculateMatchAverage(matches, getSpeakerAuto);
teamToData[team]['Avg Auto Pieces'] = calculateMatchAverage(matches, getAutoPieces);
teamToData[team]['Avg Amp Notes Teleop'] = calculateMatchAverage(matches, getAmpTeleop);
teamToData[team]['Avg Speaker Notes Teleop'] = calculateMatchAverage(matches, getSpeakerTeleop);
teamToData[team]['Avg Shuttled Notes Teleop'] = calculateMatchAverage(matches, getShuttledNotes);
teamToData[team]['Avg Total Speaker Notes Teleop'] = calculateMatchAverage(matches, getTotalSpeakerTeleop);
teamToData[team]['Avg Teleop Pieces'] = calculateMatchAverage(matches, getTeleopPieces);
teamToData[team]['Avg Total Notes'] = calculateMatchAverage(matches, getNotes);
teamToData[team]['Avg Climb Points'] = calculateMatchAverage(matches, getTeleopClimbPoints);
teamToData[team]['Avg Weighted Score'] = calculateMatchAverage(matches, getWeightedScoreFirst);
teamToData[team]['Max Amp Notes Auto'] = calculateMatchMax(matches, getAmpAuto)
teamToData[team]['Max Speaker Notes Auto'] = calculateMatchMax(matches, getSpeakerAuto)
teamToData[team]['Max Auto Pieces'] = calculateMatchMax(matches, getAutoPieces);
teamToData[team]['Max Amp Notes Teleop'] = calculateMatchMax(matches, getAmpTeleop)
teamToData[team]['Max Speaker Notes Teleop'] = calculateMatchMax(matches, getSpeakerTeleop)
teamToData[team]['Max Shuttled Notes Teleop'] = calculateMatchMax(matches, getShuttledNotes)
teamToData[team]['Max Total Sepaker Notes Teleop'] = calculateMatchMax(matches, getSpeakerTeleop)
teamToData[team]['Max Teleop Pieces'] = calculateMatchMax(matches, getTeleopPieces);
teamToData[team]['Max Total Notes'] = calculateMatchMax(matches, getNotes)
teamToData[team]['Max Climb Points'] = calculateMatchMax(matches, getTeleopClimbPoints)
teamToData[team]['Max Weighted Score'] = calculateMatchMax(matches, getWeightedScoreFirst);
}
return teamToData;
}
function initiallyLoadGraph(){
var xTitle = 'Avg Teleop Pieces';
var yTitle = 'Avg Points';
$('#selectXAxis').val(xTitle);
$('#selectYAxis').val(yTitle);
drawChart(xTitle, yTitle);
}
function loadTeamData(teamNumber){
$.get('readAPI.php', {
'readAllMatchData': true
}).done(function(data) {
matchData = JSON.parse(data);
teamData = matchDataToTeamData(matchData);
addSelectOptions();
initiallyLoadGraph();
});
}
$(document).ready(function () {
loadTeamData();
});
$('.graphSelect').change(function (){
var xAxis = $('#selectXAxis').val();
var yAxis = $('#selectYAxis').val();
drawChart(xAxis, yAxis);
});
</script>
</html>