]>
Commit | Line | Data |
---|---|---|
5bbf0128 MG |
1 | package Gruntmaster::Page::St; |
2 | ||
3 | use 5.014000; | |
4 | use strict; | |
5 | use warnings; | |
6 | use parent qw/Exporter/; | |
7 | our @EXPORT_OK = qw/generate/; | |
8 | our $VERSION = '0.001'; | |
9 | ||
10 | use constant TITLE => 'Standings'; | |
11 | ||
5bbf0128 | 12 | use HTML::Template::Compiled; |
5bbf0128 MG |
13 | use List::Util qw/sum/; |
14 | use POSIX qw/strftime/; | |
5bbf0128 | 15 | use Gruntmaster::Page::Common qw/header footer/; |
cd9af27e | 16 | use Gruntmaster::Data qw/problems jobcard job_result_text job_result job_problem job_user/; |
5bbf0128 MG |
17 | |
18 | my %templates = ( | |
cd9af27e | 19 | en => <<'HTML', |
5bbf0128 MG |
20 | <table border> |
21 | <thead> | |
22 | <tr><th>Username<tmpl_loop problems><th><tmpl_var _></tmpl_loop><th>Total | |
23 | <tbody> | |
24 | <tmpl_loop st><tr><td><tmpl_var user> | |
25 | <tmpl_loop scores><td><tmpl_var _> | |
26 | </tmpl_loop><td><tmpl_var score> | |
27 | </tmpl_loop> | |
28 | </table> | |
29 | HTML | |
30 | ); | |
31 | ||
32 | $templates{$_} = header($_, TITLE) . $templates{$_} for keys %templates; | |
33 | $templates{$_} .= footer $_ for keys %templates; | |
34 | ||
35 | sub generate{ | |
cd9af27e MG |
36 | local $Gruntmaster::Data::contest = ($_[0] =~ m,^ct/([^/]+)/,)[0]; |
37 | my $htc = HTML::Template::Compiled->new(scalarref => \$templates{$_[1]}); | |
38 | ||
39 | my @problems = sort problems; | |
40 | my %scores; | |
41 | for (1 .. jobcard) { | |
42 | if (job_result_text =~ m/^(\d+)/) { | |
43 | $scores{job_user()}{job_problem()} = $1; | |
44 | } else { | |
45 | $scores{job_user()}{job_problem()} = job_result() ? 0 : 100; | |
46 | } | |
5bbf0128 | 47 | } |
5bbf0128 | 48 | |
cd9af27e MG |
49 | my @st = sort { $b->{score} <=> $a->{score} } map { |
50 | my $user = $_; | |
51 | +{ | |
52 | user => $user, | |
53 | score => sum (values $scores{$user}), | |
54 | scores => [map { $scores{$user}{$_} // '-'} @problems], | |
55 | } | |
56 | } keys %scores; | |
57 | $htc->param(problems => \@problems); | |
58 | $htc->param(st => \@st); | |
59 | $htc->output | |
5bbf0128 MG |
60 | } |
61 | ||
62 | 1 |