]> git.sesse.net Git - ultimatescore/blobdiff - carousel.js
Add a comment about what “Mark game” means.
[ultimatescore] / carousel.js
index 3147c54e8b4ac63b7e341f36f6813ff6fee9e7ed..00760310e3f5d5ed657bb3f2fc9022ff9681e9d8 100644 (file)
@@ -24,10 +24,10 @@ function addth(tr, className, content) {
        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]);
                }
@@ -152,7 +152,7 @@ function rank(games, teams, start_rank, tiebreakers) {
        // 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.
@@ -174,7 +174,7 @@ function rank(games, teams, start_rank, tiebreakers) {
        });
        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).
@@ -183,7 +183,7 @@ function rank(games, teams, start_rank, tiebreakers) {
        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).
@@ -210,7 +210,7 @@ function rank(games, teams, 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);
+                       return subrank_partitions(games, h2h_gd_parts, start_rank, tiebreakers, rank);
                }
        }
 
@@ -253,7 +253,7 @@ function rank(games, teams, start_rank, tiebreakers) {
        });
        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).
@@ -261,7 +261,7 @@ function rank(games, teams, start_rank, tiebreakers) {
                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);
                }
        }
 
@@ -293,7 +293,45 @@ function rank(games, teams, start_rank, tiebreakers) {
        });
        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.
@@ -391,7 +429,7 @@ function display_group_parsed(teams, games, group_name)
        let carousel = document.getElementById('carousel');
        clear_carousel(carousel);
 
-       addheading(carousel, 5, "Current standings<br />" + group_name);
+       addheading(carousel, 5, "Current standings, " + ultimateconfig['tournament_title'] + "<br />" + group_name);
        let tr = document.createElement("tr");
        tr.className = "subfooter";
        addth(tr, "rank", "");
@@ -427,7 +465,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("Norwegian Ultimate Championships 2018 | #ultimatenm"));
+       td.appendChild(document.createTextNode(ultimateconfig['tournament_footer']));
        td.setAttribute("colspan", "5");
        footer_tr.appendChild(td);
        carousel.appendChild(footer_tr);
@@ -469,7 +507,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);
@@ -541,7 +579,7 @@ function display_stream_schedule_parsed(teams, games, page) {
        
        let carousel = document.getElementById('carousel');
        clear_carousel(carousel);
-       addheading(carousel, 3, "Match schedule<br />" + covered_days.join('/') + " (all times CET)");
+       addheading(carousel, 3, "Stream schedule, " + ultimateconfig['tournament_title'] + "<br />" + covered_days.join('/') + " (all times CET)");
 
        let teams_to_idx = make_teams_to_idx(teams);
        row_num = 0;
@@ -581,7 +619,7 @@ 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/1uh7kr5v_hyD072b1G2tbQlhqd_8ldS_6j30CBocQ-4E/values/\'' + group_name + '\'!A1:J50?key=AIzaSyAuP9yQn8g0bSay6r_RpGtpFeIbwprH1TU');
+       req.open('GET', 'https://sheets.googleapis.com/v4/spreadsheets/' + ultimateconfig['score_sheet_id'] + '/values/\'' + group_name + '\'!A1:J50?key=' + ultimateconfig['api_key']);
        req.send();
 }
 
@@ -612,7 +650,7 @@ function showschedule(page)
 {
        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));
@@ -624,6 +662,7 @@ function showschedule(page)
 
        get_group('Group A', cb);
        get_group('Group B', cb);
+       get_group('Group C', cb);
        get_group('Playoffs', cb);
 };
 
@@ -646,7 +685,7 @@ function showcarousel()
        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);
@@ -661,6 +700,8 @@ function showcarousel()
                                [ 13000, function() { display_group_parsed(teams_per_group['Group A'], games_per_group['Group A'], 'Group A'); } ],
                                [ 2000, function() { hidetable(); } ],
                                [ 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(); } ]
                        ];
                        let num_pages = find_num_pages(combined_games);
@@ -675,6 +716,7 @@ function showcarousel()
 
        get_group('Group A', cb);
        get_group('Group B', cb);
+       get_group('Group C', cb);
        get_group('Playoffs', cb);
 };
 
@@ -695,5 +737,32 @@ function hidescorebug()
 function showscorebug()
 {
        document.getElementById('entire-bug').style.display = null;
-};
+}
 
+function showmatch2()
+{
+       let css = "-webkit-animation: fade-in 1.0s ease; -webkit-animation-fill-mode: both;";
+       document.getElementById('scorebug2').style = css;
+       document.getElementById('clockbug2').style = css;
+}
+
+function hidematch2()
+{
+       let css = "-webkit-animation: fade-out 1.0s ease; -webkit-animation-fill-mode: both;";
+       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;
+}