]> iEval git - gruntmaster-page.git/blame - lib/Gruntmaster/Page/St.pm
Add user list and user pages
[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
5bbf0128 10use HTML::Template::Compiled;
5bbf0128
MG
11use List::Util qw/sum/;
12use POSIX qw/strftime/;
2b0036ac 13use Gruntmaster::Page::Common qw/cook_templates reload_templates/;
cd9af27e 14use Gruntmaster::Data qw/problems jobcard job_result_text job_result job_problem job_user/;
5bbf0128 15
2b0036ac 16my %orig_templates = (
cd9af27e 17 en => <<'HTML',
5bbf0128
MG
18<table border>
19<thead>
20<tr><th>Username<tmpl_loop problems><th><tmpl_var _></tmpl_loop><th>Total
21<tbody>
22<tmpl_loop st><tr><td><tmpl_var user>
23<tmpl_loop scores><td><tmpl_var _>
24</tmpl_loop><td><tmpl_var score>
25</tmpl_loop>
26</table>
27HTML
28);
29
2b0036ac 30my %templates = cook_templates %orig_templates, st => 'Standings';
5bbf0128
MG
31
32sub generate{
2b0036ac 33 %templates = cook_templates %orig_templates, st => 'Standings' if reload_templates;
cd9af27e
MG
34 local $Gruntmaster::Data::contest = ($_[0] =~ m,^ct/([^/]+)/,)[0];
35 my $htc = HTML::Template::Compiled->new(scalarref => \$templates{$_[1]});
36
37 my @problems = sort problems;
38 my %scores;
39 for (1 .. jobcard) {
40 if (job_result_text =~ m/^(\d+)/) {
41 $scores{job_user()}{job_problem()} = $1;
42 } else {
43 $scores{job_user()}{job_problem()} = job_result() ? 0 : 100;
44 }
5bbf0128 45 }
5bbf0128 46
cd9af27e
MG
47 my @st = sort { $b->{score} <=> $a->{score} } map {
48 my $user = $_;
49 +{
50 user => $user,
51 score => sum (values $scores{$user}),
52 scores => [map { $scores{$user}{$_} // '-'} @problems],
53 }
54 } keys %scores;
55 $htc->param(problems => \@problems);
56 $htc->param(st => \@st);
57 $htc->output
5bbf0128
MG
58}
59
601
This page took 0.028038 seconds and 4 git commands to generate.