]> iEval git - gruntmaster-page.git/blob - lib/Gruntmaster/Page/St.pm
Fix previous commit
[gruntmaster-page.git] / lib / Gruntmaster / Page / St.pm
1 package Gruntmaster::Page::St;
2
3 use Gruntmaster::Page::Base st => 'Standings';
4
5 use constant LEVEL_VALUES => {
6 beginner => 100,
7 easy => 250,
8 medium => 500,
9 hard => 1000,
10 };
11
12 sub calc_score{
13 my ($user, $problem, $date, $tries, $totaltime) = @_;
14 my $mxscore = LEVEL_VALUES->{problem_level($problem)};
15 my $score = $mxscore;
16 my $timetaken = $date - get_open($problem, $user);
17 $timetaken = 0 if $timetaken < 0;
18 $timetaken = 300 if $timetaken > $totaltime;
19 $score = ($totaltime - $timetaken) / $totaltime * $score;
20 $score -= $tries / 10 * $mxscore;
21 $score = $mxscore * 3 / 10 if $score < $mxscore * 3 / 10;
22 int $score + 0.5
23 }
24
25 sub _generate{
26 my ($self, $htc, $lang, $env, $ct) = @_;
27 debug $env => "language is '$lang' and contest is '$ct'";
28 my ($totaltime, $start);
29
30 local $Gruntmaster::Data::contest;
31 if ($ct) {
32 $start = contest_start ($ct);
33 $totaltime = contest_end ($ct) - $start;
34 $Gruntmaster::Data::contest = $ct;
35 }
36
37 my @problems = problems;
38 @problems = sort @problems;
39 my (%scores, %tries);
40 for (1 .. jobcard) {
41 next unless defined job_user && defined job_problem && defined job_result;
42 next if $Gruntmaster::Data::contest && job_date() < $start;
43
44 if ($Gruntmaster::Data::contest) {
45 $scores{job_user()}{job_problem()} = job_result() ? 0 : calc_score (job_user(), job_problem(), job_date(), $tries{job_user()}{job_problem()}, $totaltime);
46 $tries{job_user()}{job_problem()}++;
47 } else {
48 no warnings 'numeric';
49 $scores{job_user()}{job_problem()} = 0 + job_result_text() || (job_result() ? 0 : 100)
50 }
51 }
52
53 my @st = sort { $b->{score} <=> $a->{score} or $a->{user} cmp $b->{user}} map {
54 my $user = $_;
55 +{
56 user => $user,
57 name => do {local $Gruntmaster::Data::contest; user_name $user},
58 score => sum (values $scores{$user}),
59 scores => [map { $scores{$user}{$_} // '-'} @problems],
60 problems => $Gruntmaster::Data::contest,
61 }
62 } keys %scores;
63
64 $st[0]->{rank} = 1;
65 $st[$_]->{rank} = $st[$_ - 1]->{rank} + ($st[$_]->{score} < $st[$_ - 1]->{score}) for 1 .. $#st;
66 $htc->param(problems => [map { problem_name } @problems ]) if $Gruntmaster::Data::contest;
67 $htc->param(st => \@st);
68 }
69
70 1
This page took 0.053619 seconds and 4 git commands to generate.