]>
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 - List of contests
16 use base
'DBIx::Class::Core';
18 =head1 TABLE: C<contests>
22 __PACKAGE__
->table("contests");
41 HTML fragment placed before the editorial
48 HTML fragment placed on contest page
55 Unix time when contest starts
62 Unix time when contest ends
72 __PACKAGE__
->add_columns(
74 { data_type
=> "text", is_nullable
=> 0 },
76 { data_type
=> "text", is_nullable
=> 0 },
78 { data_type
=> "text", is_nullable
=> 1 },
80 { data_type
=> "text", is_nullable
=> 1 },
82 { data_type
=> "integer", is_nullable
=> 0 },
84 { data_type
=> "integer", is_nullable
=> 0 },
86 { data_type
=> "text", is_foreign_key
=> 1, is_nullable
=> 0 },
99 __PACKAGE__
->set_primary_key("id");
103 =head2 contest_problems
107 Related object: L<Gruntmaster::Data::Result::ContestProblem>
111 __PACKAGE__
->has_many(
113 "Gruntmaster::Data::Result::ContestProblem",
114 { "foreign.contest" => "self.id" },
115 { cascade_copy
=> 0, cascade_delete
=> 0 },
118 =head2 contest_statuses
122 Related object: L<Gruntmaster::Data::Result::ContestStatus>
126 __PACKAGE__
->has_many(
128 "Gruntmaster::Data::Result::ContestStatus",
129 { "foreign.contest" => "self.id" },
130 { cascade_copy
=> 0, cascade_delete
=> 0 },
137 Related object: L<Gruntmaster::Data::Result::Job>
141 __PACKAGE__
->has_many(
143 "Gruntmaster::Data::Result::Job",
144 { "foreign.contest" => "self.id" },
145 { cascade_copy
=> 0, cascade_delete
=> 0 },
152 Related object: L<Gruntmaster::Data::Result::Open>
156 __PACKAGE__
->has_many(
158 "Gruntmaster::Data::Result::Open",
159 { "foreign.contest" => "self.id" },
160 { cascade_copy
=> 0, cascade_delete
=> 0 },
167 Related object: L<Gruntmaster::Data::Result::User>
171 __PACKAGE__
->belongs_to(
173 "Gruntmaster::Data::Result::User",
175 { is_deferrable
=> 0, on_delete
=> "CASCADE", on_update
=> "NO ACTION" },
182 Composing rels: L</contest_problems> -> problem
186 __PACKAGE__
->many_to_many("problems", "contest_problems", "problem");
189 # Created by DBIx::Class::Schema::Loader v0.07042 @ 2015-02-14 10:52:58
190 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:UTfqBbyhmo0r1HyWtGXidA
192 use Class
::Method
::Modifiers qw
/after/;
193 use List
::Util qw
/sum/;
195 after qw
/insert update delete/ => sub {
197 Gruntmaster
::Data
::purge
'/ct/';
198 Gruntmaster
::Data
::purge
'/ct/' . $self->id;
202 my ($self, $time) = @_;
203 $self->start > ($time // time)
207 my ($self, $time) = @_;
208 $self->stop <= ($time // time)
212 my ($self, $time) = @_;
213 !$self->is_pending($time) && !$self->is_finished($time)
217 my ($mxscore, $time, $tries, $totaltime) = @_;
218 my $score = $mxscore;
219 $time = 0 if $time < 0;
220 $time = 300 if $time > $totaltime;
221 $score = ($totaltime - $time) / $totaltime * $score;
222 $score -= $tries / 10 * $mxscore;
223 $score = $mxscore * 3 / 10 if $score < $mxscore * 3 / 10;
231 my @problems = map { $_->rawproblem } $self->contest_problems->search({contest
=> $ct}, {qw
/join problem order_by problem.value/});
232 my (%scores, %tries, %opens);
233 $opens{$_->rawproblem, $_->rawowner} = $_ for $self->opens->search({contest
=> $ct});
234 for my $job ($self->jobs->search({contest
=> $ct, result
=> {'!=', undef}}, {qw
/order_by me.id prefetch/ => [qw
/problem/]})) {
235 my $open = $opens{$job->rawproblem, $job->rawowner};
236 my $time = $job->date - ($open ?
$open->time : $self->start);
238 my $value = $job->problem->value;
239 my $factor = $job->result ?
0 : 1;
240 $factor = $1 / 100 if $job->result_text =~ /^(\d
+ )/s
;
241 $scores{$job->rawowner}{$job->rawproblem} = int ($factor * calc_score
($value, $time, $tries{$job->rawowner}{$job->rawproblem}++, $self->stop - $self->start));
244 my %user_to_name = map { $_->id => $_->name } $self->result_source->schema->users->all;
246 my @st = sort { $b->{score
} <=> $a->{score
} or $a->{user
} cmp $b->{user
} } map { ## no critic (ProhibitReverseSortBlock)
250 user_name
=> $user_to_name{$user},
251 score
=> sum
(values %{$scores{$user}}),
252 scores
=> [map { $scores{$user}{$_} // '-'} @problems],
256 $st[0]->{rank
} = 1 if @st;
257 $st[$_]->{rank
} = $st[$_ - 1]->{rank
} + ($st[$_]->{score
} < $st[$_ - 1]->{score
}) for 1 .. $#st;
267 =head2 is_pending(I<[$time]>)
269 Returns true if the contest is pending at time I<$time> (which defaults to C<time>).
271 =head2 is_finished(I<[$time]>)
273 Returns true if the contest is finished at time I<$time> (which defaults to C<time>).
275 =head2 is_running(I<[$time]>)
277 Returns true if the contest is running at time I<$time> (which defaults to C<time>).
281 Marius Gavrilescu E<lt>marius@ieval.roE<gt>
283 =head1 COPYRIGHT AND LICENSE
285 Copyright (C) 2014 by Marius Gavrilescu
287 This library is free software; you can redistribute it and/or modify
288 it under the same terms as Perl itself, either Perl version 5.18.1 or,
289 at your option, any later version of Perl 5 you may have available.
This page took 0.065276 seconds and 4 git commands to generate.