my ($self, $ct) = @_;
$ct &&= $self->contest($ct);
- my @problems = map { $_->problem } $self->contest_problems->search({contest => $ct && $ct->id}, {qw/join problem order_by problem.level/});
- my (%scores, %tries);
- for my $job ($self->jobs->search({contest => $ct && $ct->id}, {order_by => 'id'})) {
+ my @problems = map { $_->rawproblem } $self->contest_problems->search({contest => $ct && $ct->id}, {qw/join problem order_by problem.level/});
+ my (%scores, %tries, %opens);
+ $opens{$_->rawproblem, $_->rawowner} = $_ for $self->opens->search({contest => $ct && $ct->id});
+ for my $job ($self->jobs->search({contest => $ct && $ct->id}, {qw/order_by me.id prefetch/ => [qw/problem/]})) {
if ($ct) {
- my $open = $self->opens->find($ct->id, $job->problem->id, $job->owner->id);
+ my $open = $opens{$job->rawproblem, $job->rawowner};
my $time = $job->date - ($open ? $open->time : $ct->start);
next if $time < 0;
my $value = $job->problem->value;
my $factor = $job->result ? 0 : 1;
$factor = $1 / 100 if $job->result_text =~ /^(\d+ )/s;
- $scores{$job->owner->id}{$job->problem->id} = int ($factor * calc_score ($value, $time, $tries{$job->owner->id}{$job->problem->id}++, $ct->stop - $ct->start));
+ $scores{$job->rawowner}{$job->rawproblem} = int ($factor * calc_score ($value, $time, $tries{$job->rawowner}{$job->rawproblem}++, $ct->stop - $ct->start));
} else {
no warnings 'numeric'; ## no critic (ProhibitNoWarnings)
- $scores{$job->owner->id}{$job->problem->id} = 0 + $job->result_text || ($job->result ? 0 : 100)
+ $scores{$job->rawowner}{$job->rawproblem} = 0 + $job->result_text || ($job->result ? 0 : 100)
}
}
- my @st = sort { $b->{score} <=> $a->{score} or $a->{user}->id cmp $b->{user}->id} map { ## no critic (ProhibitReverseSortBlock)
+ my %user_to_name = map { $_ => $_->name } $self->users->all;
+
+ my @st = sort { $b->{score} <=> $a->{score} or $a->{user} cmp $b->{user} } map { ## no critic (ProhibitReverseSortBlock)
my $user = $_;
+{
- user => $self->user($user),
+ user => $user,
+ user_name => $user_to_name{$user},
score => sum (values %{$scores{$user}}),
- scores => [map { $scores{$user}{$_->id} // '-'} @problems],
+ scores => [map { $scores{$user}{$_} // '-'} @problems],
problems => $ct,
}
} keys %scores;
sub update_status {
my ($self) = @_;
my @jobs = $self->jobs->search(undef, {cache => 1})->all;
+
my %hash;
- $hash{$_->get_column('problem'), $_->get_column('owner')} = [$_, $_->result ? 1 : 0] for @jobs;
+ $hash{$_->get_column('problem'), $_->get_column('owner')} = [$_->id, $_->result ? 1 : 0] for @jobs;
my @problem_statuses = map { [split ($;), @{$hash{$_}} ] } keys %hash;
my @contest_statuses = map {