]> git.sesse.net Git - ultimatescore/blobdiff - update_sheets.js
Some parametrization and Trøndisk updates of the spreadsheets.
[ultimatescore] / update_sheets.js
index d9757b21bee385b92276b05dc5cc3f9cab171d89..2115b8ce24ac2489fa0bca2d6e46c2ddf10dbd55 100644 (file)
@@ -69,10 +69,7 @@ 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 cols = ultimateconfig['score_sheet_cols'][group_name];
 
                let teams = parse_teams_from_spreadsheet(response);
                let games = parse_games_from_spreadsheet(response, group_name, false);
@@ -80,7 +77,8 @@ function publish_group_rank(group_name)
 
                // 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 row = ultimateconfig['point_total_start_row'] + i;
+                       updates.push({ "range": cols[2] + row, "values": [ [ teams[i].pts ] ] });
                }
 
                let tiebreakers = [];
@@ -88,23 +86,24 @@ function publish_group_rank(group_name)
 
                // 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 ] ] });
+                       let row = ultimateconfig['ranking_list_start_row'] + i;
+                       updates.push({ "range": cols[0] + row, "values": [ [ teams[i].rank ] ] });
+                       updates.push({ "range": cols[1] + row, "values": [ [ teams[i].shortname ] ] });
+                       updates.push({ "range": cols[2] + row, "values": [ [ teams[i].pts ] ] });
                }
 
                let tb_str = "";
                if (tiebreakers.length != 0) {
                        tb_str = tiebreakers.join("\n");
                }
-               updates.push({ "range": cols[0] + "15", "values": [ [ tb_str ] ]});
+               updates.push({ "range": cols[0] + ultimateconfig['ranking_list_explain_row'], "values": [ [ tb_str ] ]});
 
                let json = {
                        "valueInputOption": "USER_ENTERED",
                        "data": updates 
                };
                possibly_update_oauth_key(function() {
-                       post_json('https://sheets.googleapis.com/v4/spreadsheets/1ygfeR6njBUmLyuLRq7zfYW5slMWBGnj4XxzQQ4WJklU/values:batchUpdate?key=AIzaSyAuP9yQn8g0bSay6r_RpGtpFeIbwprH1TU', json, function(response) {}, current_oauth_access_token);
+                       post_json('https://sheets.googleapis.com/v4/spreadsheets/' + ultimateconfig['score_sheet_id'] + '/values:batchUpdate?key=' + ultimateconfig['api_key'], json, function(response) {}, current_oauth_access_token);
                });
 
        });