]> git.sesse.net Git - ultimatescore/blob - carousel.js
Implement correct tiebreak rules for #4 and #6.
[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 beat_parts = partition_by_beat(teams, function(beat, teams_to_idx) {
158                 for (let i = 0; i < games.length; ++i) {
159                         let idx1 = teams_to_idx[games[i].name1];
160                         let idx2 = teams_to_idx[games[i].name2];
161                         if (idx1 !== undefined && idx2 !== undefined) {
162                                 if (games[i].score1 > games[i].score2) {
163                                         beat[idx1][idx2] = 1;
164                                 }
165                                 if (games[i].score1 < games[i].score2) {
166                                         beat[idx2][idx1] = 1;
167                                 }
168                         }
169                 }
170         });
171         if (beat_parts.length > 1) {
172                 tiebreakers.push(explain_tiebreaker(beat_parts, 'head-to-head'));
173                 return subrank_partitions(games, beat_parts, start_rank, tiebreakers);
174         }
175
176         // Rule #2: Number of games played (fewer is better).
177         // Actually the rule says “fewest losses”, but fewer games is equivalent
178         // as long as teams have the same amount of points and ties don't exist.
179         let nplayed_parts = partition(teams, function(a, b) { return a.nplayed - b.nplayed });
180         if (nplayed_parts.length > 1) {
181                 tiebreakers.push(explain_tiebreaker(nplayed_parts, 'fewer losses'));
182                 return subrank_partitions(games, nplayed_parts, start_rank, tiebreakers);
183         }
184
185         // Rule #3: Head-to-head goal difference. 
186         let teams_to_idx = make_teams_to_idx(teams);
187         for (let i = 0; i < teams.length; i++) {
188                 teams[i].h2h_gd = 0;
189                 teams[i].h2h_goals = 0;
190         }
191         for (let i = 0; i < games.length; ++i) {
192                 let idx1 = teams_to_idx[games[i].name1];
193                 let idx2 = teams_to_idx[games[i].name2];
194                 if (idx1 !== undefined && idx2 !== undefined &&
195                     !isNaN(games[i].score1) && isNaN(games[i].score2)) {
196                         teams[idx1].h2h_gd += games[i].score1;
197                         teams[idx1].h2h_gd -= games[i].score2;
198                         teams[idx2].h2h_gd += games[i].score2;
199                         teams[idx2].h2h_gd -= games[i].score1;
200
201                         teams[idx1].h2h_goals += games[i].score1;
202                         teams[idx2].h2h_goals += games[i].score2;
203                 }
204         }
205         let h2h_gd_parts = partition(teams, function(a, b) { return b.h2h_gd - a.h2h_gd });
206         if (h2h_gd_parts.length > 1) {
207                 tiebreakers.push(explain_tiebreaker(h2h_gd_parts, 'head-to-head goal difference'));
208                 return subrank_partitions(games, h2h_gd_parts, start_rank, tiebreakers);
209         }
210
211         // Rule #4: Goal difference against common opponents.
212         var results = {};
213         for (let i = 0; i < games.length; ++i) {
214                 if (results[games[i].name1] === undefined) {
215                         results[games[i].name1] = {};
216                 }
217                 if (results[games[i].name2] === undefined) {
218                         results[games[i].name2] = {};
219                 }
220                 results[games[i].name1][games[i].name2] = [ games[i].score1, games[i].score2 ];
221                 results[games[i].name2][games[i].name1] = [ games[i].score2, games[i].score1 ];
222         }
223         let gd_parts = partition_by_beat(teams, function(beat, teams_to_idx) {
224                 for (const team_i of Object.keys(teams_to_idx)) {
225                         let i = teams_to_idx[team_i];
226                         for (const team_j of Object.keys(teams_to_idx)) {
227                                 let j = teams_to_idx[team_j];
228                                 let results_i = results[team_i], results_j = results[team_j];
229                                 let gd_i = 0, gd_j = 0;
230
231                                 // See if the two teams have both played a third team k.
232                                 for (let k in results_i) {
233                                         if (!results_i.hasOwnProperty(k)) continue;
234                                         if (results_j[k] !== undefined) {
235                                                 gd_i += results_i[k][0] - results_i[k][1];
236                                                 gd_j += results_j[k][0] - results_j[k][1];
237                                         }
238                                 }
239
240                                 if (gd_i > gd_j) {
241                                         beat[i][j] = 1;
242                                 } else if (gd_i < gd_j) {
243                                         beat[j][i] = 1;
244                                 }
245                         }
246                 }
247         });
248         if (gd_parts.length > 1) {
249                 tiebreakers.push(explain_tiebreaker(gd_parts, 'goal difference versus common opponents'));
250                 return subrank_partitions(games, gd_parts, start_rank, tiebreakers);
251         }
252
253         // Rule #5: Head-to-head scored goals.
254         let h2h_goals_parts = partition(teams, function(a, b) { return b.h2h_goals - a.h2h_goals });
255         if (h2h_goals_parts.length > 1) {
256                 tiebreakers.push(explain_tiebreaker(h2h_goals_parts, 'head-to-head scored goals'));
257                 return subrank_partitions(games, h2h_goals_parts, start_rank, tiebreakers);
258         }
259
260         // Rule #6: Goals scored against common opponents.
261         let goals_parts = partition_by_beat(teams, function(beat, teams_to_idx) {
262                 for (const team_i of Object.keys(teams_to_idx)) {
263                         let i = teams_to_idx[team_i];
264                         for (const team_j of Object.keys(teams_to_idx)) {
265                                 let j = teams_to_idx[team_j];
266                                 let results_i = results[team_i], results_j = results[team_j];
267                                 let goals_i = 0, goals_j = 0;
268
269                                 // See if the two teams have both played a third team k.
270                                 for (let k in results_i) {
271                                         if (!results_i.hasOwnProperty(k)) continue;
272                                         if (results_j[k] !== undefined) {
273                                                 goals_i += results_i[k][0];
274                                                 goals_j += results_j[k][0];
275                                         }
276                                 }
277
278                                 if (goals_i > goals_j) {
279                                         beat[i][j] = 1;
280                                 } else if (goals_i < goals_j) {
281                                         beat[j][i] = 1;
282                                 }
283                         }
284                 }
285         });
286         if (goals_parts.length > 1) {
287                 tiebreakers.push(explain_tiebreaker(goals_parts, 'goals scored against common opponents'));
288                 return subrank_partitions(games, goals_parts, start_rank, tiebreakers);
289         }
290
291         // OK, it's a tie. Give them all the same rank.
292         let result = [];
293         for (let i = 0; i < teams.length; ++i) {
294                 result.push(teams[i]);
295                 result[i].rank = start_rank;
296         }
297         return result; 
298 }; 
299
300 function parse_teams_from_spreadsheet(response) {
301         let teams = [];
302         for (let i = 2; response.values[i].length >= 1; ++i) {
303                 teams.push({
304                         "name": response.values[i][0],
305                         "mediumname": response.values[i][1],
306                         "shortname": response.values[i][2],
307                         "tags": response.values[i][3],
308                         "nplayed": 0,
309                         "gd": 0,
310                         "pts": 0,
311                         "goals": 0
312                 });
313         }
314         return teams;
315 };
316
317 function parse_games_from_spreadsheet(response, group_name, include_unplayed) {
318         let games = [];
319         let i;
320         for (i = 0; i < response.values.length; ++i) {
321                 if (response.values[i][0] === 'Results') {
322                         i += 2;
323                         break;
324                 }
325         }
326
327         for ( ; response.values[i] !== undefined && response.values[i].length >= 1; ++i) {
328                 if ((response.values[i][2] && response.values[i][3]) || include_unplayed) {
329                         let real_group_name = response.values[i][9];
330                         if (real_group_name === undefined) {
331                                 real_group_name = group_name;
332                         }
333                         games.push({
334                                 "name1": response.values[i][0],
335                                 "name2": response.values[i][1],
336                                 "score1": parseInt(response.values[i][2]),
337                                 "score2": parseInt(response.values[i][3]),
338                                 "streamday": response.values[i][7],
339                                 "streamtime": response.values[i][8],
340                                 "group_name": real_group_name
341                         });
342                 }
343         }
344         return games;
345 };
346
347 function display_group(response, group_name)
348 {
349         let teams = parse_teams_from_spreadsheet(response);
350         let games = parse_games_from_spreadsheet(response, group_name, false);
351         display_group_parsed(teams, games, group_name);
352 };
353
354 function display_group_parsed(teams, games, group_name)
355 {
356         document.getElementById('entire-bug').style.display = 'none';
357
358         let teams_to_idx = make_teams_to_idx(teams);
359         for (let i = 0; i < games.length; ++i) {
360                 let idx1 = teams_to_idx[games[i].name1];
361                 let idx2 = teams_to_idx[games[i].name2];
362                 if (games[i].score1 === undefined || games[i].score2 === undefined ||
363                     isNaN(games[i].score1) || isNaN(games[i].score2) ||
364                     idx1 === undefined || idx2 === undefined ||
365                     games[i].score1 == games[i].score2) {
366                         continue;
367                 }
368                 ++teams[idx1].nplayed;
369                 ++teams[idx2].nplayed;
370                 teams[idx1].goals += games[i].score1;
371                 teams[idx2].goals += games[i].score2;
372                 teams[idx1].gd += games[i].score1;
373                 teams[idx2].gd += games[i].score2;
374                 teams[idx1].gd -= games[i].score2;
375                 teams[idx2].gd -= games[i].score1;
376                 if (games[i].score1 > games[i].score2) {
377                         teams[idx1].pts += 2;
378                 } else {
379                         teams[idx2].pts += 2;
380                 }
381         }
382
383         let tiebreakers = [];
384         teams = rank(games, teams, 1, tiebreakers);
385
386         let carousel = document.getElementById('carousel');
387         clear_carousel(carousel);
388
389         addheading(carousel, 5, "Current standings, Trøndisk 2017<br />" + group_name);
390         let tr = document.createElement("tr");
391         tr.className = "subfooter";
392         addth(tr, "rank", "");
393         addth(tr, "team", "");
394         addth(tr, "nplayed", "P");
395         addth(tr, "gd", "GD");
396         addth(tr, "pts", "Pts");
397         carousel.appendChild(tr);
398
399         let row_num = 2;
400         for (let i = 0; i < teams.length; ++i) {
401                 let tr = document.createElement("tr");
402
403                 addth(tr, "rank", teams[i].rank);
404                 addtd(tr, "team", teams[i].name);
405                 addtd(tr, "nplayed", teams[i].nplayed);
406                 addtd(tr, "gd", teams[i].gd.toString().replace(/-/, '−'));
407                 addtd(tr, "pts", teams[i].pts);
408
409                 carousel.appendChild(tr);
410         }
411
412         if (tiebreakers.length > 0) {
413                 let tie_tr = document.createElement("tr");
414                 tie_tr.className = "footer";
415                 let td = document.createElement("td");
416                 td.appendChild(document.createTextNode("Tiebreaks applied: " + tiebreakers.join(', ')));
417                 td.setAttribute("colspan", "5");
418                 tie_tr.appendChild(td);
419                 carousel.appendChild(tie_tr);
420         }
421
422         let footer_tr = document.createElement("tr");
423         footer_tr.className = "footer";
424         let td = document.createElement("td");
425         td.appendChild(document.createTextNode("www.trondheimfrisbeeklubb.no | #trøndisk"));
426         td.setAttribute("colspan", "5");
427         footer_tr.appendChild(td);
428         carousel.appendChild(footer_tr);
429
430         fade_in_rows(carousel);
431
432         carousel.style.display = 'table';
433 };
434
435 function fade_in_rows(table)
436 {
437         let trs = table.getElementsByTagName("tr");
438         for (let i = 1; i < trs.length; ++i) {  // The header already has its own fade-in.
439                 if (trs[i].className === "footer") {
440                         trs[i].style = "-webkit-animation: fade-in 1.0s ease; -webkit-animation-delay: " + (0.25 * i) + "s; -webkit-animation-fill-mode: both;";
441                 } else {
442                         trs[i].style = "-webkit-animation: fade-in 2.0s ease; -webkit-animation-delay: " + (0.25 * i) + "s; -webkit-animation-fill-mode: both;";
443                 }
444         }
445 };
446
447 function fade_out_rows(table)
448 {
449         let trs = table.getElementsByTagName("tr");
450         for (let i = 0; i < trs.length; ++i) {
451                 if (trs[i].className === "footer") {
452                         trs[i].style = "-webkit-animation: fade-out 1.0s ease; -webkit-animation-delay: " + (0.125 * i) + "s; -webkit-animation-fill-mode: both;";
453                 } else {
454                         trs[i].style = "-webkit-animation: fade-out 1.0s ease; -webkit-animation-delay: " + (0.125 * i) + "s; -webkit-animation-fill-mode: both;";
455                 }
456         }
457 };
458
459 function clear_carousel(table)
460 {
461         while (table.childNodes.length > 0) {
462                 table.removeChild(table.firstChild);
463         }
464 };
465
466 // Stream schedule
467 let max_list_len = 8;
468
469 function display_stream_schedule(response, group_name) {
470         let teams = parse_teams_from_spreadsheet(response);
471         let games = parse_games_from_spreadsheet(response, group_name, true);
472         display_stream_schedule_parsed(teams, games, 0);
473 };
474
475 function sort_game_list(games) {
476         games = games.filter(function(game) { return game.streamtime !== undefined && game.streamtime.match(/[0-9]+:[0-9]+/) != null; });
477         games.sort(function(a, b) {
478                 if (a.streamday !== b.streamday) {
479                         return a.streamday - b.streamday;
480                 }
481
482                 let m1 = a.streamtime.match(/([0-9]+):([0-9]+)/);
483                 let m2 = b.streamtime.match(/([0-9]+):([0-9]+)/);
484                 return (m1[1] * 60 + m1[2]) - (m2[1] * 60 + m2[2]);
485         });
486         return games;
487 }
488
489 function find_game_start_idx(games) {
490         // Pick out a reasonable place to start the list. We'll show the last
491         // completed match and start from there.
492         let start_idx = games.length - 1;
493         for (let i = 0; i < games.length; ++i) {
494                 if (isNaN(games[i].score1) || isNaN(games[i].score2) &&
495                     games[i].score1 === games[i].score2) {
496                         start_idx = i;
497                         break;
498                 }
499         }
500         if (start_idx > 0) start_idx--;
501         if (games.length >= max_list_len) {
502                 start_idx = Math.min(start_idx, games.length - max_list_len);
503         }
504         return start_idx;
505 }
506
507 function find_num_pages(games) {
508         games = sort_game_list(games);
509         let start_idx = find_game_start_idx(games);
510         return Math.ceil((games.length - start_idx) / max_list_len);
511 }
512
513 function display_stream_schedule_parsed(teams, games, page) {
514         document.getElementById('entire-bug').style.display = 'none';
515
516         games = sort_game_list(games);
517         let start_idx = find_game_start_idx(games);
518
519         start_idx += page * max_list_len;
520         if (start_idx >= games.length) {
521                 // Error.
522                 return;
523         }
524
525         let days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"];
526         let shortdays = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
527         let today = days[(new Date).getDay()];
528
529         let covered_days = [];
530         let row_num = 0;
531         for (let i = start_idx; i < games.length && row_num++ < max_list_len; ++i) {
532                 if (i == start_idx || games[i].streamday != games[i - 1].streamday) {
533                         covered_days.push(days[games[i].streamday]);
534                 }
535         }
536         
537         let carousel = document.getElementById('carousel');
538         clear_carousel(carousel);
539         addheading(carousel, 3, "Stream schedule, Trøndisk 2017<br />" + covered_days.join('/') + " (all times CET)");
540
541         let teams_to_idx = make_teams_to_idx(teams);
542         row_num = 0;
543         for (let i = start_idx; i < games.length && row_num < max_list_len; ++i) {
544                 let tr = document.createElement("tr");
545
546                 let name1 = teams[teams_to_idx[games[i].name1]].mediumname;
547                 let name2 = teams[teams_to_idx[games[i].name2]].mediumname;
548
549                 addtd(tr, "matchup", name1 + "–" + name2);
550                 addtd(tr, "group", games[i].group_name);
551
552                 if (!isNaN(games[i].score1) && !isNaN(games[i].score2) &&
553                     games[i].score1 !== games[i].score2) {
554                         addtd(tr, "streamtime", games[i].score1 + "–" + games[i].score2);
555                 } else {
556                         let streamtime = games[i].streamtime;
557                         let streamday = days[games[i].streamday];
558                         if (streamday !== today) {
559                                 streamtime = shortdays[games[i].streamday] + " " + streamtime;
560                         }
561                         addth(tr, "streamtime", streamtime);
562                 }
563
564                 row_num++;
565                 carousel.appendChild(tr);
566         }
567
568         fade_in_rows(carousel);
569
570         carousel.style.display = 'table';
571 };
572
573 function get_group(group_name, cb)
574 {
575         let req = new XMLHttpRequest();
576         req.onload = function(e) {
577                 cb(JSON.parse(req.responseText), group_name);
578         };
579         req.open('GET', 'https://sheets.googleapis.com/v4/spreadsheets/122tIwrXTi5ug0Vv6Np5w3pVwEWE2KkjWxtzQQfGtOZA/values/\'' + group_name + '\'!A1:J50?key=AIzaSyAuP9yQn8g0bSay6r_RpGtpFeIbwprH1TU');
580         req.send();
581 };
582
583 function showgroup(group_name)
584 {
585         get_group(group_name, display_group);
586 };
587
588 function showgroup_from_state()
589 {
590         showgroup(state['group_name']);
591 };
592
593 let carousel_timeout = null;
594
595 function hidetable()
596 {
597         fade_out_rows(document.getElementById('carousel'));
598 };
599
600 function showschedule(page)
601 {
602         let teams = [];
603         let games = [];
604         let num_left = 3;
605
606         let cb = function(response, group_name) {
607                 teams = teams.concat(parse_teams_from_spreadsheet(response));
608                 games = games.concat(parse_games_from_spreadsheet(response, group_name, true));
609                 if (--num_left == 0) {
610                         display_stream_schedule_parsed(teams, games, 0);
611                 }
612         };
613
614         get_group('Group A', cb);
615         get_group('Group B', cb);
616         get_group('Playoffs', cb);
617 };
618
619 function do_series(series)
620 {
621         do_series_internal(series, 0);
622 };
623
624 function do_series_internal(series, idx)
625 {
626         (series[idx][1])();
627         if (idx + 1 < series.length) {
628                 carousel_timeout = setTimeout(function() { do_series_internal(series, idx + 1); }, series[idx][0]);
629         }
630 };
631
632 function showcarousel()
633 {
634         let teams_per_group = [];
635         let games_per_group = [];
636         let combined_teams = [];
637         let combined_games = [];
638         let num_left = 3;
639
640         let cb = function(response, group_name) {
641                 let teams = parse_teams_from_spreadsheet(response);
642                 let games = parse_games_from_spreadsheet(response, group_name, true);
643                 teams_per_group[group_name] = teams;
644                 games_per_group[group_name] = games;
645
646                 combined_teams = combined_teams.concat(teams);
647                 combined_games = combined_games.concat(games);
648                 if (--num_left == 0) {
649                         let series = [
650                                 [ 13000, function() { display_group_parsed(teams_per_group['Group A'], games_per_group['Group A'], 'Group A'); } ],
651                                 [ 2000, function() { hidetable(); } ],
652                                 [ 13000, function() { display_group_parsed(teams_per_group['Group B'], games_per_group['Group B'], 'Group B'); } ],
653                                 [ 2000, function() { hidetable(); } ]
654                         ];
655                         let num_pages = find_num_pages(combined_games);
656                         for (let page = 0; page < num_pages; ++page) {
657                                 series.push([ 13000, function() { display_stream_schedule_parsed(combined_teams, combined_games, page); } ]);
658                                 series.push([ 2000, function() { hidetable(); } ]);
659                         }
660
661                         do_series(series);
662                 }
663         };
664
665         get_group('Group A', cb);
666         get_group('Group B', cb);
667         get_group('Playoffs', cb);
668 };
669
670 function stopcarousel()
671 {
672         if (carousel_timeout !== null) {
673                 hidetable();
674                 clearTimeout(carousel_timeout);
675                 carousel_timeout = null;
676         }
677 };
678
679 function hidescorebug()
680 {
681         document.getElementById('entire-bug').style.display = 'none';
682 }
683
684 function showscorebug()
685 {
686         document.getElementById('entire-bug').style.display = null;
687 };
688