9 my $dbh = ccbs::db_connect();
12 $dbh->{AutoCommit} = 0;
14 my $tournament = $cgi->param('tournament');
15 my %already_ordered = ();
19 # Grab all the groups; we order by the simple criteria:
20 # 1. If player A has gone to group X and player B hasn't, player A is higher.
21 # 2. If player A has a higher (max sum of songs)/(max feet of songs) (where
22 # any chosen song counts for 10) than B, player A is higher.
23 my $scores = ccbs::db_fetch_all($dbh, 'SELECT player FROM scores NATURAL JOIN tournaments NATURAL JOIN max_single_feetrating WHERE tournament=? GROUP BY round,player ORDER BY round DESC,SUM(score)/SUM(CASE WHEN chosen THEN 10 ELSE feetrating END) DESC',
25 for my $s (@$scores) {
26 next if ($already_ordered{$s->{'player'}});
27 $dbh->do('INSERT INTO tournamentrankings (tournament, ranking, player, points) VALUES (?,?,?,?)',
28 undef, $tournament, $ranking, $s->{'player'}, points_for_place($ranking));
30 $already_ordered{$s->{'player'}} = 1;
36 ccbs::print_see_other('show-tournament.pl?id=' . $tournament);
38 # gives the usual 100, 90, 81, 73, 60, 55, ... series
39 sub points_for_place {
42 return 111 - (23/2) * $n + (1/2) * $n * $n;