]> iEval git - gruntmaster-page.git/blob - lib/Gruntmaster/Page/St.pm
Add Account page
[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 parent qw/Exporter/;
7 our @EXPORT_OK = qw/generate/;
8 our $VERSION = '0.001';
9
10 use constant TITLE => 'Standings';
11
12 use HTML::Template::Compiled;
13 use List::Util qw/sum/;
14 use POSIX qw/strftime/;
15 use Gruntmaster::Page::Common qw/header footer/;
16 use Gruntmaster::Data qw/problems jobcard job_result_text job_result job_problem job_user/;
17
18 my %templates = (
19 en => <<'HTML',
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{
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 }
47 }
48
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
60 }
61
62 1
This page took 0.045861 seconds and 4 git commands to generate.