my $rankings;
if ($tournament->{'country'} == 1) {
- $rankings = ccbs::db_fetch_all($dbh, 'SELECT ranking,nick || \' (\' || countrycode || \')\' AS nick,COALESCE(points,-1) AS points FROM tournamentrankings NATURAL JOIN players NATURAL JOIN countries WHERE tournament=? ORDER BY ranking', $id);
+ $rankings = ccbs::db_fetch_all($dbh, 'SELECT ranking,player,nick || \' (\' || countrycode::varchar || \')\' AS nick,COALESCE(points,-1) AS points FROM tournamentrankings NATURAL JOIN players NATURAL JOIN countries WHERE tournament=? ORDER BY ranking', $id);
} else {
- $rankings = ccbs::db_fetch_all($dbh, 'SELECT ranking,COALESCE(nick || \' (\' || clubcode || \')\', nick) AS nick,COALESCE(points,-1) AS points FROM tournamentrankings NATURAL JOIN players NATURAL LEFT JOIN clubs WHERE tournament=? ORDER BY ranking', $id);
+ $rankings = ccbs::db_fetch_all($dbh, 'SELECT ranking,player,COALESCE(nick || \' (\' || clubcode::varchar || \')\', nick) AS nick,COALESCE(points,-1) AS points FROM tournamentrankings NATURAL JOIN players NATURAL LEFT JOIN clubs WHERE tournament=? ORDER BY ranking', $id);
}
my $songs = ccbs::db_fetch_all($dbh, 'SELECT song,title FROM machinesongs NATURAL JOIN songs WHERE machine=? ORDER BY LOWER(title)', $tournament->{'machine'});
my $scores;
if ($tournament->{'country'} == 1) {
$scores = ccbs::db_fetch_all($dbh,
- 'SELECT round,parallel,position,playmode,difficulty,songnumber,player,nick || \' (\' || countrycode || \')\' AS nick,song,title,chosen,score FROM roundparticipation NATURAL JOIN players NATURAL JOIN countries NATURAL JOIN scores NATURAL LEFT JOIN songs WHERE tournament=? ORDER BY round,parallel,position,songnumber',
- $id);
+ 'SELECT round,parallel,position,playmode,difficulty,songnumber,player,nick || \' (\' || countrycode::varchar || \')\' AS nick,song,title,chosen,score,best_rank,worst_rank FROM roundparticipation NATURAL JOIN players NATURAL JOIN countries NATURAL JOIN scores NATURAL LEFT JOIN songs NATURAL JOIN get_minmax_rank_for_players(?,\'single\') WHERE tournament=? ORDER BY round,parallel,position,songnumber',
+ $id, $id);
} else {
$scores = ccbs::db_fetch_all($dbh,
- 'SELECT round,parallel,position,playmode,difficulty,songnumber,player,COALESCE(nick || \' (\' || clubcode || \')\', nick) AS nick,song,title,chosen,score FROM roundparticipation NATURAL JOIN players NATURAL JOIN scores NATURAL LEFT JOIN songs NATURAL LEFT JOIN clubs WHERE tournament=? ORDER BY round,parallel,position,songnumber',
- $id);
+ 'SELECT round,parallel,position,playmode,difficulty,songnumber,player,COALESCE(nick || \' (\' || clubcode::varchar || \')\', nick) AS nick,song,title,chosen,score,best_rank,worst_rank FROM roundparticipation NATURAL JOIN players NATURAL JOIN scores NATURAL LEFT JOIN songs NATURAL LEFT JOIN clubs NATURAL JOIN get_minmax_rank_for_players(?,\'single\') WHERE tournament=? ORDER BY round,parallel,position,songnumber',
+ $id, $id);
}
my @rounds = ();
my $pl = $p->[$#$p]->{'players'};
if ($score->{'nick'} ne $player) {
$player = $score->{'nick'};
- push @$pl, { player => $score->{'player'}, nick => $player, songs => [], total => 0, rank => 1 };
+ push @$pl, { player => $score->{'player'}, nick => $player, songs => [], total => 0, best_rank => $score->{'best_rank'},
+ worst_rank => $score->{'worst_rank'} };
}
push @{$pl->[$#$pl]->{'songs'}}, $score;
}
}
-# Find the rank of all the players in every group, via simple insertion-like
-# sort
-for my $r (@rounds) {
- for my $p (@{$r->{'parallels'}}) {
- my $pls = $p->{'players'};
- for my $i (0..$#$pls) {
- my $rank = 1;
- for my $j (0..($i-1)) {
- if ($pls->[$i]->{'total'} < $pls->[$j]->{'total'}) {
- $pls->[$i]->{'rank'}++;
- } elsif ($pls->[$i]->{'total'} > $pls->[$j]->{'total'}) {
- $pls->[$j]->{'rank'}++;
- }
- }
- }
- }
-}
-
# FIXME: In some odd cases, there _might_ be an empty group right at the end. Fix this when
# we are able to add/delete people in groups.