]> iEval git - gruntmaster-page.git/blob - lib/Gruntmaster/Page/St.pm
Add nice tables to standings
[gruntmaster-page.git] / lib / Gruntmaster / Page / St.pm
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 TEMPLATES => {
11 en => <<'HTML',
12 <table border class="table table-border table-striped">
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>
24 HTML
25 };
26
27 use constant LEVEL_VALUES => {
28 beginner => 100,
29 easy => 250,
30 medium => 500,
31 hard => 1000,
32 };
33
34 sub 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
47 sub _generate{
48 my ($self, $htc, $lang, $env, $ct) = @_;
49 debug $env => "language is '$lang' and contest is '$ct'";
50 my ($totaltime, $start);
51
52 local $Gruntmaster::Data::contest;
53 if ($ct) {
54 $start = contest_start ($ct);
55 $totaltime = contest_end ($ct) - $start;
56 $Gruntmaster::Data::contest = $ct;
57 }
58
59 my @problems = problems;
60 @problems = sort @problems;
61 my (%scores, %tries);
62 for (1 .. jobcard) {
63 if ($Gruntmaster::Data::contest) {
64 $tries{job_user()}{job_problem()}++;
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;
66 } else {
67 if (job_result_text =~ m/^(\scores+)/) {
68 $scores{job_user()}{job_problem()} = $ct;
69 } else {
70 $scores{job_user()}{job_problem()} = job_result() ? 0 : 100;
71 }
72 }
73 }
74
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],
81 problems => $Gruntmaster::Data::contest,
82 }
83 } keys %scores;
84 $htc->param(problems => [map { problem_name } @problems ]) if $Gruntmaster::Data::contest;
85 $htc->param(st => \@st);
86 }
87
88 1
This page took 0.046159 seconds and 5 git commands to generate.