X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;ds=inline;f=lib%2FGruntmaster%2FPage%2FSt.pm;h=547eaba544297c8ea7d49947558e9c90ee8a2b5d;hb=2e2be9fd67d19611a43a37f39d4bb720f4357cf3;hp=fafded1c601dda5d63eda51851a07f568e3844ca;hpb=ca3dffeb7be20e4bf1269d8bb502f80eb533f0ab;p=plack-app-gruntmaster.git
diff --git a/lib/Gruntmaster/Page/St.pm b/lib/Gruntmaster/Page/St.pm
index fafded1..547eaba 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
-Username | Score
-
-
- |
-
-
-
-
- | | | | | |
---|
-HTML
-};
use constant LEVEL_VALUES => {
beginner => 100,
@@ -32,55 +10,51 @@ use constant LEVEL_VALUES => {
};
sub calc_score{
- my ($user, $problem, $date, $tries, $totaltime) = @_;
- my $mxscore = LEVEL_VALUES->{problem_level($problem)};
+ my ($mxscore, $time, $tries, $totaltime) = @_;
my $score = $mxscore;
- my $timetaken = $date - get_open($problem, $user);
- $timetaken = 0 if $timetaken < 0;
- $timetaken = 300 if $timetaken > $totaltime;
- $score = ($totaltime - $timetaken) / $totaltime * $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 $totaltime;
+ my ($self, $htc, $lang, $env) = @_;
+ #debug $env => "language is '$lang'";
- $path =~ m,^(?:ct/([^/]+)/)?,;
- local $Gruntmaster::Data::contest;
- if ($1) {
- $totaltime = contest_end ($1) - contest_start ($1);
- $Gruntmaster::Data::contest = $1;
- }
+ my $ct = $env->{'gruntmaster.contest'} && db($env)->contest($env->{'gruntmaster.contest'});
- my @problems = problems;
- @problems = sort @problems;
+ my @problems = map { $_->problem } db($env)->contest_problems->search({contest => $ct && $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()}, $totaltime);
+ for my $job (db($env)->jobs->search({contest => $ct && $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}->id cmp $b->{user}->id} map {
my $user = $_;
+{
- user => $user,
+ user => db($env)->user($user),
score => sum (values $scores{$user}),
- scores => [map { $scores{$user}{$_} // '-'} @problems],
- problems => $Gruntmaster::Data::contest,
+ 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);
}