tr.appendChild(th);
};
-function subrank_partitions(games, parts, start_rank, tiebreakers) {
+function subrank_partitions(games, parts, start_rank, tiebreakers, func) {
let result = [];
for (let i = 0; i < parts.length; ++i) {
- let part = rank(games, parts[i], start_rank, tiebreakers);
+ let part = func(games, parts[i], start_rank, tiebreakers);
for (let j = 0; j < part.length; ++j) {
result.push(part[j]);
}
// Rule #0: Partition the teams by score.
let score_parts = partition(teams, function(a, b) { return b.pts - a.pts });
if (score_parts.length > 1) {
- return subrank_partitions(games, score_parts, start_rank, tiebreakers);
+ return subrank_partitions(games, score_parts, start_rank, tiebreakers, rank);
}
// Rule #1: Head-to-head wins.
});
if (beat_parts.length > 1) {
tiebreakers.push(explain_tiebreaker(beat_parts, 'head-to-head'));
- return subrank_partitions(games, beat_parts, start_rank, tiebreakers);
+ return subrank_partitions(games, beat_parts, start_rank, tiebreakers, rank);
}
// Rule #2: Number of games played (fewer is better).
let nplayed_parts = partition(teams, function(a, b) { return a.nplayed - b.nplayed });
if (nplayed_parts.length > 1) {
tiebreakers.push(explain_tiebreaker(nplayed_parts, 'fewer losses'));
- return subrank_partitions(games, nplayed_parts, start_rank, tiebreakers);
+ return subrank_partitions(games, nplayed_parts, start_rank, tiebreakers, rank);
}
// Rule #3: Head-to-head goal difference (if all have played).
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);
+ return subrank_partitions(games, h2h_gd_parts, start_rank, tiebreakers, rank);
}
}
});
if (gd_parts.length > 1) {
tiebreakers.push(explain_tiebreaker(gd_parts, 'goal difference versus common opponents'));
- return subrank_partitions(games, gd_parts, start_rank, tiebreakers);
+ return subrank_partitions(games, gd_parts, start_rank, tiebreakers, rank);
}
// Rule #5: Head-to-head scored goals (if all have played).
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);
+ return subrank_partitions(games, h2h_goals_parts, start_rank, tiebreakers, rank);
}
}
});
if (goals_parts.length > 1) {
tiebreakers.push(explain_tiebreaker(goals_parts, 'goals scored against common opponents'));
- return subrank_partitions(games, goals_parts, start_rank, tiebreakers);
+ return subrank_partitions(games, goals_parts, start_rank, tiebreakers, rank);
+ }
+
+ // OK, it's a tie. Give them all the same rank.
+ let result = [];
+ for (let i = 0; i < teams.length; ++i) {
+ result.push(teams[i]);
+ result[i].rank = start_rank;
+ }
+ return result;
+};
+
+// Same, but with the simplified rules for ranking thirds. games isn't used and can be empty.
+function rank_thirds(games, teams, start_rank, tiebreakers) {
+ if (teams.length <= 1) {
+ // Only one team, so trivial.
+ teams[0].rank = start_rank;
+ return teams;
+ }
+
+ // Rule #1: Partition the teams by score.
+ let score_parts = partition(teams, function(a, b) { return b.pts - a.pts });
+ if (score_parts.length > 1) {
+ tiebreakers.push(explain_tiebreaker(score_parts, 'most games won'));
+ return subrank_partitions(games, score_parts, start_rank, tiebreakers, rank_thirds);
+ }
+
+ // Rule #2: Goal difference against common opponents.
+ let gd_parts = partition(teams, function(a, b) { return b.gd - a.gd });
+ if (gd_parts.length > 1) {
+ tiebreakers.push(explain_tiebreaker(gd_parts, 'goal difference'));
+ return subrank_partitions(games, gd_parts, start_rank, tiebreakers, rank_thirds);
+ }
+
+ // Rule #3: Goals scored.
+ let goal_parts = partition(teams, function(a, b) { return b.goals - a.goals });
+ if (goal_parts.length > 1) {
+ tiebreakers.push(explain_tiebreaker(goal_parts, 'goals scored'));
+ return subrank_partitions(games, goal_parts, start_rank, tiebreakers, rank_thirds);
}
// OK, it's a tie. Give them all the same rank.
{
let teams = [];
let games = [];
- let num_left = 3;
+ let num_left = 4;
let cb = function(response, group_name) {
teams = teams.concat(parse_teams_from_spreadsheet(response));
let games_per_group = [];
let combined_teams = [];
let combined_games = [];
- let num_left = 3;
+ let num_left = 4;
let cb = function(response, group_name) {
let teams = parse_teams_from_spreadsheet(response);
document.getElementById('scorebug2').style = css;
document.getElementById('clockbug2').style = css;
}
+
+function showmatch3()
+{
+ let css = "-webkit-animation: fade-in 1.0s ease; -webkit-animation-fill-mode: both;";
+ document.getElementById('scorebug3').style = css;
+ document.getElementById('clockbug3').style = css;
+}
+
+function hidematch3()
+{
+ let css = "-webkit-animation: fade-out 1.0s ease; -webkit-animation-fill-mode: both;";
+ document.getElementById('scorebug3').style = css;
+ document.getElementById('clockbug3').style = css;
+}