]> iEval git - plack-app-gruntmaster.git/commitdiff
Improve standings
authorMarius Gavrilescu <marius@ieval.ro>
Thu, 30 Jan 2014 16:45:05 +0000 (18:45 +0200)
committerMarius Gavrilescu <marius@ieval.ro>
Thu, 30 Jan 2014 16:45:05 +0000 (18:45 +0200)
lib/Gruntmaster/Page/St.pm

index 27f3a9c598cee110a4e3d9b1247ecd71b7c68bde..fafded1c601dda5d63eda51851a07f568e3844ca 100644 (file)
@@ -32,13 +32,13 @@ use constant LEVEL_VALUES => {
 };
 
 sub calc_score{
-       my ($user, $problem, $date, $tries) = @_;
+       my ($user, $problem, $date, $tries, $totaltime) = @_;
        my $mxscore = LEVEL_VALUES->{problem_level($problem)};
        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;
+       $timetaken = 0 if $timetaken < 0;
+       $timetaken = 300 if $timetaken > $totaltime;
+       $score = ($totaltime - $timetaken) / $totaltime * $score;
        $score -= $tries / 10 * $mxscore;
        $score = $mxscore * 3 / 10 if $score < $mxscore * 3 / 10;
        int $score
@@ -46,9 +46,14 @@ sub calc_score{
 
 sub _generate{
        my ($self, $htc, $path, $lang) = @_;
+       my $totaltime;
 
        $path =~ m,^(?:ct/([^/]+)/)?,;
-       local $Gruntmaster::Data::contest = $1 if $1;
+       local $Gruntmaster::Data::contest;
+       if ($1) {
+               $totaltime = contest_end ($1) - contest_start ($1);
+               $Gruntmaster::Data::contest = $1;
+       }
 
        my @problems = problems;
        @problems = sort @problems;
@@ -56,7 +61,7 @@ sub _generate{
        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()});
+                       $scores{job_user()}{job_problem()} = job_result() ? 0 : calc_score (job_user(), job_problem(), job_date(), $tries{job_user()}{job_problem()}, $totaltime);
                } else {
                        if (job_result_text =~ m/^(\d+)/) {
                                $scores{job_user()}{job_problem()} = $1;
@@ -72,6 +77,7 @@ sub _generate{
                        user => $user,
                        score => sum (values $scores{$user}),
                        scores => [map { $scores{$user}{$_} // '-'} @problems],
+                       problems => $Gruntmaster::Data::contest,
                }
        } keys %scores;
        $htc->param(problems => [map { problem_name } @problems ]) if $Gruntmaster::Data::contest;
This page took 0.030064 seconds and 4 git commands to generate.