From: Steinar H. Gunderson Date: Wed, 10 May 2023 17:17:57 +0000 (+0200) Subject: Make a table for the offense category. X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=6fb60809d0eb0c5f39f418668bd02320a7382b81;p=pkanalytics Make a table for the offense category. --- diff --git a/ultimate.js b/ultimate.js index 798c582..e4b0928 100644 --- a/ultimate.js +++ b/ultimate.js @@ -160,6 +160,7 @@ function process_matches(json) { handler = e['player']; } } else if (type === 'throwaway') { + ++p.num_throws; ++p.throwaways; handler = prev_handler = null; } else if (type === 'drop') { @@ -192,6 +193,8 @@ function process_matches(json) { let rows = []; if (chosen_category === 'general') { rows = make_table_general(players); + } else if (chosen_category === 'offense') { + rows = make_table_offense(players); } else if (chosen_category === 'pulls') { rows = make_table_pulls(players); } @@ -201,6 +204,8 @@ function process_matches(json) { function get_chosen_category() { if (window.location.hash === '#pulls') { return 'pulls'; + } else if (window.location.hash === '#offense') { + return 'offense'; } else { return 'general'; } @@ -216,6 +221,7 @@ function write_main_menu(chosen_category) { a.setAttribute('href', '#general'); elems.push(a); } + elems.push(document.createTextNode(' | ')); if (chosen_category === 'pulls') { elems.push(document.createTextNode('Pulls')); @@ -225,6 +231,17 @@ function write_main_menu(chosen_category) { a.setAttribute('href', '#pulls'); elems.push(a); } + + elems.push(document.createTextNode(' | ')); + if (chosen_category === 'offense') { + elems.push(document.createTextNode('Offense')); + } else { + let a = document.createElement('a'); + a.appendChild(document.createTextNode('Offense')); + a.setAttribute('href', '#offense'); + elems.push(a); + } + document.getElementById('mainmenu').replaceChildren(...elems); } @@ -255,6 +272,46 @@ function make_table_general(players) { return rows; } +function make_table_offense(players) { + let rows = []; + { + let header = document.createElement('tr'); + add_cell(header, 'th', 'Player'); + add_cell(header, 'th', 'Goals'); + add_cell(header, 'th', 'Assists'); + add_cell(header, 'th', 'Hockey assists'); + add_cell(header, 'th', 'Throws'); + add_cell(header, 'th', 'Throwaways'); + add_cell(header, 'th', '%OK'); + add_cell(header, 'th', 'Catches'); + add_cell(header, 'th', 'Drops'); + add_cell(header, 'th', '%OK'); + add_cell(header, 'th', 'Soft +/-'); + rows.push(header); + } + + for (const [q,p] of Object.entries(players)) { + let throw_ok = 100 * (1 - p.throwaways / p.num_throws); + let catch_ok = 100 * (p.catches / (p.catches + p.drops)); + + let row = document.createElement('tr'); + add_cell(row, 'td', p.name); // TODO: number? + add_cell(row, 'td', p.goals); + add_cell(row, 'td', p.assists); + add_cell(row, 'td', p.hockey_assists); + add_cell(row, 'td', p.num_throws); + add_cell(row, 'td', p.throwaways); + add_cell(row, 'td', throw_ok.toFixed(0) + '%'); + add_cell(row, 'td', p.catches); + add_cell(row, 'td', p.drops); + add_cell(row, 'td', catch_ok.toFixed(0) + '%'); + add_cell(row, 'td', '+' + p.offensive_soft_plus); + add_cell(row, 'td', '-' + p.offensive_soft_minus); + rows.push(row); + } + return rows; +} + function make_table_pulls(players) { let rows = []; {