]> git.sesse.net Git - ccbs/commitdiff
Replace the web frontend's rank calculations with the stored procedures.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 12 Jun 2005 00:46:36 +0000 (00:46 +0000)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 12 Jun 2005 00:46:36 +0000 (00:46 +0000)
html/show-tournament.pl
html/templates/show-tournament.tmpl

index ab58b647f476c7bd04f2e606c3d75ce3592b19e2..d5173bac97239d730777de776e215f9401fffa37 100755 (executable)
@@ -46,12 +46,12 @@ if ($bigscreen) {
 my $scores;
 if ($tournament->{'country'} == 1) {
        $scores = ccbs::db_fetch_all($dbh,
-       'SELECT round,parallel,position,playmode,difficulty,songnumber,player,nick || \' (\' || countrycode::varchar || \')\' 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::varchar || \')\', 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 = ();
@@ -96,7 +96,8 @@ for my $score (@$scores) {
        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;
@@ -106,24 +107,6 @@ for my $score (@$scores) {
        }
 }
 
-# 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.
 
index ecb14175b4a045d865b934d366b143c221f102fb..291ccda9d6e9ea0fea45d853cb97beb4a4c0f5cd 100644 (file)
         [% END %]
         [% IF p.num_songs > 1 %]
      <td>[% pl.total %]</td>
-        [% END %]      
-     <td>[% pl.rank %]</td>
+        [% END %]  
+[% IF pl.best_rank == pl.worst_rank %]
+     <td>[% pl.best_rank %]
+[% ELSE %]     
+     <td>[% pl.best_rank %]-[% pl.worst_rank %]</td>
+[% END %]     
     </tr>
       [% ELSE %]
     <tr>