From: Marius Gavrilescu Date: Mon, 23 Dec 2013 06:49:14 +0000 (+0200) Subject: Add standings X-Git-Url: http://git.ieval.ro/?a=commitdiff_plain;h=5bbf0128012c09c78462ee49b874f968385b0978;p=gruntmaster-page.git Add standings --- diff --git a/gruntmaster-genallpages b/gruntmaster-genallpages index 2a08af0..5ba2bfd 100755 --- a/gruntmaster-genallpages +++ b/gruntmaster-genallpages @@ -14,6 +14,7 @@ generate "$_/index.html" for grep {-d} ; for my $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/*>; diff --git a/lib/Gruntmaster/Page.pm b/lib/Gruntmaster/Page.pm index 00f2cdb..7b5e933 100644 --- a/lib/Gruntmaster/Page.pm +++ b/lib/Gruntmaster/Page.pm @@ -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$,; diff --git a/lib/Gruntmaster/Page/Ct/Entry.pm b/lib/Gruntmaster/Page/Ct/Entry.pm index 50ee0c2..725e3e9 100644 --- a/lib/Gruntmaster/Page/Ct/Entry.pm +++ b/lib/Gruntmaster/Page/Ct/Entry.pm @@ -25,7 +25,7 @@ Contest end time:

Problems
Job log
-Standings
+Standings HTML ); diff --git a/lib/Gruntmaster/Page/Pb.pm b/lib/Gruntmaster/Page/Pb.pm index a2cccff..a3902c2 100644 --- a/lib/Gruntmaster/Page/Pb.pm +++ b/lib/Gruntmaster/Page/Pb.pm @@ -33,11 +33,6 @@ my %templates = (

  • -

    Advanced

    -
      -
    • -
    -

    Hard

    • diff --git a/lib/Gruntmaster/Page/St.pm b/lib/Gruntmaster/Page/St.pm new file mode 100644 index 0000000..f4d961e --- /dev/null +++ b/lib/Gruntmaster/Page/St.pm @@ -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', + + + +
      UsernameTotal +
      + + + +
      +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