X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;f=lib%2FGruntmaster%2FPage%2FSt.pm;fp=lib%2FGruntmaster%2FPage%2FSt.pm;h=0000000000000000000000000000000000000000;hb=594d53ba258320b2b98ec4413a808366237f5e40;hp=9ed2a31c67c6c05d6b911de09c9af400dcd02bbf;hpb=600e4c01f0fc265a61aea2830c26ed2bd6d77c73;p=plack-app-gruntmaster.git diff --git a/lib/Gruntmaster/Page/St.pm b/lib/Gruntmaster/Page/St.pm deleted file mode 100644 index 9ed2a31..0000000 --- a/lib/Gruntmaster/Page/St.pm +++ /dev/null @@ -1,64 +0,0 @@ -package Gruntmaster::Page::St; - -use Gruntmaster::Page::Base st => 'Standings'; - -use constant LEVEL_VALUES => { - beginner => 100, - easy => 250, - medium => 500, - hard => 1000, -}; - -sub calc_score{ - my ($mxscore, $time, $tries, $totaltime) = @_; - my $score = $mxscore; - $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 + 0.5 -} - -sub _generate{ - my ($self, $htc, $lang, $env) = @_; - #debug $env => "language is '$lang'"; - - my $ct = $env->{'gruntmaster.contest'} && db($env)->contest($env->{'gruntmaster.contest'}); - - my @problems = map { $_->problem } db($env)->contest_problems->search({contest => $ct && $ct->id}, {qw/join problem order_by problem.level/}); - my (%scores, %tries); - for my $job (db($env)->jobs->search({contest => $ct && $ct->id}, {order_by => 'id'})) { - - if ($ct) { - my $open = db($env)->opens->find($ct->id, $job->problem->id, $job->owner->id); - my $time = $job->date - ($open ? $open->time : $ct->start); - next if $time < 0; - my $value = $job->problem->value // LEVEL_VALUES->{$job->problem->level}; - my $factor = $job->result ? 0 : 1; - $factor = $1 / 100 if $job->result_text =~ /^(\d+ )/; - $scores{$job->owner->id}{$job->problem->id} = int ($factor * calc_score ($value, $time, $tries{$job->owner->id}{$job->problem->id}, $ct->stop - $ct->start)); - $tries{$job->owner->id}{$job->problem->id}++; - } else { - 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} or $a->{user}->id cmp $b->{user}->id} map { - my $user = $_; - +{ - user => db($env)->user($user), - score => sum (values $scores{$user}), - scores => [map { $scores{$user}{$_->id} // '-'} @problems], - problems => $ct, - } - } keys %scores; - - $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); -} - -1