From ca3dffeb7be20e4bf1269d8bb502f80eb533f0ab Mon Sep 17 00:00:00 2001 From: Marius Gavrilescu Date: Thu, 30 Jan 2014 18:45:05 +0200 Subject: [PATCH] Improve standings --- lib/Gruntmaster/Page/St.pm | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/Gruntmaster/Page/St.pm b/lib/Gruntmaster/Page/St.pm index 27f3a9c..fafded1 100644 --- a/lib/Gruntmaster/Page/St.pm +++ b/lib/Gruntmaster/Page/St.pm @@ -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; -- 2.39.2