]> iEval git - gruntmaster-page.git/blame - lib/Gruntmaster/Page/St.pm
Add Account page
[gruntmaster-page.git] / lib / Gruntmaster / Page / St.pm
CommitLineData
5bbf0128
MG
1package Gruntmaster::Page::St;
2
3use 5.014000;
4use strict;
5use warnings;
6use parent qw/Exporter/;
7our @EXPORT_OK = qw/generate/;
8our $VERSION = '0.001';
9
10use constant TITLE => 'Standings';
11
5bbf0128 12use HTML::Template::Compiled;
5bbf0128
MG
13use List::Util qw/sum/;
14use POSIX qw/strftime/;
5bbf0128 15use Gruntmaster::Page::Common qw/header footer/;
cd9af27e 16use Gruntmaster::Data qw/problems jobcard job_result_text job_result job_problem job_user/;
5bbf0128
MG
17
18my %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>
29HTML
30);
31
32$templates{$_} = header($_, TITLE) . $templates{$_} for keys %templates;
33$templates{$_} .= footer $_ for keys %templates;
34
35sub 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
621
This page took 0.025917 seconds and 4 git commands to generate.