]> git.sesse.net Git - pkanalytics/commitdiff
Make a table for the offense category.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Wed, 10 May 2023 17:17:57 +0000 (19:17 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Wed, 10 May 2023 17:17:57 +0000 (19:17 +0200)
ultimate.js

index 798c582bea99043607bb0a89abbc7f8d2365a5dd..e4b0928631b72eb6793a213a96fc56288ab8ed0e 100644 (file)
@@ -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 = [];
        {