sub standings {
my ($self, $ct) = @_;
- $ct &&= $self->contest($ct);
+ my $ctobj = $self->contest($ct);
- my @problems = map { $_->rawproblem } $self->contest_problems->search({contest => $ct && $ct->id}, {qw/join problem order_by problem.level/});
+ my @problems = map { $_->rawproblem } $self->contest_problems->search({contest => $ct}, {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 = $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->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->rawowner}{$job->rawproblem} = 0 + $job->result_text || ($job->result ? 0 : 100)
- }
+ $opens{$_->rawproblem, $_->rawowner} = $_ for $self->opens->search({contest => $ct});
+ for my $job ($self->jobs->search({contest => $ct}, {qw/order_by me.id prefetch/ => [qw/problem/]})) {
+ my $open = $opens{$job->rawproblem, $job->rawowner};
+ my $time = $job->date - ($open ? $open->time : $ctobj->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->rawowner}{$job->rawproblem} = int ($factor * calc_score ($value, $time, $tries{$job->rawowner}{$job->rawproblem}++, $ctobj->stop - $ctobj->start));
}
my %user_to_name = map { $_ => $_->name } $self->users->all;
user_name => $user_to_name{$user},
score => sum (values %{$scores{$user}}),
scores => [map { $scores{$user}{$_} // '-'} @problems],
- problems => $ct,
}
} keys %scores;