]> iEval git - gruntmaster-page.git/blame - lib/Gruntmaster/Page/St.pm
Add contest support to gensrc
[gruntmaster-page.git] / lib / Gruntmaster / Page / St.pm
CommitLineData
5bbf0128
MG
1package Gruntmaster::Page::St;
2
3use 5.014000;
4use strict;
5use warnings;
bb95f538
MG
6use Gruntmaster::Page::Base st => 'Standings';
7our @ISA = qw/Gruntmaster::Page::Base/;
5bbf0128
MG
8our $VERSION = '0.001';
9
410a7b48 10use 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>
24HTML
bb95f538 25};
5bbf0128 26
d17951d1
MG
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) = @_;
36 my $mxscore = LEVEL_VALUES->{problem_level($problem)};
37 my $score = $mxscore;
38 my $timetaken = $date - get_open($problem, $user);
39 $timetaken = 1 if $timetaken < 1;
40 $timetaken = 150 + int rand 150 if $timetaken > 3600;
41 $score = (3600 - $timetaken) / 3600 * $score;
42 $score -= $tries / 10 * $mxscore;
43 $score = $mxscore * 3 / 10 if $score < $mxscore * 3 / 10;
44 int $score
45}
46
bb95f538
MG
47sub _generate{
48 my ($self, $htc, $path, $lang) = @_;
5bbf0128 49
410a7b48 50 $path =~ m,^(?:ct/([^/]+)/)?,;
d17951d1 51 local $Gruntmaster::Data::contest = $1 if $1;
cd9af27e 52
410a7b48
MG
53 my @problems = problems;
54 @problems = sort @problems;
d17951d1 55 my (%scores, %tries);
cd9af27e 56 for (1 .. jobcard) {
d17951d1
MG
57 if ($Gruntmaster::Data::contest) {
58 $tries{job_user()}{job_problem()}++;
59 $scores{job_user()}{job_problem()} = job_result() ? 0 : calc_score (job_user(), job_problem(), job_date(), $tries{job_user()}{job_problem()});
cd9af27e 60 } else {
d17951d1
MG
61 if (job_result_text =~ m/^(\d+)/) {
62 $scores{job_user()}{job_problem()} = $1;
63 } else {
64 $scores{job_user()}{job_problem()} = job_result() ? 0 : 100;
65 }
cd9af27e 66 }
5bbf0128 67 }
5bbf0128 68
cd9af27e
MG
69 my @st = sort { $b->{score} <=> $a->{score} } map {
70 my $user = $_;
71 +{
72 user => $user,
73 score => sum (values $scores{$user}),
74 scores => [map { $scores{$user}{$_} // '-'} @problems],
75 }
76 } keys %scores;
746789c0 77 $htc->param(problems => [map { problem_name } @problems ]) if $Gruntmaster::Data::contest;
cd9af27e 78 $htc->param(st => \@st);
5bbf0128
MG
79}
80
811
This page took 0.032635 seconds and 4 git commands to generate.