From 258fdeb237f0c821cfae94442ae94b62ddf2d0af Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Wed, 10 May 2023 22:21:03 +0200 Subject: [PATCH] Add a row for some semi-interesting globals. --- ultimate.js | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) diff --git a/ultimate.js b/ultimate.js index 250f4f7..b56a856 100644 --- a/ultimate.js +++ b/ultimate.js @@ -79,6 +79,19 @@ function process_matches(json) { }; } + // 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; @@ -88,6 +101,7 @@ function process_matches(json) { 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; @@ -133,6 +147,23 @@ function process_matches(json) { } } } + + // 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; } @@ -145,6 +176,9 @@ function process_matches(json) { ++point_num; last_goal = t; } + if (type !== 'out' && game_started === null) { + game_started = t; + } // Pull management if (type === 'pull') { @@ -243,6 +277,12 @@ function process_matches(json) { 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(); @@ -331,6 +371,7 @@ function make_table_general(players) { } 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; @@ -344,6 +385,20 @@ function make_table_general(players) { 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; } @@ -365,7 +420,12 @@ function make_table_offense(players) { 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)); @@ -383,7 +443,32 @@ function make_table_offense(players) { 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; } @@ -400,6 +485,7 @@ function make_table_defense(players) { 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; @@ -442,6 +528,7 @@ function make_table_playing_time(players) { } 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); @@ -451,5 +538,17 @@ function make_table_playing_time(players) { 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; } -- 2.39.2