]>
iEval git - gruntmaster-data.git/blob - lib/Gruntmaster/Data/Result/Contest.pm
2 package Gruntmaster
::Data
::Result
::Contest
;
4 # Created by DBIx::Class::Schema::Loader
5 # DO NOT MODIFY THE FIRST PART OF THIS FILE
9 Gruntmaster::Data::Result::Contest
16 use base
'DBIx::Class::Core';
18 =head1 TABLE: C<contests>
22 __PACKAGE__
->table("contests");
54 __PACKAGE__
->add_columns(
56 { data_type
=> "text", is_nullable
=> 0 },
58 { data_type
=> "text", is_nullable
=> 0 },
60 { data_type
=> "integer", is_nullable
=> 0 },
62 { data_type
=> "integer", is_nullable
=> 0 },
64 { data_type
=> "text", is_foreign_key
=> 1, is_nullable
=> 0 },
77 __PACKAGE__
->set_primary_key("id");
81 =head2 contest_problems
85 Related object: L<Gruntmaster::Data::Result::ContestProblem>
89 __PACKAGE__
->has_many(
91 "Gruntmaster::Data::Result::ContestProblem",
92 { "foreign.contest" => "self.id" },
93 { cascade_copy
=> 0, cascade_delete
=> 0 },
96 =head2 contest_statuses
100 Related object: L<Gruntmaster::Data::Result::ContestStatus>
104 __PACKAGE__
->has_many(
106 "Gruntmaster::Data::Result::ContestStatus",
107 { "foreign.contest" => "self.id" },
108 { cascade_copy
=> 0, cascade_delete
=> 0 },
115 Related object: L<Gruntmaster::Data::Result::Job>
119 __PACKAGE__
->has_many(
121 "Gruntmaster::Data::Result::Job",
122 { "foreign.contest" => "self.id" },
123 { cascade_copy
=> 0, cascade_delete
=> 0 },
130 Related object: L<Gruntmaster::Data::Result::Open>
134 __PACKAGE__
->has_many(
136 "Gruntmaster::Data::Result::Open",
137 { "foreign.contest" => "self.id" },
138 { cascade_copy
=> 0, cascade_delete
=> 0 },
145 Related object: L<Gruntmaster::Data::Result::User>
149 __PACKAGE__
->belongs_to(
151 "Gruntmaster::Data::Result::User",
153 { is_deferrable
=> 0, on_delete
=> "CASCADE", on_update
=> "NO ACTION" },
160 Composing rels: L</contest_problems> -> problem
164 __PACKAGE__
->many_to_many("problems", "contest_problems", "problem");
167 # Created by DBIx::Class::Schema::Loader v0.07042 @ 2014-12-11 23:51:27
168 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:nu+Io9AhYkzYCky5UpCaKQ
170 use List
::Util qw
/sum/;
173 my ($self, $time) = @_;
174 $self->start > ($time // time)
178 my ($self, $time) = @_;
179 $self->stop <= ($time // time)
183 my ($self, $time) = @_;
184 !$self->is_pending($time) && !$self->is_finished($time)
188 my ($mxscore, $time, $tries, $totaltime) = @_;
189 my $score = $mxscore;
190 $time = 0 if $time < 0;
191 $time = 300 if $time > $totaltime;
192 $score = ($totaltime - $time) / $totaltime * $score;
193 $score -= $tries / 10 * $mxscore;
194 $score = $mxscore * 3 / 10 if $score < $mxscore * 3 / 10;
202 my @problems = map { $_->rawproblem } $self->contest_problems->search({contest
=> $ct}, {qw
/join problem order_by problem.level/});
203 my (%scores, %tries, %opens);
204 $opens{$_->rawproblem, $_->rawowner} = $_ for $self->opens->search({contest
=> $ct});
205 for my $job ($self->jobs->search({contest
=> $ct}, {qw
/order_by me.id prefetch/ => [qw
/problem/]})) {
206 my $open = $opens{$job->rawproblem, $job->rawowner};
207 my $time = $job->date - ($open ?
$open->time : $self->start);
209 my $value = $job->problem->value;
210 my $factor = $job->result ?
0 : 1;
211 $factor = $1 / 100 if $job->result_text =~ /^(\d
+ )/s
;
212 $scores{$job->rawowner}{$job->rawproblem} = int ($factor * calc_score
($value, $time, $tries{$job->rawowner}{$job->rawproblem}++, $self->stop - $self->start));
215 my %user_to_name = map { $_->id => $_->name } $self->result_source->schema->users->all;
217 my @st = sort { $b->{score
} <=> $a->{score
} or $a->{user
} cmp $b->{user
} } map { ## no critic (ProhibitReverseSortBlock)
221 user_name
=> $user_to_name{$user},
222 score
=> sum
(values %{$scores{$user}}),
223 scores
=> [map { $scores{$user}{$_} // '-'} @problems],
228 $st[$_]->{rank
} = $st[$_ - 1]->{rank
} + ($st[$_]->{score
} < $st[$_ - 1]->{score
}) for 1 .. $#st;
238 =head2 is_pending(I<[$time]>)
240 Returns true if the contest is pending at time I<$time> (which defaults to C<time>).
242 =head2 is_finished(I<[$time]>)
244 Returns true if the contest is finished at time I<$time> (which defaults to C<time>).
246 =head2 is_running(I<[$time]>)
248 Returns true if the contest is running at time I<$time> (which defaults to C<time>).
252 Marius Gavrilescu E<lt>marius@ieval.roE<gt>
254 =head1 COPYRIGHT AND LICENSE
256 Copyright (C) 2014 by Marius Gavrilescu
258 This library is free software; you can redistribute it and/or modify
259 it under the same terms as Perl itself, either Perl version 5.18.1 or,
260 at your option, any later version of Perl 5 you may have available.
This page took 0.062245 seconds and 4 git commands to generate.