]> iEval git - gruntmaster-page.git/commitdiff
Add ranks to standings and reduce warnings
authorMarius Gavrilescu <marius@ieval.ro>
Sat, 8 Feb 2014 22:55:59 +0000 (00:55 +0200)
committerMarius Gavrilescu <marius@ieval.ro>
Sat, 8 Feb 2014 22:55:59 +0000 (00:55 +0200)
lib/Gruntmaster/Page/St.pm
tmpl/st.en

index 099c1936a6f6646c747fdd8a44ff0bb5530f3e81..2186fea570647822782d3fb32f6a3492f0750c2c 100644 (file)
@@ -46,8 +46,8 @@ sub _generate{
                if ($Gruntmaster::Data::contest) {
                        $tries{job_user()}{job_problem()}++;
                        $scores{job_user()}{job_problem()} = job_result() ? 0 : calc_score (job_user(), job_problem(), job_date(), $tries{job_user()}{job_problem()}, $totaltime) if job_date() > $start;
-               } else {
-                       if (job_result_text =~ m/^(\scores+)/) {
+               } elsif (defined job_user && defined job_problem && defined job_result) {
+                       if (defined job_result_text && job_result_text =~ m/^(\scores+)/) {
                                $scores{job_user()}{job_problem()} = $ct;
                        } else {
                                $scores{job_user()}{job_problem()} = job_result() ? 0 : 100;
@@ -55,7 +55,7 @@ sub _generate{
                }
        }
 
-       my @st = sort { $b->{score} <=> $a->{score} } map {
+       my @st = sort { $b->{score} <=> $a->{score} or $a->{user} cmp $b->{user}} map {
                my $user = $_;
                +{
                        user => $user,
@@ -64,6 +64,9 @@ sub _generate{
                        problems => $Gruntmaster::Data::contest,
                }
        } keys %scores;
+
+       $st[0]->{rank} = 1;
+       $st[$_]->{rank} = $st[$_ - 1]->{rank} + ($st[$_]->{score} < $st[$_ - 1]->{score}) for 1 .. $#st;
        $htc->param(problems => [map { problem_name } @problems ]) if $Gruntmaster::Data::contest;
        $htc->param(st => \@st);
 }
index 1e4c8ec0380aae9de3de3d635c714452dfa35cd1..0c9893b1bd71c2bbc887151c788bbd62ea113319 100644 (file)
@@ -1,11 +1,11 @@
 <table border class="table table-border table-striped">
 <thead>
-<tmpl_if problems><tr><th>Username<tmpl_loop problems><th><tmpl_var _></tmpl_loop><th>Total
-<tmpl_else><tr><th>Username<th>Score
+<tmpl_if problems><tr><th>Rank<th>Username<tmpl_loop problems><th><tmpl_var _></tmpl_loop><th>Total
+<tmpl_else><tr><th>Rank<th>Username<th>Score
 </tmpl_if>
 
 <tbody>
-<tmpl_loop st><tr><td><tmpl_var user>
+<tmpl_loop st><tr><td><tmpl_var rank><td><tmpl_var user>
 <tmpl_if problems><tmpl_loop scores><td><tmpl_var _>
 </tmpl_loop></tmpl_if><td><tmpl_var score>
 </tmpl_loop>
This page took 0.035884 seconds and 4 git commands to generate.