-# Find all last rounds with only one group per round
-my $srounds = ccbs::db_fetch_all($dbh, 'SELECT round FROM groups WHERE tournament=? GROUP BY round HAVING COUNT(*) = 1 ORDER BY round DESC', $tournament);
-
-my $last_sround;
-for my $sr (@$srounds) {
- # only accept strict ordering
- last if (defined($last_sround) && $sr->{'round'} != $last_sround - 1);
- $last_sround = $sr->{'round'};
-
- # Grab the highscore list from this round
- my $scores = ccbs::db_fetch_all($dbh, 'SELECT player,SUM(score) AS score FROM scores WHERE tournament=? AND round=? GROUP BY parallel,player ORDER BY SUM(score) DESC',
- $tournament, $sr->{'round'});
- for my $s (@$scores) {
- next if ($already_ordered{$s->{'player'}});
- $dbh->do('INSERT INTO tournamentrankings (tournament, ranking, player, points) VALUES (?,?,?,?)',
- undef, $tournament, $ranking, $s->{'player'}, points_for_place($ranking));
- $ranking++;
- $already_ordered{$s->{'player'}} = 1;
- }
-}
-
-# This should never happen
-if (!defined($last_sround)) {
- ccbs::user_error("Forsøk på å avslutte en turnering med flere grupper aktive.");
-}
-
-# Grab all the remaining groups; we order by the simple criteria: