]> iEval git - gruntmaster-page.git/commitdiff
Add standings
authorMarius Gavrilescu <marius@ieval.ro>
Mon, 23 Dec 2013 06:49:14 +0000 (08:49 +0200)
committerMarius Gavrilescu <marius@ieval.ro>
Mon, 23 Dec 2013 07:00:49 +0000 (09:00 +0200)
gruntmaster-genallpages
lib/Gruntmaster/Page.pm
lib/Gruntmaster/Page/Ct/Entry.pm
lib/Gruntmaster/Page/Pb.pm
lib/Gruntmaster/Page/St.pm [new file with mode: 0644]

index 2a08af01d1c9af6a7136a07a8f53bb7acd92e86c..5ba2bfdbc814b8d1e4bc98e86c5821821a428276 100755 (executable)
@@ -14,6 +14,7 @@ generate "$_/index.html" for grep {-d} <ct/*>;
 
 for my $ct ('', <ct/*/>) {
   generate "${ct}log/index.html";
+  generate "${ct}log/st.html" if length $ct;
   generate "${ct}pb/index.html";
   generate "${ct}submit.html";
   generate "$_/index.html" for grep {-d} <${ct}log/*>, <${ct}pb/*>;
index 00f2cdbaa03de2b03e141cc8868040ac60abeec0..7b5e9339cd9f613eb3c47eee1b24be05b8034a28 100644 (file)
@@ -35,7 +35,7 @@ sub declaregen{
   declaregen Index        => qr,^index$,;
   declaregen Ct           => qr,^ct/index$,;
   declaregen 'Ct::Entry'  => qr,^ct/$component/index$,;
-  #declaregen St           => qr,^ct/$component/st/index$,;
+  declaregen St           => qr,^ct/$component/log/st$,;
   declaregen Log          => qr,^${contest}log/index$,;
   declaregen 'Log::Entry' => qr,^${contest}log/$component/index$,;
   declaregen Submit       => qr,^${contest}submit$,;
index 50ee0c2b259d1879f77e5233cea04e91df776b38..725e3e9ef9aaf222dfb3973612142fe5764d67e4 100644 (file)
@@ -25,7 +25,7 @@ Contest end time: <tmpl_var end><p>
 
 <tmpl_if started><a href="pb/">Problems</a><br>
 <a href="log/">Job log</a><br>
-<a href="st/">Standings</a></tmpl_if>
+<a href="log/st.var">Standings</a></tmpl_if>
 HTML
 );
 
index a2cccff504516d7c90969a00977c2be54a584ec8..a3902c23676ed296a9e1173105bd7fec3a0d2780 100644 (file)
@@ -33,11 +33,6 @@ my %templates = (
 <tmpl_loop medium><li><a href="<tmpl_var id>"><tmpl_var name></a>
 </tmpl_loop></ul>
 
-<h2>Advanced</h2>
-<ul>
-<tmpl_loop advanced><li><a href="<tmpl_var id>"><tmpl_var name></a>
-</tmpl_loop></ul>
-
 <h2>Hard</h2>
 <ul>
 <tmpl_loop hard><li><a href="<tmpl_var id>"><tmpl_var name></a>
diff --git a/lib/Gruntmaster/Page/St.pm b/lib/Gruntmaster/Page/St.pm
new file mode 100644 (file)
index 0000000..f4d961e
--- /dev/null
@@ -0,0 +1,69 @@
+package Gruntmaster::Page::St;
+
+use 5.014000;
+use strict;
+use warnings;
+use parent qw/Exporter/;
+our @EXPORT_OK = qw/generate/;
+our $VERSION = '0.001';
+
+use constant TITLE => 'Standings';
+
+use Fcntl qw/:flock/;
+use HTML::Template::Compiled;
+use IO::File;
+use List::Util qw/sum/;
+use POSIX qw/strftime/;
+use YAML::Any qw/LoadFile/;
+use Gruntmaster::Page::Common qw/header footer/;
+
+my %templates = (
+  en => <<'HTML',
+<table border>
+<thead>
+<tr><th>Username<tmpl_loop problems><th><tmpl_var _></tmpl_loop><th>Total
+<tbody>
+<tmpl_loop st><tr><td><tmpl_var user>
+<tmpl_loop scores><td><tmpl_var _>
+</tmpl_loop><td><tmpl_var score>
+</tmpl_loop>
+</table>
+HTML
+);
+
+$templates{$_}  = header($_, TITLE) . $templates{$_} for keys %templates;
+$templates{$_} .= footer $_ for keys %templates;
+
+sub generate{
+  my ($path, $lang) = @_;
+  $path =~ s,/st\.html$,,;
+  my $template = $templates{$lang};
+  my $htc = HTML::Template::Compiled->new(scalarref => \$template);
+  IO::File->new(">$path/meta.yml")->close unless -f "$path/meta.yml";
+  flock my $metafh = IO::File->new("<$path/meta.yml"), LOCK_SH;
+  my $meta = LoadFile "$path/meta.yml";
+  my @problems = sort grep { /^\w+$/ } map { s,.*/,,r } <$path/../pb/*>;
+  my %scores;
+  for (1 .. $meta->{last}) {
+       my $meta = LoadFile "$path/$_/meta.yml";
+       if ($meta->{result_text} =~ m/^(\d+)/) {
+         $scores{$meta->{user}}{$meta->{problem}} = $1;
+       } else {
+         $scores{$meta->{user}}{$meta->{problem}} = $meta->{result} ? 0 : 100;
+       }
+  }
+
+  my @st = sort { $b->{score} <=> $a->{score} } map {
+       my $user = $_;
+       +{
+         user => $user,
+         score => sum (values $scores{$user}),
+         scores => [map { $scores{$user}{$_} // '-'} @problems],
+       }
+  } keys %scores;
+  $htc->param(problems => \@problems);
+  $htc->param(st => \@st);
+  $htc->output
+}
+
+1
This page took 0.023081 seconds and 4 git commands to generate.