X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=carousel.js;h=35b02883c7d91809e89e5ec891e10733c9595c83;hb=3c3a5c028bed3922840a2b5ad7ab861fca092582;hp=fcf5cc5178862d82dc88ebfbd1db9e47686e0c0c;hpb=e6f6d97706538a174b9f3e0539ed68ca4d28cc71;p=ultimatescore diff --git a/carousel.js b/carousel.js index fcf5cc5..35b0288 100644 --- a/carousel.js +++ b/carousel.js @@ -69,6 +69,8 @@ function make_teams_to_idx(teams) let teams_to_idx = []; for (let i = 0; i < teams.length; i++) { teams_to_idx[teams[i].name] = i; + teams_to_idx[teams[i].mediumname] = i; + teams_to_idx[teams[i].shortname] = i; } return teams_to_idx; } @@ -154,6 +156,7 @@ function rank(games, teams, start_rank, tiebreakers) { } // Rule #1: Head-to-head wins. + let num_relevant_games = 0; let beat_parts = partition_by_beat(teams, function(beat, teams_to_idx) { for (let i = 0; i < games.length; ++i) { let idx1 = teams_to_idx[games[i].name1]; @@ -161,9 +164,10 @@ function rank(games, teams, start_rank, tiebreakers) { if (idx1 !== undefined && idx2 !== undefined) { if (games[i].score1 > games[i].score2) { beat[idx1][idx2] = 1; - } - if (games[i].score1 < games[i].score2) { + ++num_relevant_games; + } else if (games[i].score1 < games[i].score2) { beat[idx2][idx1] = 1; + ++num_relevant_games; } } } @@ -182,30 +186,32 @@ function rank(games, teams, start_rank, tiebreakers) { return subrank_partitions(games, nplayed_parts, start_rank, tiebreakers); } - // Rule #3: Head-to-head goal difference. + // Rule #3: Head-to-head goal difference (if all have played). let teams_to_idx = make_teams_to_idx(teams); - for (let i = 0; i < teams.length; i++) { - teams[i].h2h_gd = 0; - teams[i].h2h_goals = 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]; - if (idx1 !== undefined && idx2 !== undefined && - !isNaN(games[i].score1) && !isNaN(games[i].score2)) { - teams[idx1].h2h_gd += games[i].score1; - teams[idx1].h2h_gd -= games[i].score2; - teams[idx2].h2h_gd += games[i].score2; - teams[idx2].h2h_gd -= games[i].score1; - - teams[idx1].h2h_goals += games[i].score1; - teams[idx2].h2h_goals += games[i].score2; + if (num_relevant_games >= teams.length * (teams.length - 1) / 2) { + for (let i = 0; i < teams.length; i++) { + teams[i].h2h_gd = 0; + teams[i].h2h_goals = 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]; + if (idx1 !== undefined && idx2 !== undefined && + !isNaN(games[i].score1) && !isNaN(games[i].score2)) { + teams[idx1].h2h_gd += games[i].score1; + teams[idx1].h2h_gd -= games[i].score2; + teams[idx2].h2h_gd += games[i].score2; + teams[idx2].h2h_gd -= games[i].score1; + + teams[idx1].h2h_goals += games[i].score1; + teams[idx2].h2h_goals += games[i].score2; + } + } + let h2h_gd_parts = partition(teams, function(a, b) { return b.h2h_gd - a.h2h_gd }); + if (h2h_gd_parts.length > 1) { + tiebreakers.push(explain_tiebreaker(h2h_gd_parts, 'head-to-head goal difference')); + return subrank_partitions(games, h2h_gd_parts, start_rank, tiebreakers); } - } - let h2h_gd_parts = partition(teams, function(a, b) { return b.h2h_gd - a.h2h_gd }); - if (h2h_gd_parts.length > 1) { - tiebreakers.push(explain_tiebreaker(h2h_gd_parts, 'head-to-head goal difference')); - return subrank_partitions(games, h2h_gd_parts, start_rank, tiebreakers); } // Rule #4: Goal difference against common opponents. @@ -231,7 +237,7 @@ function rank(games, teams, start_rank, tiebreakers) { // See if the two teams have both played a third team k. for (let k in results_i) { if (!results_i.hasOwnProperty(k)) continue; - if (results_j[k] !== undefined) { + if (results_j !== undefined && results_j[k] !== undefined) { gd_i += results_i[k][0] - results_i[k][1]; gd_j += results_j[k][0] - results_j[k][1]; } @@ -250,11 +256,13 @@ function rank(games, teams, start_rank, tiebreakers) { return subrank_partitions(games, gd_parts, start_rank, tiebreakers); } - // Rule #5: Head-to-head scored goals. - let h2h_goals_parts = partition(teams, function(a, b) { return b.h2h_goals - a.h2h_goals }); - if (h2h_goals_parts.length > 1) { - tiebreakers.push(explain_tiebreaker(h2h_goals_parts, 'head-to-head scored goals')); - return subrank_partitions(games, h2h_goals_parts, start_rank, tiebreakers); + // Rule #5: Head-to-head scored goals (if all have played). + if (num_relevant_games >= teams.length * (teams.length - 1) / 2) { + let h2h_goals_parts = partition(teams, function(a, b) { return b.h2h_goals - a.h2h_goals }); + if (h2h_goals_parts.length > 1) { + tiebreakers.push(explain_tiebreaker(h2h_goals_parts, 'head-to-head scored goals')); + return subrank_partitions(games, h2h_goals_parts, start_rank, tiebreakers); + } } // Rule #6: Goals scored against common opponents. @@ -269,7 +277,7 @@ function rank(games, teams, start_rank, tiebreakers) { // See if the two teams have both played a third team k. for (let k in results_i) { if (!results_i.hasOwnProperty(k)) continue; - if (results_j[k] !== undefined) { + if (results_j !== undefined && results_j[k] !== undefined) { goals_i += results_i[k][0]; goals_j += results_j[k][0]; } @@ -344,17 +352,8 @@ function parse_games_from_spreadsheet(response, group_name, include_unplayed) { return games; }; -function display_group(response, group_name) +function apply_games_to_teams(games, teams) { - let teams = parse_teams_from_spreadsheet(response); - let games = parse_games_from_spreadsheet(response, group_name, false); - display_group_parsed(teams, games, group_name); -}; - -function display_group_parsed(teams, games, group_name) -{ - document.getElementById('entire-bug').style.display = 'none'; - let teams_to_idx = make_teams_to_idx(teams); for (let i = 0; i < games.length; ++i) { let idx1 = teams_to_idx[games[i].name1]; @@ -379,14 +378,20 @@ function display_group_parsed(teams, games, group_name) teams[idx2].pts += 2; } } +} +function display_group_parsed(teams, games, group_name) +{ + document.getElementById('entire-bug').style.display = 'none'; + + apply_games_to_teams(games, teams); let tiebreakers = []; teams = rank(games, teams, 1, tiebreakers); let carousel = document.getElementById('carousel'); clear_carousel(carousel); - addheading(carousel, 5, "Current standings, Trøndisk 2017
" + group_name); + addheading(carousel, 5, "Current standings
" + group_name); let tr = document.createElement("tr"); tr.className = "subfooter"; addth(tr, "rank", ""); @@ -422,7 +427,7 @@ function display_group_parsed(teams, games, group_name) let footer_tr = document.createElement("tr"); footer_tr.className = "footer"; let td = document.createElement("td"); - td.appendChild(document.createTextNode("www.trondheimfrisbeeklubb.no | #trøndisk")); + td.appendChild(document.createTextNode("Norwegian Ultimate Championships 2018 | #ultimatenm")); td.setAttribute("colspan", "5"); footer_tr.appendChild(td); carousel.appendChild(footer_tr); @@ -464,7 +469,7 @@ function clear_carousel(table) }; // Stream schedule -let max_list_len = 8; +let max_list_len = 7; function display_stream_schedule(response, group_name) { let teams = parse_teams_from_spreadsheet(response); @@ -536,7 +541,7 @@ function display_stream_schedule_parsed(teams, games, page) { let carousel = document.getElementById('carousel'); clear_carousel(carousel); - addheading(carousel, 3, "Stream schedule, Trøndisk 2017
" + covered_days.join('/') + " (all times CET)"); + addheading(carousel, 3, "Match schedule
" + covered_days.join('/') + " (all times CET)"); let teams_to_idx = make_teams_to_idx(teams); row_num = 0; @@ -576,19 +581,25 @@ function get_group(group_name, cb) req.onload = function(e) { cb(JSON.parse(req.responseText), group_name); }; - req.open('GET', 'https://sheets.googleapis.com/v4/spreadsheets/122tIwrXTi5ug0Vv6Np5w3pVwEWE2KkjWxtzQQfGtOZA/values/\'' + group_name + '\'!A1:J50?key=AIzaSyAuP9yQn8g0bSay6r_RpGtpFeIbwprH1TU'); + req.open('GET', 'https://sheets.googleapis.com/v4/spreadsheets/1uh7kr5v_hyD072b1G2tbQlhqd_8ldS_6j30CBocQ-4E/values/\'' + group_name + '\'!A1:J50?key=AIzaSyAuP9yQn8g0bSay6r_RpGtpFeIbwprH1TU'); req.send(); -}; +} function showgroup(group_name) { - get_group(group_name, display_group); -}; + get_group(group_name, function(response, group_name) { + let teams = parse_teams_from_spreadsheet(response); + let games = parse_games_from_spreadsheet(response, group_name, false); + display_group_parsed(teams, games, group_name); + }); + publish_group_rank(group_name); // Update the spreadsheet in the background. +} + function showgroup_from_state() { showgroup(state['group_name']); -}; +} let carousel_timeout = null;