7 my $dbh = ccbs::db_connect();
10 $dbh->{AutoCommit} = 0;
12 my $tournament = $cgi->param('tournament');
13 my %already_ordered = ();
17 # Find all last rounds with only one group per round
18 my $srounds = ccbs::db_fetch_all($dbh, 'SELECT round FROM groups WHERE tournament=? GROUP BY round HAVING COUNT(*) = 1 ORDER BY round DESC', $tournament);
21 for my $sr (@$srounds) {
22 # only accept strict ordering
23 last if (defined($last_sround) && $sr->{'round'} != $last_sround - 1);
25 # Grab the highscore list from this round
26 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',
27 $tournament, $sr->{'round'});
28 for my $s (@$scores) {
29 next if ($already_ordered{$s->{'player'}});
30 $dbh->do('INSERT INTO tournamentrankings (tournament, ranking, player, points) VALUES (?,?,?,?)',
31 undef, $tournament, $ranking, $s->{'player'}, points_for_place($ranking));
33 $already_ordered{$s->{'player'}} = 1;
37 # This should never happen
38 if (!defined($last_sround)) {
39 ccbs::user_error("Forsøk på å avslutte en turnering med flere grupper aktive.");
45 ccbs::print_see_other('show-tournament.pl?id=' . $tournament);
47 # gives the usual 100, 91, 83, 76. 65, 61, ... series
48 sub points_for_place {
51 return 110 - (21/2) * $n + (1/2) * $n * $n;