]> git.sesse.net Git - ultimatescore/blobdiff - update_sheets.js
Support having a second scorebug for a second BT6000-controlled match.
[ultimatescore] / update_sheets.js
index 2a2461b00cc258fe400c78e96d539006659b9c40..d9757b21bee385b92276b05dc5cc3f9cab171d89 100644 (file)
@@ -68,26 +68,31 @@ function possibly_update_oauth_key(cb) {
 function publish_group_rank(group_name)
 {
        get_group(group_name, function(response, group_name) {
+               let updates = [];
+               let cols = ["Results!B", "Results!C", "Results!D"];
+               if (group_name === 'Group B') {
+                       cols = ["Results!F", "Results!G", "Results!H"];
+               }
+
                let teams = parse_teams_from_spreadsheet(response);
                let games = parse_games_from_spreadsheet(response, group_name, false);
                apply_games_to_teams(games, teams);
-               let tiebreakers = [];
-               teams = rank(games, teams, 1, tiebreakers);
 
-               let cols = ["Results!B", "Results!C", "Results!D"];
-               if (group_name === 'Group B') {
-                       cols = ["Results!F", "Results!G", "Results!H"];
+               // Write the points total to the unsorted columns.
+               for (let i = 0; i < teams.length; ++i) {
+                       updates.push({ "range": cols[2] + (4 + i), "values": [ [ teams[i].pts ] ] });
                }
 
-               let updates = [];
+               let tiebreakers = [];
+               teams = rank(games, teams, 1, tiebreakers);
+
+               // Write the ranking table, from scratch.
                for (let i = 0; i < teams.length; ++i) {
                        updates.push({ "range": cols[0] + (10 + i), "values": [ [ teams[i].rank ] ] });
                        updates.push({ "range": cols[1] + (10 + i), "values": [ [ teams[i].shortname ] ] });
                        updates.push({ "range": cols[2] + (10 + i), "values": [ [ teams[i].pts ] ] });
                }
 
-               // TODO: update the points total at the seeding?
-
                let tb_str = "";
                if (tiebreakers.length != 0) {
                        tb_str = tiebreakers.join("\n");
@@ -99,7 +104,7 @@ function publish_group_rank(group_name)
                        "data": updates 
                };
                possibly_update_oauth_key(function() {
-                       post_json('https://sheets.googleapis.com/v4/spreadsheets/1uh7kr5v_hyD072b1G2tbQlhqd_8ldS_6j30CBocQ-4E/values:batchUpdate?key=AIzaSyAuP9yQn8g0bSay6r_RpGtpFeIbwprH1TU', json, function(response) {}, current_oauth_access_token);
+                       post_json('https://sheets.googleapis.com/v4/spreadsheets/1ygfeR6njBUmLyuLRq7zfYW5slMWBGnj4XxzQQ4WJklU/values:batchUpdate?key=AIzaSyAuP9yQn8g0bSay6r_RpGtpFeIbwprH1TU', json, function(response) {}, current_oauth_access_token);
                });
 
        });