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);
}
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';
}
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);
}
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;
+}