X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;f=lib%2FGruntmaster%2FPage%2FSt.pm;h=2d7b23831f29cb08420ae5d04f90dc1b9d07279c;hb=d3200993969efcd4d9c0ce6a5666a012815ad2d5;hp=27f3a9c598cee110a4e3d9b1247ecd71b7c68bde;hpb=d17951d1fd99fc1ed82cb900b8fff7091971e59b;p=gruntmaster-page.git diff --git a/lib/Gruntmaster/Page/St.pm b/lib/Gruntmaster/Page/St.pm index 27f3a9c..2d7b238 100644 --- a/lib/Gruntmaster/Page/St.pm +++ b/lib/Gruntmaster/Page/St.pm @@ -1,28 +1,6 @@ package Gruntmaster::Page::St; -use 5.014000; -use strict; -use warnings; use Gruntmaster::Page::Base st => 'Standings'; -our @ISA = qw/Gruntmaster::Page::Base/; -our $VERSION = '0.001'; - -use constant TEMPLATES => { - en => <<'HTML', - - - -
UsernameTotal -
UsernameScore - - -
- - - -
-HTML -}; use constant LEVEL_VALUES => { beginner => 100, @@ -32,49 +10,51 @@ use constant LEVEL_VALUES => { }; sub calc_score{ - my ($user, $problem, $date, $tries) = @_; - my $mxscore = LEVEL_VALUES->{problem_level($problem)}; + my ($mxscore, $time, $tries, $totaltime) = @_; my $score = $mxscore; - my $timetaken = $date - get_open($problem, $user); - $timetaken = 1 if $timetaken < 1; - $timetaken = 150 + int rand 150 if $timetaken > 3600; - $score = (3600 - $timetaken) / 3600 * $score; + $time = 0 if $time < 0; + $time = 300 if $time > $totaltime; + $score = ($totaltime - $time) / $totaltime * $score; $score -= $tries / 10 * $mxscore; $score = $mxscore * 3 / 10 if $score < $mxscore * 3 / 10; - int $score + int $score + 0.5 } sub _generate{ - my ($self, $htc, $path, $lang) = @_; + my ($self, $htc, $lang, $env, $ct) = @_; + debug $env => "language is '$lang' and contest is '$ct'"; - $path =~ m,^(?:ct/([^/]+)/)?,; - local $Gruntmaster::Data::contest = $1 if $1; + $ct &&= db($env)->contest($ct); - my @problems = problems; - @problems = sort @problems; + my @problems = map { $_->problem } db($env)->contest_problems->search({contest => $ct->id}, {qw/join problem order_by problem.level/}); my (%scores, %tries); - for (1 .. jobcard) { - 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()}); + for my $job (db($env)->jobs->search({contest => $ct->id})) { + + if ($ct) { + my $time = $job->date - $ct->start; + next if $time < 0; + my $value = $job->problem->value // LEVEL_VALUES->{$job->problem->level}; + $scores{$job->owner->id}{$job->problem->id} = $job->result ? 0 : calc_score ($value, $time, $tries{$job->owner}{$job->problem}, $ct->stop - $ct->start); + $tries{$job->owner->id}{$job->problem->id}++; } else { - if (job_result_text =~ m/^(\d+)/) { - $scores{job_user()}{job_problem()} = $1; - } else { - $scores{job_user()}{job_problem()} = job_result() ? 0 : 100; - } + no warnings 'numeric'; + $scores{$job->owner->id}{$job->problem->id} = 0 + $job->result_text || ($job->result ? 0 : 100) } } - 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, + user => db($env)->user($user), score => sum (values $scores{$user}), - scores => [map { $scores{$user}{$_} // '-'} @problems], + scores => [map { $scores{$user}{$_->id} // '-'} @problems], + problems => $ct, } } keys %scores; - $htc->param(problems => [map { problem_name } @problems ]) if $Gruntmaster::Data::contest; + + $st[0]->{rank} = 1; + $st[$_]->{rank} = $st[$_ - 1]->{rank} + ($st[$_]->{score} < $st[$_ - 1]->{score}) for 1 .. $#st; + $htc->param(problems => \@problems) if $ct; $htc->param(st => \@st); }