]> git.sesse.net Git - ultimatescore/blob - carousel.js
82027427b53afdf488508fbe239888d31acab625
[ultimatescore] / carousel.js
1 'use strict';
2
3 function addheading(carousel, colspan, content)
4 {
5         let thead = document.createElement("thead");
6         let tr = document.createElement("tr");
7         let th = document.createElement("th");
8         th.innerHTML = content;
9         th.setAttribute("colspan", colspan);
10         tr.appendChild(th);
11         thead.appendChild(tr);
12         carousel.appendChild(thead);
13 };
14 function addtd(tr, className, content) {
15         let td = document.createElement("td");
16         td.appendChild(document.createTextNode(content));
17         td.className = className;
18         tr.appendChild(td);
19 };
20 function addth(tr, className, content) {
21         let th = document.createElement("th");
22         th.appendChild(document.createTextNode(content));
23         th.className = className;
24         tr.appendChild(th);
25 };
26
27 function subrank_partitions(games, parts, start_rank, tiebreakers) {
28         let result = [];
29         for (let i = 0; i < parts.length; ++i) {
30                 let part = rank(games, parts[i], start_rank, tiebreakers);
31                 for (let j = 0; j < part.length; ++j) {
32                         result.push(part[j]);
33                 }
34                 start_rank += part.length;
35         }
36         return result;
37 };
38
39 function partition(teams, compare)
40 {
41         teams.sort(compare);
42
43         let parts = [];
44         let curr_part = [teams[0]];
45         for (let i = 1; i < teams.length; ++i) {
46                 if (compare(teams[i], curr_part[0]) != 0) {
47                         parts.push(curr_part);
48                         curr_part = [];
49                 }
50                 curr_part.push(teams[i]);
51         }
52         if (curr_part.length != 0) {
53                 parts.push(curr_part);
54         }
55         return parts;
56 };
57
58 function explain_tiebreaker(parts, rule_name)
59 {
60         let result = [];
61         for (let i = 0; i < parts.length; ++i) {
62                 result.push(parts[i].map(function(x) { return x.shortname; }).join("/"));
63         }
64         return result.join(" > ") + " (" + rule_name + ")";
65 }
66
67 function make_teams_to_idx(teams)
68 {
69         let teams_to_idx = [];
70         for (let i = 0; i < teams.length; i++) {
71                 teams_to_idx[teams[i].name] = i;
72         }
73         return teams_to_idx;
74 }
75
76 function partition_by_beat(teams, fill_beatmatrix)
77 {
78         // Head-to-head score by way of components. First construct the beat matrix.
79         let n = teams.length;
80         let beat = new Array(n);
81         let teams_to_idx = make_teams_to_idx(teams);
82         for (let i = 0; i < n; i++) {
83                 beat[i] = new Array(n);
84                 for (let j = 0; j < n; j++) {
85                         beat[i][j] = 0;
86                 }
87         }
88         fill_beatmatrix(beat, teams_to_idx);
89         // Floyd-Warshall for transitive closure.
90         for (let k = 0; k < n; ++k) {
91                 for (let i = 0; i < n; ++i) {
92                         for (let j = 0; j < n; ++j) {
93                                 if (beat[i][k] && beat[k][j]) {
94                                         beat[i][j] = 1;
95                                 }
96                         }
97                 }
98         }
99
100         // See if we can find any team that is comparable to all others.
101         for (let pivot_idx = 0; pivot_idx < n; pivot_idx++) {
102                 let incomparable = false;
103                 for (let i = 0; i < n; ++i) {
104                         if (i != pivot_idx && beat[pivot_idx][i] == 0 && beat[i][pivot_idx] == 0) {
105                                 incomparable = true;
106                                 break;
107                         }
108                 }
109                 if (!incomparable) {
110                         // Split the teams into three partitions:
111                         let better_than_pivot = [], equal = [], worse_than_pivot = [];
112                         for (let i = 0; i < n; ++i) {
113                                 let we_beat = (beat[pivot_idx][i] == 1);
114                                 let they_beat = (beat[i][pivot_idx] == 1);
115                                 if ((i == pivot_idx) || (we_beat && they_beat)) {
116                                         equal.push(teams[i]);
117                                 } else if (we_beat && !they_beat) {
118                                         worse_than_pivot.push(teams[i]);
119                                 } else if (they_beat && !we_beat) {
120                                         better_than_pivot.push(teams[i]);
121                                 } else {
122                                         console.log("this shouldn't happen");
123                                 }
124                         } 
125                         let result = [];
126                         if (better_than_pivot.length > 0) {
127                                 result = partition_by_beat(better_than_pivot, fill_beatmatrix);
128                         }
129                         result.push(equal);  // Obviously can't be partitioned further.
130                         if (worse_than_pivot.length > 0) {
131                                 result = result.concat(partition_by_beat(worse_than_pivot, fill_beatmatrix));
132                         }
133                         return result;
134                 }
135         }
136
137         // No usable pivot was found, so the graph is inherently
138         // disconnected, and we cannot partition it.
139         return [teams];
140 }
141
142 // Takes in an array, gives every element a rank starting with 1, and returns.
143 function rank(games, teams, start_rank, tiebreakers) {
144         if (teams.length <= 1) {
145                 // Only one team, so trivial.
146                 teams[0].rank = start_rank;
147                 return teams;
148         }
149
150         // Rule #0: Partition the teams by score.
151         let score_parts = partition(teams, function(a, b) { return b.pts - a.pts });
152         if (score_parts.length > 1) {
153                 return subrank_partitions(games, score_parts, start_rank, tiebreakers);
154         }
155
156         // Rule #1: Head-to-head wins.
157         let num_relevant_games = 0;
158         let beat_parts = partition_by_beat(teams, function(beat, teams_to_idx) {
159                 for (let i = 0; i < games.length; ++i) {
160                         let idx1 = teams_to_idx[games[i].name1];
161                         let idx2 = teams_to_idx[games[i].name2];
162                         if (idx1 !== undefined && idx2 !== undefined) {
163                                 if (games[i].score1 > games[i].score2) {
164                                         beat[idx1][idx2] = 1;
165                                         ++num_relevant_games;
166                                 } else if (games[i].score1 < games[i].score2) {
167                                         beat[idx2][idx1] = 1;
168                                         ++num_relevant_games;
169                                 }
170                         }
171                 }
172         });
173         if (beat_parts.length > 1) {
174                 tiebreakers.push(explain_tiebreaker(beat_parts, 'head-to-head'));
175                 return subrank_partitions(games, beat_parts, start_rank, tiebreakers);
176         }
177
178         // Rule #2: Number of games played (fewer is better).
179         // Actually the rule says “fewest losses”, but fewer games is equivalent
180         // as long as teams have the same amount of points and ties don't exist.
181         let nplayed_parts = partition(teams, function(a, b) { return a.nplayed - b.nplayed });
182         if (nplayed_parts.length > 1) {
183                 tiebreakers.push(explain_tiebreaker(nplayed_parts, 'fewer losses'));
184                 return subrank_partitions(games, nplayed_parts, start_rank, tiebreakers);
185         }
186
187         // Rule #3: Head-to-head goal difference (if all have played).
188         let teams_to_idx = make_teams_to_idx(teams);
189         if (num_relevant_games >= teams.length * (teams.length - 1) / 2) {
190                 for (let i = 0; i < teams.length; i++) {
191                         teams[i].h2h_gd = 0;
192                         teams[i].h2h_goals = 0;
193                 }
194                 for (let i = 0; i < games.length; ++i) {
195                         let idx1 = teams_to_idx[games[i].name1];
196                         let idx2 = teams_to_idx[games[i].name2];
197                         if (idx1 !== undefined && idx2 !== undefined &&
198                             !isNaN(games[i].score1) && !isNaN(games[i].score2)) {
199                                 teams[idx1].h2h_gd += games[i].score1;
200                                 teams[idx1].h2h_gd -= games[i].score2;
201                                 teams[idx2].h2h_gd += games[i].score2;
202                                 teams[idx2].h2h_gd -= games[i].score1;
203
204                                 teams[idx1].h2h_goals += games[i].score1;
205                                 teams[idx2].h2h_goals += games[i].score2;
206                         }
207                 }
208                 let h2h_gd_parts = partition(teams, function(a, b) { return b.h2h_gd - a.h2h_gd });
209                 if (h2h_gd_parts.length > 1) {
210                         tiebreakers.push(explain_tiebreaker(h2h_gd_parts, 'head-to-head goal difference'));
211                         return subrank_partitions(games, h2h_gd_parts, start_rank, tiebreakers);
212                 }
213         }
214
215         // Rule #4: Goal difference against common opponents.
216         var results = {};
217         for (let i = 0; i < games.length; ++i) {
218                 if (results[games[i].name1] === undefined) {
219                         results[games[i].name1] = {};
220                 }
221                 if (results[games[i].name2] === undefined) {
222                         results[games[i].name2] = {};
223                 }
224                 results[games[i].name1][games[i].name2] = [ games[i].score1, games[i].score2 ];
225                 results[games[i].name2][games[i].name1] = [ games[i].score2, games[i].score1 ];
226         }
227         let gd_parts = partition_by_beat(teams, function(beat, teams_to_idx) {
228                 for (const team_i of Object.keys(teams_to_idx)) {
229                         let i = teams_to_idx[team_i];
230                         for (const team_j of Object.keys(teams_to_idx)) {
231                                 let j = teams_to_idx[team_j];
232                                 let results_i = results[team_i], results_j = results[team_j];
233                                 let gd_i = 0, gd_j = 0;
234
235                                 // See if the two teams have both played a third team k.
236                                 for (let k in results_i) {
237                                         if (!results_i.hasOwnProperty(k)) continue;
238                                         if (results_j !== undefined && results_j[k] !== undefined) {
239                                                 gd_i += results_i[k][0] - results_i[k][1];
240                                                 gd_j += results_j[k][0] - results_j[k][1];
241                                         }
242                                 }
243
244                                 if (gd_i > gd_j) {
245                                         beat[i][j] = 1;
246                                 } else if (gd_i < gd_j) {
247                                         beat[j][i] = 1;
248                                 }
249                         }
250                 }
251         });
252         if (gd_parts.length > 1) {
253                 tiebreakers.push(explain_tiebreaker(gd_parts, 'goal difference versus common opponents'));
254                 return subrank_partitions(games, gd_parts, start_rank, tiebreakers);
255         }
256
257         // Rule #5: Head-to-head scored goals (if all have played).
258         if (num_relevant_games >= teams.length * (teams.length - 1) / 2) {
259                 let h2h_goals_parts = partition(teams, function(a, b) { return b.h2h_goals - a.h2h_goals });
260                 if (h2h_goals_parts.length > 1) {
261                         tiebreakers.push(explain_tiebreaker(h2h_goals_parts, 'head-to-head scored goals'));
262                         return subrank_partitions(games, h2h_goals_parts, start_rank, tiebreakers);
263                 }
264         }
265
266         // Rule #6: Goals scored against common opponents.
267         let goals_parts = partition_by_beat(teams, function(beat, teams_to_idx) {
268                 for (const team_i of Object.keys(teams_to_idx)) {
269                         let i = teams_to_idx[team_i];
270                         for (const team_j of Object.keys(teams_to_idx)) {
271                                 let j = teams_to_idx[team_j];
272                                 let results_i = results[team_i], results_j = results[team_j];
273                                 let goals_i = 0, goals_j = 0;
274
275                                 // See if the two teams have both played a third team k.
276                                 for (let k in results_i) {
277                                         if (!results_i.hasOwnProperty(k)) continue;
278                                         if (results_j !== undefined && results_j[k] !== undefined) {
279                                                 goals_i += results_i[k][0];
280                                                 goals_j += results_j[k][0];
281                                         }
282                                 }
283
284                                 if (goals_i > goals_j) {
285                                         beat[i][j] = 1;
286                                 } else if (goals_i < goals_j) {
287                                         beat[j][i] = 1;
288                                 }
289                         }
290                 }
291         });
292         if (goals_parts.length > 1) {
293                 tiebreakers.push(explain_tiebreaker(goals_parts, 'goals scored against common opponents'));
294                 return subrank_partitions(games, goals_parts, start_rank, tiebreakers);
295         }
296
297         // OK, it's a tie. Give them all the same rank.
298         let result = [];
299         for (let i = 0; i < teams.length; ++i) {
300                 result.push(teams[i]);
301                 result[i].rank = start_rank;
302         }
303         return result; 
304 }; 
305
306 function parse_teams_from_spreadsheet(response) {
307         let teams = [];
308         for (let i = 2; response.values[i].length >= 1; ++i) {
309                 teams.push({
310                         "name": response.values[i][0],
311                         "mediumname": response.values[i][1],
312                         "shortname": response.values[i][2],
313                         "tags": response.values[i][3],
314                         "nplayed": 0,
315                         "gd": 0,
316                         "pts": 0,
317                         "goals": 0
318                 });
319         }
320         return teams;
321 };
322
323 function parse_games_from_spreadsheet(response, group_name, include_unplayed) {
324         let games = [];
325         let i;
326         for (i = 0; i < response.values.length; ++i) {
327                 if (response.values[i][0] === 'Results') {
328                         i += 2;
329                         break;
330                 }
331         }
332
333         for ( ; response.values[i] !== undefined && response.values[i].length >= 1; ++i) {
334                 if ((response.values[i][2] && response.values[i][3]) || include_unplayed) {
335                         let real_group_name = response.values[i][9];
336                         if (real_group_name === undefined) {
337                                 real_group_name = group_name;
338                         }
339                         games.push({
340                                 "name1": response.values[i][0],
341                                 "name2": response.values[i][1],
342                                 "score1": parseInt(response.values[i][2]),
343                                 "score2": parseInt(response.values[i][3]),
344                                 "streamday": response.values[i][7],
345                                 "streamtime": response.values[i][8],
346                                 "group_name": real_group_name
347                         });
348                 }
349         }
350         return games;
351 };
352
353 function display_group(response, group_name)
354 {
355         let teams = parse_teams_from_spreadsheet(response);
356         let games = parse_games_from_spreadsheet(response, group_name, false);
357         display_group_parsed(teams, games, group_name);
358 };
359
360 function display_group_parsed(teams, games, group_name)
361 {
362         document.getElementById('entire-bug').style.display = 'none';
363
364         let teams_to_idx = make_teams_to_idx(teams);
365         for (let i = 0; i < games.length; ++i) {
366                 let idx1 = teams_to_idx[games[i].name1];
367                 let idx2 = teams_to_idx[games[i].name2];
368                 if (games[i].score1 === undefined || games[i].score2 === undefined ||
369                     isNaN(games[i].score1) || isNaN(games[i].score2) ||
370                     idx1 === undefined || idx2 === undefined ||
371                     games[i].score1 == games[i].score2) {
372                         continue;
373                 }
374                 ++teams[idx1].nplayed;
375                 ++teams[idx2].nplayed;
376                 teams[idx1].goals += games[i].score1;
377                 teams[idx2].goals += games[i].score2;
378                 teams[idx1].gd += games[i].score1;
379                 teams[idx2].gd += games[i].score2;
380                 teams[idx1].gd -= games[i].score2;
381                 teams[idx2].gd -= games[i].score1;
382                 if (games[i].score1 > games[i].score2) {
383                         teams[idx1].pts += 2;
384                 } else {
385                         teams[idx2].pts += 2;
386                 }
387         }
388
389         let tiebreakers = [];
390         teams = rank(games, teams, 1, tiebreakers);
391
392         let carousel = document.getElementById('carousel');
393         clear_carousel(carousel);
394
395         addheading(carousel, 5, "Current standings<br />" + group_name);
396         let tr = document.createElement("tr");
397         tr.className = "subfooter";
398         addth(tr, "rank", "");
399         addth(tr, "team", "");
400         addth(tr, "nplayed", "P");
401         addth(tr, "gd", "GD");
402         addth(tr, "pts", "Pts");
403         carousel.appendChild(tr);
404
405         let row_num = 2;
406         for (let i = 0; i < teams.length; ++i) {
407                 let tr = document.createElement("tr");
408
409                 addth(tr, "rank", teams[i].rank);
410                 addtd(tr, "team", teams[i].name);
411                 addtd(tr, "nplayed", teams[i].nplayed);
412                 addtd(tr, "gd", teams[i].gd.toString().replace(/-/, '−'));
413                 addtd(tr, "pts", teams[i].pts);
414
415                 carousel.appendChild(tr);
416         }
417
418         if (tiebreakers.length > 0) {
419                 let tie_tr = document.createElement("tr");
420                 tie_tr.className = "footer";
421                 let td = document.createElement("td");
422                 td.appendChild(document.createTextNode("Tiebreaks applied: " + tiebreakers.join(', ')));
423                 td.setAttribute("colspan", "5");
424                 tie_tr.appendChild(td);
425                 carousel.appendChild(tie_tr);
426         }
427
428         let footer_tr = document.createElement("tr");
429         footer_tr.className = "footer";
430         let td = document.createElement("td");
431         td.appendChild(document.createTextNode("Norwegian Ultimate Championships 2018 | #ultimatenm"));
432         td.setAttribute("colspan", "5");
433         footer_tr.appendChild(td);
434         carousel.appendChild(footer_tr);
435
436         fade_in_rows(carousel);
437
438         carousel.style.display = 'table';
439 };
440
441 function fade_in_rows(table)
442 {
443         let trs = table.getElementsByTagName("tr");
444         for (let i = 1; i < trs.length; ++i) {  // The header already has its own fade-in.
445                 if (trs[i].className === "footer") {
446                         trs[i].style = "-webkit-animation: fade-in 1.0s ease; -webkit-animation-delay: " + (0.25 * i) + "s; -webkit-animation-fill-mode: both;";
447                 } else {
448                         trs[i].style = "-webkit-animation: fade-in 2.0s ease; -webkit-animation-delay: " + (0.25 * i) + "s; -webkit-animation-fill-mode: both;";
449                 }
450         }
451 };
452
453 function fade_out_rows(table)
454 {
455         let trs = table.getElementsByTagName("tr");
456         for (let i = 0; i < trs.length; ++i) {
457                 if (trs[i].className === "footer") {
458                         trs[i].style = "-webkit-animation: fade-out 1.0s ease; -webkit-animation-delay: " + (0.125 * i) + "s; -webkit-animation-fill-mode: both;";
459                 } else {
460                         trs[i].style = "-webkit-animation: fade-out 1.0s ease; -webkit-animation-delay: " + (0.125 * i) + "s; -webkit-animation-fill-mode: both;";
461                 }
462         }
463 };
464
465 function clear_carousel(table)
466 {
467         while (table.childNodes.length > 0) {
468                 table.removeChild(table.firstChild);
469         }
470 };
471
472 // Stream schedule
473 let max_list_len = 8;
474
475 function display_stream_schedule(response, group_name) {
476         let teams = parse_teams_from_spreadsheet(response);
477         let games = parse_games_from_spreadsheet(response, group_name, true);
478         display_stream_schedule_parsed(teams, games, 0);
479 };
480
481 function sort_game_list(games) {
482         games = games.filter(function(game) { return game.streamtime !== undefined && game.streamtime.match(/[0-9]+:[0-9]+/) != null; });
483         games.sort(function(a, b) {
484                 if (a.streamday !== b.streamday) {
485                         return a.streamday - b.streamday;
486                 }
487
488                 let m1 = a.streamtime.match(/([0-9]+):([0-9]+)/);
489                 let m2 = b.streamtime.match(/([0-9]+):([0-9]+)/);
490                 return (m1[1] * 60 + m1[2]) - (m2[1] * 60 + m2[2]);
491         });
492         return games;
493 }
494
495 function find_game_start_idx(games) {
496         // Pick out a reasonable place to start the list. We'll show the last
497         // completed match and start from there.
498         let start_idx = games.length - 1;
499         for (let i = 0; i < games.length; ++i) {
500                 if (isNaN(games[i].score1) || isNaN(games[i].score2) &&
501                     games[i].score1 === games[i].score2) {
502                         start_idx = i;
503                         break;
504                 }
505         }
506         if (start_idx > 0) start_idx--;
507         if (games.length >= max_list_len) {
508                 start_idx = Math.min(start_idx, games.length - max_list_len);
509         }
510         return start_idx;
511 }
512
513 function find_num_pages(games) {
514         games = sort_game_list(games);
515         let start_idx = find_game_start_idx(games);
516         return Math.ceil((games.length - start_idx) / max_list_len);
517 }
518
519 function display_stream_schedule_parsed(teams, games, page) {
520         document.getElementById('entire-bug').style.display = 'none';
521
522         games = sort_game_list(games);
523         let start_idx = find_game_start_idx(games);
524
525         start_idx += page * max_list_len;
526         if (start_idx >= games.length) {
527                 // Error.
528                 return;
529         }
530
531         let days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"];
532         let shortdays = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
533         let today = days[(new Date).getDay()];
534
535         let covered_days = [];
536         let row_num = 0;
537         for (let i = start_idx; i < games.length && row_num++ < max_list_len; ++i) {
538                 if (i == start_idx || games[i].streamday != games[i - 1].streamday) {
539                         covered_days.push(days[games[i].streamday]);
540                 }
541         }
542         
543         let carousel = document.getElementById('carousel');
544         clear_carousel(carousel);
545         addheading(carousel, 3, "Match schedule<br />" + covered_days.join('/') + " (all times CET)");
546
547         let teams_to_idx = make_teams_to_idx(teams);
548         row_num = 0;
549         for (let i = start_idx; i < games.length && row_num < max_list_len; ++i) {
550                 let tr = document.createElement("tr");
551
552                 let name1 = teams[teams_to_idx[games[i].name1]].mediumname;
553                 let name2 = teams[teams_to_idx[games[i].name2]].mediumname;
554
555                 addtd(tr, "matchup", name1 + "–" + name2);
556                 addtd(tr, "group", games[i].group_name);
557
558                 if (!isNaN(games[i].score1) && !isNaN(games[i].score2) &&
559                     games[i].score1 !== games[i].score2) {
560                         addtd(tr, "streamtime", games[i].score1 + "–" + games[i].score2);
561                 } else {
562                         let streamtime = games[i].streamtime;
563                         let streamday = days[games[i].streamday];
564                         if (streamday !== today) {
565                                 streamtime = shortdays[games[i].streamday] + " " + streamtime;
566                         }
567                         addth(tr, "streamtime", streamtime);
568                 }
569
570                 row_num++;
571                 carousel.appendChild(tr);
572         }
573
574         fade_in_rows(carousel);
575
576         carousel.style.display = 'table';
577 };
578
579 function get_group(group_name, cb)
580 {
581         let req = new XMLHttpRequest();
582         req.onload = function(e) {
583                 cb(JSON.parse(req.responseText), group_name);
584         };
585         req.open('GET', 'https://sheets.googleapis.com/v4/spreadsheets/122tIwrXTi5ug0Vv6Np5w3pVwEWE2KkjWxtzQQfGtOZA/values/\'' + group_name + '\'!A1:J50?key=AIzaSyAuP9yQn8g0bSay6r_RpGtpFeIbwprH1TU');
586         req.send();
587 };
588
589 function showgroup(group_name)
590 {
591         get_group(group_name, display_group);
592 };
593
594 function showgroup_from_state()
595 {
596         showgroup(state['group_name']);
597 };
598
599 let carousel_timeout = null;
600
601 function hidetable()
602 {
603         fade_out_rows(document.getElementById('carousel'));
604 };
605
606 function showschedule(page)
607 {
608         let teams = [];
609         let games = [];
610         let num_left = 3;
611
612         let cb = function(response, group_name) {
613                 teams = teams.concat(parse_teams_from_spreadsheet(response));
614                 games = games.concat(parse_games_from_spreadsheet(response, group_name, true));
615                 if (--num_left == 0) {
616                         display_stream_schedule_parsed(teams, games, 0);
617                 }
618         };
619
620         get_group('Group A', cb);
621         get_group('Group B', cb);
622         get_group('Playoffs', cb);
623 };
624
625 function do_series(series)
626 {
627         do_series_internal(series, 0);
628 };
629
630 function do_series_internal(series, idx)
631 {
632         (series[idx][1])();
633         if (idx + 1 < series.length) {
634                 carousel_timeout = setTimeout(function() { do_series_internal(series, idx + 1); }, series[idx][0]);
635         }
636 };
637
638 function showcarousel()
639 {
640         let teams_per_group = [];
641         let games_per_group = [];
642         let combined_teams = [];
643         let combined_games = [];
644         let num_left = 3;
645
646         let cb = function(response, group_name) {
647                 let teams = parse_teams_from_spreadsheet(response);
648                 let games = parse_games_from_spreadsheet(response, group_name, true);
649                 teams_per_group[group_name] = teams;
650                 games_per_group[group_name] = games;
651
652                 combined_teams = combined_teams.concat(teams);
653                 combined_games = combined_games.concat(games);
654                 if (--num_left == 0) {
655                         let series = [
656                                 [ 13000, function() { display_group_parsed(teams_per_group['Group A'], games_per_group['Group A'], 'Group A'); } ],
657                                 [ 2000, function() { hidetable(); } ],
658                                 [ 13000, function() { display_group_parsed(teams_per_group['Group B'], games_per_group['Group B'], 'Group B'); } ],
659                                 [ 2000, function() { hidetable(); } ]
660                         ];
661                         let num_pages = find_num_pages(combined_games);
662                         for (let page = 0; page < num_pages; ++page) {
663                                 series.push([ 13000, function() { display_stream_schedule_parsed(combined_teams, combined_games, page); } ]);
664                                 series.push([ 2000, function() { hidetable(); } ]);
665                         }
666
667                         do_series(series);
668                 }
669         };
670
671         get_group('Group A', cb);
672         get_group('Group B', cb);
673         get_group('Playoffs', cb);
674 };
675
676 function stopcarousel()
677 {
678         if (carousel_timeout !== null) {
679                 hidetable();
680                 clearTimeout(carousel_timeout);
681                 carousel_timeout = null;
682         }
683 };
684
685 function hidescorebug()
686 {
687         document.getElementById('entire-bug').style.display = 'none';
688 }
689
690 function showscorebug()
691 {
692         document.getElementById('entire-bug').style.display = null;
693 };
694