X-Git-Url: https://git.sesse.net/?p=ccbs;a=blobdiff_plain;f=html%2Fdo-finish-tournament.pl;h=b493968e3fa8ea07b97c5ae57b4ebe20683e8b35;hp=7c7b14a0fe74efe5f07b94192ed907f79af4cc82;hb=11b5968454610745e6cd47fb71edea1218f835dd;hpb=8f737799f877c7de7594754ebe798a2ba41b2b8a diff --git a/html/do-finish-tournament.pl b/html/do-finish-tournament.pl index 7c7b14a..b493968 100755 --- a/html/do-finish-tournament.pl +++ b/html/do-finish-tournament.pl @@ -21,6 +21,7 @@ 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', @@ -39,6 +40,19 @@ 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: +# 1. If player A has gone to group X and player B hasn't, player A is higher. +# 2. If player A has higher max score than player B, player A is higher. +my $scores = ccbs::db_fetch_all($dbh, 'SELECT player FROM scores WHERE tournament=? AND round < ? GROUP BY round,player ORDER BY round DESC,MAX(score) DESC', + $tournament, $last_sround); +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; +} + $dbh->commit; $dbh->disconnect;