]>
Commit | Line | Data |
---|---|---|
5bbf0128 MG |
1 | package Gruntmaster::Page::St; |
2 | ||
3 | use 5.014000; | |
4 | use strict; | |
5 | use warnings; | |
bb95f538 MG |
6 | use Gruntmaster::Page::Base st => 'Standings'; |
7 | our @ISA = qw/Gruntmaster::Page::Base/; | |
5bbf0128 MG |
8 | our $VERSION = '0.001'; |
9 | ||
410a7b48 | 10 | use constant TEMPLATES => { |
cd9af27e | 11 | en => <<'HTML', |
5bbf0128 MG |
12 | <table border> |
13 | <thead> | |
746789c0 MG |
14 | <tmpl_if problems><tr><th>Username<tmpl_loop problems><th><tmpl_var _></tmpl_loop><th>Total |
15 | <tmpl_else><tr><th>Username<th>Score | |
16 | </tmpl_if> | |
17 | ||
5bbf0128 MG |
18 | <tbody> |
19 | <tmpl_loop st><tr><td><tmpl_var user> | |
746789c0 MG |
20 | <tmpl_if problems><tmpl_loop scores><td><tmpl_var _> |
21 | </tmpl_loop></tmpl_if><td><tmpl_var score> | |
5bbf0128 MG |
22 | </tmpl_loop> |
23 | </table> | |
24 | HTML | |
bb95f538 | 25 | }; |
5bbf0128 | 26 | |
d17951d1 MG |
27 | use constant LEVEL_VALUES => { |
28 | beginner => 100, | |
29 | easy => 250, | |
30 | medium => 500, | |
31 | hard => 1000, | |
32 | }; | |
33 | ||
34 | sub calc_score{ | |
ca3dffeb | 35 | my ($user, $problem, $date, $tries, $totaltime) = @_; |
d17951d1 MG |
36 | my $mxscore = LEVEL_VALUES->{problem_level($problem)}; |
37 | my $score = $mxscore; | |
38 | my $timetaken = $date - get_open($problem, $user); | |
ca3dffeb MG |
39 | $timetaken = 0 if $timetaken < 0; |
40 | $timetaken = 300 if $timetaken > $totaltime; | |
41 | $score = ($totaltime - $timetaken) / $totaltime * $score; | |
d17951d1 MG |
42 | $score -= $tries / 10 * $mxscore; |
43 | $score = $mxscore * 3 / 10 if $score < $mxscore * 3 / 10; | |
44 | int $score | |
45 | } | |
46 | ||
bb95f538 | 47 | sub _generate{ |
7dc32473 MG |
48 | my ($self, $htc, $lang, $logger, $ct) = @_; |
49 | debug $logger => "language is '$lang' and contest is '$ct'"; | |
a90230ea | 50 | my ($totaltime, $start); |
5bbf0128 | 51 | |
ca3dffeb | 52 | local $Gruntmaster::Data::contest; |
7dc32473 MG |
53 | if ($ct) { |
54 | $start = contest_start ($ct); | |
55 | $totaltime = contest_end ($ct) - $start; | |
56 | $Gruntmaster::Data::contest = $ct; | |
ca3dffeb | 57 | } |
cd9af27e | 58 | |
410a7b48 MG |
59 | my @problems = problems; |
60 | @problems = sort @problems; | |
d17951d1 | 61 | my (%scores, %tries); |
cd9af27e | 62 | for (1 .. jobcard) { |
d17951d1 MG |
63 | if ($Gruntmaster::Data::contest) { |
64 | $tries{job_user()}{job_problem()}++; | |
a90230ea | 65 | $scores{job_user()}{job_problem()} = job_result() ? 0 : calc_score (job_user(), job_problem(), job_date(), $tries{job_user()}{job_problem()}, $totaltime) if job_date() > $start; |
cd9af27e | 66 | } else { |
7dc32473 MG |
67 | if (job_result_text =~ m/^(\scores+)/) { |
68 | $scores{job_user()}{job_problem()} = $ct; | |
d17951d1 MG |
69 | } else { |
70 | $scores{job_user()}{job_problem()} = job_result() ? 0 : 100; | |
71 | } | |
cd9af27e | 72 | } |
5bbf0128 | 73 | } |
5bbf0128 | 74 | |
cd9af27e MG |
75 | my @st = sort { $b->{score} <=> $a->{score} } map { |
76 | my $user = $_; | |
77 | +{ | |
78 | user => $user, | |
79 | score => sum (values $scores{$user}), | |
80 | scores => [map { $scores{$user}{$_} // '-'} @problems], | |
ca3dffeb | 81 | problems => $Gruntmaster::Data::contest, |
cd9af27e MG |
82 | } |
83 | } keys %scores; | |
746789c0 | 84 | $htc->param(problems => [map { problem_name } @problems ]) if $Gruntmaster::Data::contest; |
cd9af27e | 85 | $htc->param(st => \@st); |
5bbf0128 MG |
86 | } |
87 | ||
88 | 1 |