forked from Paradox2102/roborecon-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
match-intel.html
192 lines (158 loc) · 7.75 KB
/
match-intel.html
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
---
layout: page
permalink: /match-intel/
---
<div class="container">
<div class="row">
<div class="col-md-12" style="padding-left:0;">
<h3>Match: <span id="match-name"></span></h3>
</div>
</div>
<div class="row" style="background-color:#2295C7;">
<div id="blue0" class="col-md-4 ps-match-intel-team">
</div>
<div id="blue1" class="col-md-4 ps-match-intel-team">
</div>
<div id="blue2" class="col-md-4 ps-match-intel-team">
</div>
</div>
<div class="row" style="background-color:#D44829;">
<div id="red0" class="col-md-4 ps-match-intel-team">
</div>
<div id="red1" class="col-md-4 ps-match-intel-team">
</div>
<div id="red2" class="col-md-4 ps-match-intel-team">
</div>
</div>
</div>
<script>
$(function() {
// *** onload ***
var matchName = AppUtility.getUrlParameter('m');
$('#match-name').html(matchName);
var blueAlliance = [ AppUtility.getUrlParameter('b0'), AppUtility.getUrlParameter('b1'), AppUtility.getUrlParameter('b2') ];
var redAlliance = [ AppUtility.getUrlParameter('r0'), AppUtility.getUrlParameter('r1'), AppUtility.getUrlParameter('r2') ];
ParadoxScout.getMatchIntelligence(null, blueAlliance, redAlliance, function(teamData, blueAverages, redAverages) {
// 1. iterate each team's info from TBA & scouting reports
$.each(teamData, function(k,v) {
// used to comparing against their alliance partners
allianceAvgs = (k.startsWith('blue') ? blueAverages : redAverages);
// determine strengths/weaknesses for team
var strengthsWeaknesses = [];
app_match_intel_config.strengths_weaknesses_stats.forEach(function(el) {
// ratings shoule be based on 0-100
var sw_rating = 0.0;
var sw_html = '';
if (el.calc_type === 'avg') {
// ignore ratings=0 for categories with a max value as it indicates they team hasn't been rated for it at all
if (el.max && v[el.id] <= 0.00) return;
// if category has a min/max, divide avg. value by the maximum to return probability as a percentage
if (el.max) {
sw_rating = (v[el.id] / el.max) * 100;
sw_html = `${ sw_rating.toFixed(2) }%`;
}
//
else {
sw_rating = ((v[el.id] / allianceAvgs[el.id]) / 3) * 100;
sw_html = `${ sw_rating.toFixed(2) }%`;
}
}
else if (el.calc_type === 'accuracy') {
// ignore if no attempts
if (v[el.id].made_count === 0 && v[el.id].missed_count === 0) return;
sw_rating = parseFloat(v[el.id].accuracy);
sw_html = `${ v[el.id].accuracy }% ( ${ v[el.id].made_count } | ${ v[el.id].missed_count } )`;
}
strengthsWeaknesses.push({
name: el.title,
calc_type: el.calc_type,
rating: +sw_rating.toFixed(2),
text: sw_html
});
});
// sort strength/weakness ratings in asc. order (weakest to strongest)
strengthsWeaknesses.sort(function(a, b){ return a.rating - b.rating; });
// get top n weaknesses and top n strengths
var n = 4;
var sw_bottom3 = $.grep(strengthsWeaknesses, function (el) { return el.rating < 70; }).slice(0,n);
if (sw_bottom3.length < 1) sw_bottom3.push({ name: 'N/A', text:'' });
var sw_top3 = $.grep(strengthsWeaknesses, function (el) { return el.rating >= 70; }).slice(-n).reverse();
if (sw_top3.length < 1) sw_top3.push({ name: 'N/A', text:'' });
// 2. build team summary html
var $el = $('#' + k);
// build summary_panel
$el.append('<h4 style="float:left;"><a href="{{ site.baseurl }}/team-details?team_id=' + v.team_key + '">Team: ' + v.team_key.replace(/frc/i, '') + '</a></h4>');
var summary_panel_html = '<div style="clear:both;">'
app_match_intel_config.summary_panel.forEach(function(el) {
summary_panel_html += `<p class="pull-left" style="margin:0px 10px 5px 0px;">${el.title}: <span class="label label-default" style="font-size:14px;">${v[el.id]}</span></p>`;
});
$el.append(summary_panel_html + '</div>')
$el.append('<p style="clear:both;text-align:center;margin:5px 0px 5px; 0px;">Pit Stats</p>');
var pit_stats_html = '<table style="width:100%;">'
app_match_intel_config.pit_stats.forEach(function(el) {
var css = ('css' in el) ? ` class="${el.css}"` : ''
if(el.id in v.pit_report){
pit_stats_html += `<tr${css}><td>${el.title}:</td><td>${v.pit_report[el.id]}</td></tr>`;
}else{
pit_stats_html += `<tr${css}><td>${el.title}:</td><td> </td></tr>`;
}
});
$el.append(pit_stats_html + '</table>')
// build match status
$el.append('<p style="clear:both;text-align:center;margin:5px 0px 5px; 0px;">MATCH STATS</p>');
var match_stats_html = '<table style="width:100%;">'
app_match_intel_config.match_stats.forEach(function(el) {
var css = ('css' in el) ? ` class="${el.css}"` : ''
if (el.calc_type === 'accuracy') {
match_stats_html += `<tr${css}><td>${el.title}</td><td class="match-intel-rating-val" data-rating-accuracy="${v[el.id].accuracy}">${v[el.id].accuracy}% ( ${v[el.id].made_count} | ${v[el.id].missed_count} )</td></tr>`
}
else {
match_stats_html += `<tr${css}><td>${el.title}:</td><td>${v[el.id]}</td></tr>`;
}
});
$el.append(match_stats_html + '</table>')
// build team stats
$el.append('<p style="clear:both; text-align:center;margin:5px 0px 5px; 0px;">TEAM STATS</p>');
var team_stats_html = '<table style="width:100%;">'
app_match_intel_config.team_stats.forEach(function(el) {
var css = ('css' in el) ? ` class="${el.css}"` : ''
if (el.calc_type === 'accuracy') {
team_stats_html += `<tr${css}><td>${el.title}</td><td class="match-intel-rating-val" data-rating-accuracy="${v[el.id].accuracy}">${v[el.id].accuracy}% ( ${v[el.id].made_count} | ${v[el.id].missed_count} )</td></tr>`
}
else {
team_stats_html += `<tr${css}><td>${el.title}:</td><td>${v[el.id]}</td></tr>`;
}
});
$el.append(team_stats_html + '</table>')
// build strengths/weakness table
var $weakTbl = $('<table style="width:100%;background-color:#4a0000;">');
for(var i = 0; i < n; i++) {
if (!sw_bottom3[i]) {
$weakTbl.append('<tr><td colspan="2"> </td></tr>');
}
else {
$weakTbl.append('<tr><td>' + sw_bottom3[i].name + ':</td><td class="match-intel-rating-val" data-rating-accuracy="' + sw_bottom3[i].rating + '">' + sw_bottom3[i].text + '</td></tr>');
}
}
$weakTbl.append('</table>');
var $strengthTbl = $('<table style="width:100%;background-color:#013d01;">');
for(var i = 0; i < n; i++) {
if (!sw_top3[i]) {
$strengthTbl.append('<tr><td colspan="2"> </td></tr>');
}
else {
$strengthTbl.append('<tr><td>' + sw_top3[i].name + ':</td><td class="match-intel-rating-val" data-rating-accuracy="' + sw_top3[i].rating + '">' + sw_top3[i].text + '</td></tr>');
}
}
$strengthTbl.append('</table>');
$el.append('<p style="text-align:center;margin:5px 0px 5px; 0px;">STRENGTHS</p>');
$el.append($strengthTbl);
$el.append('<p style="text-align:center;margin:5px 0px 5px; 0px;">WEAKNESSES</p>');
$el.append($weakTbl);
});
// stylize ratings (< 3 then red and >=4 is green)
$('td.match-intel-rating-val').filter(function(el){ return parseFloat($(this).data('rating-accuracy')) >= 70.0; }).css('color', '#6EFF74');
$('td.match-intel-rating-val').filter(function(el){ return parseFloat($(this).data('rating-accuracy')) < 70.0; }).css('color', '#FF0000');
});
});
</script>