-
addheading = function(carousel, colspan, content)
{
var thead = document.createElement("thead");
return teams;
};
-parse_games_from_spreadsheet = function(response, include_unplayed) {
+parse_games_from_spreadsheet = function(response, group_name, include_unplayed) {
var games = [];
for (var i = 12; response.values[i] !== undefined && response.values[i].length >= 1; ++i) {
if ((response.values[i][2] && response.values[i][3]) || include_unplayed) {
"name2": response.values[i][1],
"score1": parseInt(response.values[i][2]),
"score2": parseInt(response.values[i][3]),
- "streamtime": response.values[i][7]
+ "streamtime": response.values[i][7],
+ "group_name": group_name
});
}
}
return games;
};
-var req = new XMLHttpRequest();
-req.onload = function(e) {
- var response = JSON.parse(req.responseText);
+var display_group = function(response, group_name) {
var teams = parse_teams_from_spreadsheet(response);
- var games = parse_games_from_spreadsheet(response, false);
+ var games = parse_games_from_spreadsheet(response, group_name, false);
var teams_to_idx = make_teams_to_idx(teams);
for (i = 0; i < games.length; ++i) {
var carousel = document.getElementById('carousel');
- addheading(carousel, 5, "Current standings, TrønDisk 2017<br />Group A");
+ addheading(carousel, 5, "Current standings, TrønDisk 2017<br />" + group_name);
var tr = document.createElement("tr");
tr.className = "subfooter";
addth(tr, "rank", "");
carousel.style.display = 'table';
};
-req.open('GET', 'https://sheets.googleapis.com/v4/spreadsheets/1CwRHQtpokVMGTPJu2FYYG-6rnG7OfISIcEHwBfXh-Y4/values/A1:H25?key=AIzaSyAuP9yQn8g0bSay6r_RpGtpFeIbwprH1TU');
-if (false) {
- req.send();
-}
// Stream schedule
-var req2 = new XMLHttpRequest();
-req2.onload = function(e) {
- var response = JSON.parse(req.responseText);
+var display_stream_schedule = function(response, group_name) {
var teams = parse_teams_from_spreadsheet(response);
+ var games = parse_games_from_spreadsheet(response, group_name, true);
+ display_stream_schedule_parsed(teams, games);
+};
+
+var display_stream_schedule_parsed = function(teams, games) {
var teams_to_idx = make_teams_to_idx(teams);
- var games = parse_games_from_spreadsheet(response, true);
games = games.filter(function(game) { return game.streamtime !== undefined && game.streamtime.match(/[0-9]+:[0-9]+/) != null; });
games.sort(function(a, b) {
var m1 = a.streamtime.match(/([0-9]+):([0-9]+)/);
var name2 = teams[teams_to_idx[games[i].name2]].mediumname;
addtd(tr, "matchup", name1 + "–" + name2);
- addtd(tr, "group", "Group A");
+ addtd(tr, "group", games[i].group_name);
if (!isNaN(games[i].score1) && !isNaN(games[i].score2) &&
games[i].score1 !== games[i].score2) {
tr.style = "-webkit-animation: fade-in 1.0s ease; -webkit-animation-delay: " + 0.25 * (row_num++) + "s; -webkit-animation-fill-mode: both;";
carousel.appendChild(tr);
}
+
+ carousel.style.display = 'table';
};
-req2.open('GET', 'https://sheets.googleapis.com/v4/spreadsheets/1CwRHQtpokVMGTPJu2FYYG-6rnG7OfISIcEHwBfXh-Y4/values/A1:H25?key=AIzaSyAuP9yQn8g0bSay6r_RpGtpFeIbwprH1TU');
-if (false) {
- req2.send();
-}
+
+var get_group = function(group_name, cb)
+{
+ var req = new XMLHttpRequest();
+ req.onload = function(e) {
+ cb(JSON.parse(req.responseText), group_name);
+ };
+ req.open('GET', 'https://sheets.googleapis.com/v4/spreadsheets/1CwRHQtpokVMGTPJu2FYYG-6rnG7OfISIcEHwBfXh-Y4/values/\'' + group_name + '\'!A1:H25?key=AIzaSyAuP9yQn8g0bSay6r_RpGtpFeIbwprH1TU');
+ req.send();
+};
+
+//get_group('Group A', display_group);
+//get_group('Group A', display_stream_schedule);
+//get_group('Group A', function(response_a) {
+// get_group('Group B', function(response_b) {
+// var teams = parse_teams_from_spreadsheet(response_a);
+// var games = parse_games_from_spreadsheet(response_a, 'Group A', true);
+// teams = teams.concat(parse_teams_from_spreadsheet(response_b));
+// games = games.concat(parse_games_from_spreadsheet(response_b, 'Group B', true));
+// console.log(teams);
+// console.log(games);
+// display_stream_schedule_parsed(teams, games);
+// });
+//});