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 ] ]
$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))});
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} };
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
}
$_->{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;
};
};
sortby { $b->{id} <=> $a->{id}};
mangle {
+ my $env = shift;
$_->{results} &&= decode_json $_->{results};
$_->{owner_name} = $_->{rs}->owner->name;
$_->{problem_name} = $_->{rs}->problem->name;
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
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';
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';