};
}
+ // Globals.
+ players['globals'] = {
+ 'points_played': 0,
+ 'playing_time_ms': 0,
+ 'field_time_ms': 0,
+
+ 'offensive_points_completed': 0,
+ 'offensive_points_won': 0,
+ 'defensive_points_completed': 0,
+ 'defensive_points_won': 0,
+ };
+ let globals = players['globals'];
+
for (const match of json['matches']) {
let handler = null;
let prev_handler = null;
let pull_started = null;
let last_pull_was_ours = null; // Effectively whether we're playing an O or D point (not affected by turnovers).
let point_num = 0;
+ let game_started = null;
let last_goal = null;
for (const [q,p] of Object.entries(players)) {
p.on_field_since = null;
}
}
}
+
+ // Update globals.
+ ++globals.points_played;
+ if (live_since !== null) {
+ globals.playing_time_ms += t - live_since;
+ }
+ if (last_pull_was_ours === true) { // D point.
+ ++globals.defensive_points_completed;
+ if (type === 'goal') {
+ ++globals.defensive_points_won;
+ }
+ } else if (last_pull_was_ours === false) { // O point.
+ ++globals.offensive_points_completed;
+ if (type === 'goal') {
+ ++globals.offensive_points_won;
+ }
+ }
live_since = null;
}
++point_num;
last_goal = t;
}
+ if (type !== 'out' && game_started === null) {
+ game_started = t;
+ }
// Pull management
if (type === 'pull') {
p.field_time_ms += last_goal - p.on_field_since;
}
}
+ if (game_started !== null && last_goal !== null) {
+ globals.field_time_ms += last_goal - game_started;
+ }
+ if (live_since !== null && last_goal !== null) {
+ globals.playing_time_ms += last_goal - live_since;
+ }
}
let chosen_category = get_chosen_category();
}
for (const [q,p] of Object.entries(players)) {
+ if (q === 'globals') continue;
let row = document.createElement('tr');
let pm = p.goals + p.assists + p.hockey_assists + p.defenses - p.throwaways - p.drops;
let soft_pm = p.offensive_soft_plus + p.defensive_soft_plus - p.offensive_soft_minus - p.defensive_soft_minus;
add_cell(row, 'td', p.points_played);
rows.push(row);
}
+
+ // Globals.
+ let globals = players['globals'];
+ let o_efficiency = (globals.offensive_points_won / globals.offensive_points_completed) * 2 - 1;
+ let d_efficiency = (globals.defensive_points_won / globals.defensive_points_completed) * 2 - 1;
+ let row = document.createElement('tr');
+ add_cell(row, 'td', '');
+ add_cell(row, 'td', '');
+ add_cell(row, 'td', '');
+ add_cell(row, 'td', globals.offensive_points_completed > 0 ? o_efficiency.toFixed(2) : 'N/A');
+ add_cell(row, 'td', globals.defensive_points_completed > 0 ? d_efficiency.toFixed(2) : 'N/A');
+ add_cell(row, 'td', globals.points_played);
+ rows.push(row);
+
return rows;
}
rows.push(header);
}
+ let num_throws = 0;
+ let throwaways = 0;
+ let catches = 0;
+ let drops = 0;
for (const [q,p] of Object.entries(players)) {
+ if (q === 'globals') continue;
let throw_ok = 100 * (1 - p.throwaways / p.num_throws);
let catch_ok = 100 * (p.catches / (p.catches + p.drops));
add_cell(row, 'td', '+' + p.offensive_soft_plus);
add_cell(row, 'td', '-' + p.offensive_soft_minus);
rows.push(row);
+
+ num_throws += p.num_throws;
+ throwaways += p.throwaways;
+ catches += p.catches;
+ drops += p.drops;
}
+
+ // Globals.
+ let throw_ok = 100 * (1 - throwaways / num_throws);
+ let catch_ok = 100 * (catches / (catches + drops));
+
+ let row = document.createElement('tr');
+ add_cell(row, 'td', '');
+ add_cell(row, 'td', '');
+ add_cell(row, 'td', '');
+ add_cell(row, 'td', '');
+ add_cell(row, 'td', num_throws);
+ add_cell(row, 'td', throwaways);
+ add_cell(row, 'td', throw_ok.toFixed(0) + '%');
+ add_cell(row, 'td', catches);
+ add_cell(row, 'td', drops);
+ add_cell(row, 'td', catch_ok.toFixed(0) + '%');
+ add_cell(row, 'td', '');
+ add_cell(row, 'td', '');
+ rows.push(row);
+
return rows;
}
rows.push(header);
}
for (const [q,p] of Object.entries(players)) {
+ if (q === 'globals') continue;
let sum_time = 0;
for (const t of p.pull_times) {
sum_time += t;
}
for (const [q,p] of Object.entries(players)) {
+ if (q === 'globals') continue;
let row = document.createElement('tr');
add_cell(row, 'td', p.name); // TODO: number?
add_cell(row, 'td', p.points_played);
add_cell(row, 'td', p.defensive_points_completed);
rows.push(row);
}
+
+ // Globals.
+ let globals = players['globals'];
+ let row = document.createElement('tr');
+ add_cell(row, 'td', '');
+ add_cell(row, 'td', globals.points_played);
+ add_cell(row, 'td', Math.floor(globals.playing_time_ms / 60000) + ' min');
+ add_cell(row, 'td', Math.floor(globals.field_time_ms / 60000) + ' min');
+ add_cell(row, 'td', globals.offensive_points_completed);
+ add_cell(row, 'td', globals.defensive_points_completed);
+ rows.push(row);
+
return rows;
}