X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=carousel.js;h=0dda4750cfa8f57b2a5809ba4ab03bb1f2b58ad6;hb=f7264a2c41749350b0fdcd6f604170d2f31ebaa3;hp=98724729d5e050bb00f2f8e4d262b3802b88a58e;hpb=55d9ba8633cfe33170ce30e7d8a66f13f6e23acc;p=ultimatescore diff --git a/carousel.js b/carousel.js index 9872472..0dda475 100644 --- a/carousel.js +++ b/carousel.js @@ -1,5 +1,21 @@ 'use strict'; +function jsonclone(x) +{ + return JSON.parse(JSON.stringify(x)); +} + +// Log with deep clone, so that the browser will show the object at time of log, +// instead of what it looks like at time of view. +function dlog() +{ + let args = []; + for (const arg of arguments) { + args.push(jsonclone(arg)); + } + console.log(args); +} + function addheading(carousel, colspan, content) { let thead = document.createElement("thead"); @@ -10,19 +26,21 @@ function addheading(carousel, colspan, content) tr.appendChild(th); thead.appendChild(tr); carousel.appendChild(thead); -}; +} + function addtd(tr, className, content) { let td = document.createElement("td"); td.appendChild(document.createTextNode(content)); td.className = className; tr.appendChild(td); -}; +} + function addth(tr, className, content) { let th = document.createElement("th"); th.appendChild(document.createTextNode(content)); th.className = className; tr.appendChild(th); -}; +} function subrank_partitions(games, parts, start_rank, tiebreakers, func) { let result = []; @@ -391,9 +409,21 @@ function parse_games_from_spreadsheet(response, group_name, include_unplayed) { return games; }; -function apply_games_to_teams(games, teams) +function apply_games_to_teams(games, teams, ignored_teams, ret_ignored_games) { let teams_to_idx = make_teams_to_idx(teams); + let ignored_teams_idx; + if (ignored_teams === undefined) { + ignored_teams_idx = []; + } else { + ignored_teams_idx = make_teams_to_idx(ignored_teams); + } + for (let i = 0; i < teams.length; ++i) { + teams[i].nplayed = 0; + teams[i].goals = 0; + teams[i].gd = 0; + teams[i].pts = 0; + } for (let i = 0; i < games.length; ++i) { let idx1 = teams_to_idx[games[i].name1]; let idx2 = teams_to_idx[games[i].name2]; @@ -403,6 +433,23 @@ function apply_games_to_teams(games, teams) games[i].score1 == games[i].score2) { continue; } + + let ignored_idx1 = ignored_teams_idx[games[i].name1]; + let ignored_idx2 = ignored_teams_idx[games[i].name2]; + if (ignored_idx1 !== undefined || ignored_idx2 !== undefined) { + if (ret_ignored_games !== undefined) { + // Figure out whether the fifth we're ignoring was only picked out arbitrarily + // (ie., there's a tie for 5th); if so, mark it as such. + let arbitrary = false; + if (ignored_idx1 !== undefined && ignored_teams[ignored_idx1].rank < 5) { + arbitrary = true; + } else if (ignored_idx2 !== undefined && ignored_teams[ignored_idx2].rank < 5) { + arbitrary = true; + } + ret_ignored_games.push([teams[idx1].shortname, teams[idx2].shortname, arbitrary]); + } + continue; + } ++teams[idx1].nplayed; ++teams[idx2].nplayed; teams[idx1].goals += games[i].score1; @@ -428,7 +475,7 @@ function filter_teams(teams, response) let idx1 = teams_to_idx[games[i].name1]; let idx2 = teams_to_idx[games[i].name2]; if (idx1 !== undefined) { - ++teams[idx1].ngames; + ++teams[idx1].ngames; // FIXME: shouldn't nplayed be just as good? } if (idx2 !== undefined) { ++teams[idx2].ngames; @@ -711,6 +758,7 @@ function showcarousel() let cb = function(response, group_name) { let teams = parse_teams_from_spreadsheet(response); let games = parse_games_from_spreadsheet(response, group_name, true); + teams = filter_teams(teams, response); teams_per_group[group_name] = teams; games_per_group[group_name] = games; @@ -723,7 +771,7 @@ function showcarousel() [ 13000, function() { display_group_parsed(teams_per_group['Group B'], games_per_group['Group B'], 'Group B'); } ], [ 2000, function() { hidetable(); } ], [ 13000, function() { display_group_parsed(teams_per_group['Group C'], games_per_group['Group C'], 'Group C'); } ], - [ 2000, function() { hidetable(); } ] + [ 2000, function() { hidetable(); } ], [ 13000, function() { display_group_parsed(teams_per_group['Playoffs 9th-13th'], games_per_group['Playoffs 9th-13th'], 'Playoffs 9th–13th'); } ], [ 2000, function() { hidetable(); } ] ];