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