]> git.sesse.net Git - ultimatescore/blobdiff - update_sheets.js
Make the roster scripts executable.
[ultimatescore] / update_sheets.js
index 9a1fff4531abbfe116f6d1d2cf55795092f54d29..24381358ed52713cca0f129ef5ac424cccede69e 100644 (file)
@@ -72,6 +72,7 @@ function publish_group_rank(teams, games, group_name)
        let cols = config['score_sheet_cols'];
 
        apply_games_to_teams(games, teams, group_name);
+       teams.sort(function(a, b) { return a.seeding - b.seeding });
 
        // Write the points total to the unsorted columns.
        if (config['point_total_start_row'] !== null) {
@@ -247,7 +248,9 @@ function montecarlo(all_teams, groups, games, groups_to_calc) {
                                third_groups = ranked;
                        } else {
                                for (let i = 0; i < groups_to_calc.length; ++i) {
-                                       if (third_groups[i].group_idx !== ranked[i].group_idx) {
+                                       if (third_groups[i].group_idx !== ranked[i].group_idx ||  // Different from a previous simulation.
+                                           (i < (third_groups.length - 1) && ranked[i].rank === ranked[i + 1].rank) ||  // Disallow ties.
+                                           (i > 0 && ranked[i].rank === ranked[i - 1].rank)) {  // Disallow ties.
                                                third_groups[i].group_idx = null;
                                        }
                                }
@@ -262,6 +265,26 @@ function montecarlo(all_teams, groups, games, groups_to_calc) {
                }
        }
 
+       // These are pretty hard-coded, but that's probably fine. Must come after we've concretized X, Y, etc.
+       for (const group_name of real_group_names) {
+               let teams = filter_teams_by_group(all_teams, groups, 'Group ' + group_name);
+               if (teams.length >= 5) {
+                       for (const other_group_name of real_group_names) {
+                               replacements.push([ group_name + other_group_name + '5', group_name + '5' ]);
+                       }
+                       for (const other_group_name of pseudo_group_names) {
+                               replacements.push([ group_name + other_group_name + '5', group_name + '5' ]);
+                       }
+               } else {  // Perhaps a bit overkill.
+                       for (const other_group_name of real_group_names) {
+                               replacements.push([ group_name + other_group_name + '5', other_group_name + '5' ]);
+                       }
+                       for (const other_group_name of pseudo_group_names) {
+                               replacements.push([ group_name + other_group_name + '5', other_group_name + '5' ]);
+                       }
+               }
+       }
+
        for (let group_idx = 0; group_idx < groups_to_calc.length; ++group_idx) {
                for (let i = 0; i < teams[group_idx].length; ++i) {
                        if (teams[group_idx][i].simulated_rank !== null) {
@@ -295,7 +318,7 @@ function do_replacements(str, replacements) {
        return str;
 }
 
-function fill_playoff(all_teams, groups, replacements, teams) {
+function fill_playoff(all_teams, groups, replacements) {
        let team_expansions = {};
        for (const team of all_teams) {
                team_expansions[team.name] = team_expansions[team.mediumname] = team_expansions[team.shortname] =
@@ -371,6 +394,8 @@ function fill_playoff(all_teams, groups, replacements, teams) {
                                        get_all_group_games(all_teams, groups, function(group_games) {
                                                // NOTE: filter_teams_by_group will be delayed by one cycle
                                                // after W P1 etc. becomes determined for the first time.
+                                               // Note that this requires the Groups sheet to pick out
+                                               // the right teams from the group matches in the Results sheet!
                                                let teams_l1 = filter_teams_by_group(all_teams, groups, 'Playoffs 9th–11th');
                                                let teams_l2 = filter_teams_by_group(all_teams, groups, 'Playoffs 12th–14th');
                                                publish_group_rank(teams_l1, group_games, 'Playoffs 9th–11th');
@@ -407,7 +432,7 @@ function publish_group_ranks() {
                                publish_group_rank(teams_c, games, 'Group C');
 
                                let replacements = montecarlo(teams, groups, games, ['Group A', 'Group B', 'Group C']);
-                               fill_playoff(teams, groups, replacements, [teams_a, teams_b, teams_c]);
+                               fill_playoff(teams, groups, replacements);
                        });
                });
        });
@@ -415,6 +440,7 @@ function publish_group_ranks() {
 
 function get_all_playoff_games(teams, groups, group_games, cb) {
        let replacements = montecarlo(teams, groups, group_games, ['Group A', 'Group B', 'Group C']);
+       fill_playoff(teams, groups, replacements);  // To get the replacements.
        let games = ultimateconfig['playoff_games'];
        get_results('Results', function(response) {
                let playoff_games = [];