// No frameworks, no compilers, no npm, just JavaScript. :-)
-let json;
+let global_json;
+addEventListener('hashchange', () => { console.log('heei'); process_matches(global_json); });
fetch('ultimate.json')
.then(response => response.json())
- .then(response => { process_matches(response); });
+ .then(response => { global_json = response; process_matches(global_json); });
function attribute_player_time(player, to, from) {
if (player.on_field_since > from) {
} else if (type === 'offensive_soft_plus' || type === 'offensive_soft_minus' || type === 'defensive_soft_plus' || type === 'defensive_soft_minus') {
++p[type];
} else if (type !== 'in' && type !== 'out' && type !== 'pull' &&
- type !== 'their_pull' && type !== 'restart' && type !== 'goal' &&
type !== 'their_goal' && type !== 'stoppage' && type !== 'unknown' &&
type !== 'set_defense' && type !== 'goal' && type !== 'throwaway' &&
type !== 'drop' && type !== 'set_offense' && type !== 'their_goal' &&
}
}
+ let chosen_category = get_chosen_category();
+ write_main_menu(chosen_category);
+
let rows = [];
+ if (chosen_category === 'general') {
+ rows = make_table_general(players);
+ } else if (chosen_category === 'pulls') {
+ console.log("PULL STATS");
+ for (const [q,p] of Object.entries(players)) {
+ if (p.pulls === 0) {
+ continue;
+ }
+ let sum_time = 0;
+ for (const t of p.pull_times) {
+ sum_time += t;
+ }
+ let avg_time = 1e-3 * sum_time / p.pulls;
+ let msg = p.name + ' did ' + p.pulls + ' pull(s), ' + p.oob_pulls + ' OOB';
+ if (p.oob_pulls < p.pulls) {
+ msg += ', avg. hangtime ' + avg_time.toFixed(1) + ' sec for others';
+ }
+ console.log(msg, p.pull_times);
+ }
+ }
+ document.getElementById('stats').replaceChildren(...rows);
+}
+function get_chosen_category() {
+ if (window.location.hash === '#pulls') {
+ return 'pulls';
+ } else {
+ return 'general';
+ }
+}
+
+function write_main_menu(chosen_category) {
+ let elems = [];
+ if (chosen_category === 'general') {
+ elems.push(document.createTextNode('General'));
+ } else {
+ let a = document.createElement('a');
+ a.appendChild(document.createTextNode('General'));
+ a.setAttribute('href', '#general');
+ elems.push(a);
+ }
+ elems.push(document.createTextNode(' | '));
+ if (chosen_category === 'pulls') {
+ elems.push(document.createTextNode('Pulls'));
+ } else {
+ let a = document.createElement('a');
+ a.appendChild(document.createTextNode('Pulls'));
+ a.setAttribute('href', '#pulls');
+ elems.push(a);
+ }
+ document.getElementById('mainmenu').replaceChildren(...elems);
+}
+
+function make_table_general(players) {
+ let rows = [];
{
let header = document.createElement('tr');
add_cell(header, 'th', 'Player');
rows.push(row);
console.log(p.name + " played " + p.points_played + " points (" + Math.floor(p.playing_time_ms / 60000) + " min), " + p.goals + " goals, " + p.assists + " assists, plus/minus: " + pm);
}
- document.getElementById('stats').replaceChildren(...rows);
-
- console.log("PULL STATS");
- for (const [q,p] of Object.entries(players)) {
- if (p.pulls === 0) {
- continue;
- }
- let sum_time = 0;
- for (const t of p.pull_times) {
- sum_time += t;
- }
- let avg_time = 1e-3 * sum_time / p.pulls;
- let msg = p.name + ' did ' + p.pulls + ' pull(s), ' + p.oob_pulls + ' OOB';
- if (p.oob_pulls < p.pulls) {
- msg += ', avg. hangtime ' + avg_time.toFixed(1) + ' sec for others';
- }
- console.log(msg, p.pull_times);
- }
+ return rows;
}