From 6bdf86462be42eda23d9b1f9b08fa1f6951486f6 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Sun, 12 Jun 2005 00:46:36 +0000 Subject: [PATCH] Replace the web frontend's rank calculations with the stored procedures. --- html/show-tournament.pl | 29 ++++++----------------------- html/templates/show-tournament.tmpl | 8 ++++++-- 2 files changed, 12 insertions(+), 25 deletions(-) diff --git a/html/show-tournament.pl b/html/show-tournament.pl index ab58b64..d5173ba 100755 --- a/html/show-tournament.pl +++ b/html/show-tournament.pl @@ -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. diff --git a/html/templates/show-tournament.tmpl b/html/templates/show-tournament.tmpl index ecb1417..291ccda 100644 --- a/html/templates/show-tournament.tmpl +++ b/html/templates/show-tournament.tmpl @@ -163,8 +163,12 @@ [% END %] [% IF p.num_songs > 1 %] [% pl.total %] - [% END %] - [% pl.rank %] + [% END %] +[% IF pl.best_rank == pl.worst_rank %] + [% pl.best_rank %] +[% ELSE %] + [% pl.best_rank %]-[% pl.worst_rank %] +[% END %] [% ELSE %] -- 2.39.2