X-Git-Url: https://git.sesse.net/?p=ccbs;a=blobdiff_plain;f=html%2Fdo-finish-tournament.pl;h=bf53b91844dddeff86a8da74243ce84512584b72;hp=a22da1769fd4f594b2d94a0fd4151fac3226aa47;hb=31c8c1f081e2f04dd0a2635aa27cf8dfdfb1f400;hpb=9b92b979d4647472f0beefae30c08855a3284966 diff --git a/html/do-finish-tournament.pl b/html/do-finish-tournament.pl index a22da17..bf53b91 100755 --- a/html/do-finish-tournament.pl +++ b/html/do-finish-tournament.pl @@ -16,37 +16,12 @@ my %already_ordered = (); my $ranking = 1; my $points = 100; -# 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: +# Grab all the 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); +# 2. If player A has a higher (max sum of songs)/(max feet of songs) (where +# any chosen song counts for 10) than B, player A is higher. +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', + $tournament); for my $s (@$scores) { next if ($already_ordered{$s->{'player'}}); $dbh->do('INSERT INTO tournamentrankings (tournament, ranking, player, points) VALUES (?,?,?,?)', @@ -60,13 +35,13 @@ $dbh->disconnect; ccbs::print_see_other('show-tournament.pl?id=' . $tournament); -# gives the usual 100, 91, 83, 76. 65, 61, ... series +# gives the usual 100, 90, 81, 73, 60, 55, ... series sub points_for_place { my $n = shift; if ($n <= 10) { - return 110 - (21/2) * $n + (1/2) * $n * $n; - } elsif ($n <= 65) { - return 65 - $n; + return 111 - (23/2) * $n + (1/2) * $n * $n; + } elsif ($n <= 56) { + return 56 - $n; } else { return 0; }