]> iEval git - gruntmaster-page.git/blame_incremental - lib/Gruntmaster/Page/St.pm
Improve standings
[gruntmaster-page.git] / lib / Gruntmaster / Page / St.pm
... / ...
CommitLineData
1package Gruntmaster::Page::St;
2
3use 5.014000;
4use strict;
5use warnings;
6use Gruntmaster::Page::Base st => 'Standings';
7our @ISA = qw/Gruntmaster::Page::Base/;
8our $VERSION = '0.001';
9
10use constant TEMPLATES => {
11 en => <<'HTML',
12<table border>
13<thead>
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
18<tbody>
19<tmpl_loop st><tr><td><tmpl_var user>
20<tmpl_if problems><tmpl_loop scores><td><tmpl_var _>
21</tmpl_loop></tmpl_if><td><tmpl_var score>
22</tmpl_loop>
23</table>
24HTML
25};
26
27use constant LEVEL_VALUES => {
28 beginner => 100,
29 easy => 250,
30 medium => 500,
31 hard => 1000,
32};
33
34sub calc_score{
35 my ($user, $problem, $date, $tries, $totaltime) = @_;
36 my $mxscore = LEVEL_VALUES->{problem_level($problem)};
37 my $score = $mxscore;
38 my $timetaken = $date - get_open($problem, $user);
39 $timetaken = 0 if $timetaken < 0;
40 $timetaken = 300 if $timetaken > $totaltime;
41 $score = ($totaltime - $timetaken) / $totaltime * $score;
42 $score -= $tries / 10 * $mxscore;
43 $score = $mxscore * 3 / 10 if $score < $mxscore * 3 / 10;
44 int $score
45}
46
47sub _generate{
48 my ($self, $htc, $path, $lang) = @_;
49 my $totaltime;
50
51 $path =~ m,^(?:ct/([^/]+)/)?,;
52 local $Gruntmaster::Data::contest;
53 if ($1) {
54 $totaltime = contest_end ($1) - contest_start ($1);
55 $Gruntmaster::Data::contest = $1;
56 }
57
58 my @problems = problems;
59 @problems = sort @problems;
60 my (%scores, %tries);
61 for (1 .. jobcard) {
62 if ($Gruntmaster::Data::contest) {
63 $tries{job_user()}{job_problem()}++;
64 $scores{job_user()}{job_problem()} = job_result() ? 0 : calc_score (job_user(), job_problem(), job_date(), $tries{job_user()}{job_problem()}, $totaltime);
65 } else {
66 if (job_result_text =~ m/^(\d+)/) {
67 $scores{job_user()}{job_problem()} = $1;
68 } else {
69 $scores{job_user()}{job_problem()} = job_result() ? 0 : 100;
70 }
71 }
72 }
73
74 my @st = sort { $b->{score} <=> $a->{score} } map {
75 my $user = $_;
76 +{
77 user => $user,
78 score => sum (values $scores{$user}),
79 scores => [map { $scores{$user}{$_} // '-'} @problems],
80 problems => $Gruntmaster::Data::contest,
81 }
82 } keys %scores;
83 $htc->param(problems => [map { problem_name } @problems ]) if $Gruntmaster::Data::contest;
84 $htc->param(st => \@st);
85}
86
871
This page took 0.02461 seconds and 4 git commands to generate.