]> git.sesse.net Git - pkanalytics/commitdiff
Add a per-point stats category.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Thu, 11 May 2023 15:42:02 +0000 (17:42 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Thu, 11 May 2023 15:42:02 +0000 (17:42 +0200)
ultimate.js

index 7e150b684f45e14ea7983e72320d7c13fb3e2191..d030ec43c9bd6928c7b6a37f18f0630c2e1a3acc 100644 (file)
@@ -316,6 +316,8 @@ function process_matches(json) {
                rows = make_table_defense(players);
        } else if (chosen_category === 'playing_time') {
                rows = make_table_playing_time(players);
+       } else if (chosen_category === 'per_point') {
+               rows = make_table_per_point(players);
        }
        document.getElementById('stats').replaceChildren(...rows);
 }
@@ -327,6 +329,8 @@ function get_chosen_category() {
                return 'defense';
        } else if (window.location.hash === '#playing_time') {
                return 'playing_time';
+       } else if (window.location.hash === '#per_point') {
+               return 'per_point';
        } else {
                return 'general';
        }
@@ -373,6 +377,16 @@ function write_main_menu(chosen_category) {
                elems.push(a);
        }
 
+       elems.push(document.createTextNode(' | '));
+       if (chosen_category === 'per_point') {
+               elems.push(document.createTextNode('Per point'));
+       } else {
+               let a = document.createElement('a');
+               a.appendChild(document.createTextNode('Per point'));
+               a.setAttribute('href', '#per_point');
+               elems.push(a);
+       }
+
        document.getElementById('mainmenu').replaceChildren(...elems);
 }
 
@@ -579,3 +593,76 @@ function make_table_playing_time(players) {
 
        return rows;
 }
+
+function make_table_per_point(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', 'Ds');
+               add_cell(header, 'th', 'Throwaways');
+               add_cell(header, 'th', 'Drops');
+               rows.push(header);
+       }
+
+       let goals = 0;
+       let assists = 0;
+       let hockey_assists = 0;
+       let defenses = 0;
+       let throwaways = 0;
+       let drops = 0;
+       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?
+               if (p.points_played > 0) {
+                       add_cell(row, 'td', p.goals == 0 ? 0 : (p.goals / p.points_played).toFixed(2));
+                       add_cell(row, 'td', p.assists == 0 ? 0 : (p.assists / p.points_played).toFixed(2));
+                       add_cell(row, 'td', p.hockey_assists == 0 ? 0 : (p.hockey_assists / p.points_played).toFixed(2));
+                       add_cell(row, 'td', p.defenses == 0 ? 0 : (p.defenses / p.points_played).toFixed(2));
+                       add_cell(row, 'td', p.throwaways == 0 ? 0 : (p.throwaways / p.points_played).toFixed(2));
+                       add_cell(row, 'td', p.drops == 0 ? 0 : (p.drops / p.points_played).toFixed(2));
+               } else {
+                       add_cell(row, 'td', 'N/A');
+                       add_cell(row, 'td', 'N/A');
+                       add_cell(row, 'td', 'N/A');
+                       add_cell(row, 'td', 'N/A');
+                       add_cell(row, 'td', 'N/A');
+                       add_cell(row, 'td', 'N/A');
+               }
+               rows.push(row);
+
+               goals += p.goals;
+               assists += p.assists;
+               hockey_assists += p.hockey_assists;
+               defenses += p.defenses;
+               throwaways += p.throwaways;
+               drops += p.drops;
+       }
+
+       // Globals.
+       let globals = players['globals'];
+       let row = document.createElement('tr');
+       add_cell(row, 'td', '');
+       if (globals.points_played > 0) {
+               add_cell(row, 'td', goals == 0 ? 0 : (goals / globals.points_played).toFixed(2));
+               add_cell(row, 'td', assists == 0 ? 0 : (assists / globals.points_played).toFixed(2));
+               add_cell(row, 'td', hockey_assists == 0 ? 0 : (hockey_assists / globals.points_played).toFixed(2));
+               add_cell(row, 'td', defenses == 0 ? 0 : (defenses / globals.points_played).toFixed(2));
+               add_cell(row, 'td', throwaways == 0 ? 0 : (throwaways / globals.points_played).toFixed(2));
+               add_cell(row, 'td', drops == 0 ? 0 : (drops / globals.points_played).toFixed(2));
+       } else {
+               add_cell(row, 'td', 'N/A');
+               add_cell(row, 'td', 'N/A');
+               add_cell(row, 'td', 'N/A');
+               add_cell(row, 'td', 'N/A');
+               add_cell(row, 'td', 'N/A');
+               add_cell(row, 'td', 'N/A');
+       }
+       rows.push(row);
+
+       return rows;
+}