Import some changes from the mindcoding branch
authorMarius Gavrilescu <marius@ieval.ro>
Fri, 18 Apr 2014 15:03:58 +0000 (18:03 +0300)
committerMarius Gavrilescu <marius@ieval.ro>
Fri, 18 Apr 2014 15:03:58 +0000 (18:03 +0300)
lib/Gruntmaster/Page/Base.pm
lib/Gruntmaster/Page/Generic.pm
lib/Gruntmaster/Page/Register.pm
lib/Gruntmaster/Page/St.pm

index 99ca432732cfc9d8a9a27ba21e79752a01d2f726..1a68b3c2b48658513d8796ad02cad0434ac8327b 100644 (file)
@@ -88,6 +88,7 @@ sub generate{
        my $htc = HTML::Template::Compiled->new(scalarref => \$templates{$self}{$lang}, default_escape => 'HTML', use_perl => 1);
        $self->_generate($htc, $lang, @args);
        my $out = $htc->output;
+       utf8::decode($out) for 1 .. 3;
        utf8::encode($out);
        my $vary = 'Accept-Language, ' . $self->vary;
        [200, ['Content-Type' => 'text/html', 'Content-Language' => $_[1], 'Vary' => $vary, 'X-Forever' => 1, 'Cache-Control' => 'max-age=' . $self->max_age], [ $out ] ]
index 9e07d4c8a68814aa11189b8a8f5a30e7d9390864..15b887ea03c64d778fbf38738c3c5857d75603cf 100644 (file)
@@ -38,6 +38,8 @@ sub list {
        $rs = $rs->search(undef, {order_by => 'me.id'}) unless $rs->is_ordered;
        if (my $page = $env->{'gruntmaster.page'}) {
                my $pages = int ($rs->count / PAGE_SIZE);
+               $params{default_page} = $page == -1;
+               $pages = 1 if $pages < 1;
                $page = $pages if $page == -1;
                @params{'page', 'pages'} = ($page, $pages);
                $rs = $rs->search(undef, {offset => ($page - 1) * PAGE_SIZE, ($page == $pages ? () : (rows => PAGE_SIZE))});
@@ -47,7 +49,7 @@ sub list {
                exists $thing{columns} ? (columns => $thing{columns}) : (),
        });
        my @thing = map +{rs => $_, $_->get_columns}, $rs->all;
-       @thing = map  { $thing{mangle}->(); $_ } @thing if exists $thing{mangle};
+       @thing = map  { $thing{mangle}->($env); $_ } @thing if exists $thing{mangle};
        @thing = grep { $thing{choose}->() } @thing if exists $thing{choose};
        @thing = sort { $thing{sortby}->() } @thing if exists $thing{sortby};
        $thing{group} //= sub { $thing{id} };
@@ -64,7 +66,8 @@ sub entry {
        my %thing = %$thing;
        debug $env => "Rsname is $thing{rsname} and id is $id";
        my %params = map {+ rs => $_, $_->get_columns } db($env)->resultset($thing{rsname})->find($id);
-       $thing{mangle}->(local $_ = \%params) if exists $thing{mangle};
+       local $_ = \%params;
+       $thing{mangle}->($env) if exists $thing{mangle};
        wantarray ? %params : \%params
 }
 
@@ -132,10 +135,11 @@ thing {
                $_->{owner_name} = $_->{rs}->owner->name;
                $_->{cansubmit} = $env->{'gruntmaster.contest'} ? time < db($env)->contest($env->{'gruntmaster.contest'})->stop : 1;
                eval {
-                       db($env)->open->create({
+                       db($env)->opens->create({
                                contest => $env->{'gruntmaster.contest'},
                                problem => $_->{id},
                                owner   => $env->{REMOTE_USER},
+                               time    => time,
                        })
                } if $env->{'gruntmaster.contest'} && time >= db($env)->contest($env->{'gruntmaster.contest'})->start;
        };
@@ -161,6 +165,7 @@ thing {
        };
        sortby { $b->{id} <=> $a->{id}};
        mangle {
+               my $env = shift;
                $_->{results} &&= decode_json $_->{results};
                $_->{owner_name} = $_->{rs}->owner->name;
                $_->{problem_name} = $_->{rs}->problem->name;
@@ -171,5 +176,6 @@ thing {
 
 putsym 'Gruntmaster::Page::Pb::Entry::vary',    sub { 'Authorization' };
 putsym 'Gruntmaster::Page::Pb::Entry::max_age', sub { 600 };
+putsym 'Gruntmaster::Page::Log::max_age', sub { 10 };
 
 1
index ed2566058c7e334fbd989d399568c5b39d25be18..ef2760f4ebac4198dc70d294c99dd2298b384129 100644 (file)
@@ -14,7 +14,7 @@ sub generate{
        return reply 'All fields are required' if grep { !length } $username, $password, $confirm_password, $name, $email, $phone, $town, $university, $level;
        pwset $username, $password;
 
-       db($env)->create({id => $username, name => $name, email => $email, phone => $phone, town => $town, university => $university, level => $level});
+       db($env)->users->create({id => $username, name => $name, email => $email, phone => $phone, town => $town, university => $university, level => $level});
 
        purge  "/us/";
        reply 'Registered successfully';
index 547eaba544297c8ea7d49947558e9c90ee8a2b5d..9ed2a31c67c6c05d6b911de09c9af400dcd02bbf 100644 (file)
@@ -28,13 +28,16 @@ sub _generate{
 
        my @problems = map { $_->problem } db($env)->contest_problems->search({contest => $ct && $ct->id}, {qw/join problem order_by problem.level/});
        my (%scores, %tries);
-       for my $job (db($env)->jobs->search({contest => $ct && $ct->id})) {
+       for my $job (db($env)->jobs->search({contest => $ct && $ct->id}, {order_by => 'id'})) {
 
                if ($ct) {
-                       my $time = $job->date - $ct->start;
+                       my $open = db($env)->opens->find($ct->id, $job->problem->id, $job->owner->id);
+                       my $time = $job->date - ($open ? $open->time : $ct->start);
                        next if $time < 0;
                        my $value = $job->problem->value // LEVEL_VALUES->{$job->problem->level};
-                       $scores{$job->owner->id}{$job->problem->id} = $job->result ? 0 : calc_score ($value, $time, $tries{$job->owner}{$job->problem}, $ct->stop - $ct->start);
+                       my $factor = $job->result ? 0 : 1;
+                       $factor = $1 / 100 if $job->result_text =~ /^(\d+ )/;
+                       $scores{$job->owner->id}{$job->problem->id} = int ($factor * calc_score ($value, $time, $tries{$job->owner->id}{$job->problem->id}, $ct->stop - $ct->start));
                        $tries{$job->owner->id}{$job->problem->id}++;
                } else {
                        no warnings 'numeric';
This page took 0.018932 seconds and 4 git commands to generate.