]>
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 Unix time when contest starts
48 Unix time when contest ends
58 __PACKAGE__
->add_columns(
60 { data_type
=> "text", is_nullable
=> 0 },
62 { data_type
=> "text", is_nullable
=> 0 },
64 { data_type
=> "integer", is_nullable
=> 0 },
66 { data_type
=> "integer", is_nullable
=> 0 },
68 { data_type
=> "text", is_foreign_key
=> 1, is_nullable
=> 0 },
81 __PACKAGE__
->set_primary_key("id");
85 =head2 contest_problems
89 Related object: L<Gruntmaster::Data::Result::ContestProblem>
93 __PACKAGE__
->has_many(
95 "Gruntmaster::Data::Result::ContestProblem",
96 { "foreign.contest" => "self.id" },
97 { cascade_copy
=> 0, cascade_delete
=> 0 },
100 =head2 contest_statuses
104 Related object: L<Gruntmaster::Data::Result::ContestStatus>
108 __PACKAGE__
->has_many(
110 "Gruntmaster::Data::Result::ContestStatus",
111 { "foreign.contest" => "self.id" },
112 { cascade_copy
=> 0, cascade_delete
=> 0 },
119 Related object: L<Gruntmaster::Data::Result::Job>
123 __PACKAGE__
->has_many(
125 "Gruntmaster::Data::Result::Job",
126 { "foreign.contest" => "self.id" },
127 { cascade_copy
=> 0, cascade_delete
=> 0 },
134 Related object: L<Gruntmaster::Data::Result::Open>
138 __PACKAGE__
->has_many(
140 "Gruntmaster::Data::Result::Open",
141 { "foreign.contest" => "self.id" },
142 { cascade_copy
=> 0, cascade_delete
=> 0 },
149 Related object: L<Gruntmaster::Data::Result::User>
153 __PACKAGE__
->belongs_to(
155 "Gruntmaster::Data::Result::User",
157 { is_deferrable
=> 0, on_delete
=> "CASCADE", on_update
=> "NO ACTION" },
164 Composing rels: L</contest_problems> -> problem
168 __PACKAGE__
->many_to_many("problems", "contest_problems", "problem");
171 # Created by DBIx::Class::Schema::Loader v0.07042 @ 2014-12-19 16:54:00
172 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:IxxZqQwKisBwDabCNUD55Q
174 use Class
::Method
::Modifiers qw
/after/;
175 use List
::Util qw
/sum/;
177 after qw
/insert update delete/ => sub {
179 Gruntmaster
::Data
::purge
'/ct/';
180 Gruntmaster
::Data
::purge
'/ct/' . $self->id;
184 my ($self, $time) = @_;
185 $self->start > ($time // time)
189 my ($self, $time) = @_;
190 $self->stop <= ($time // time)
194 my ($self, $time) = @_;
195 !$self->is_pending($time) && !$self->is_finished($time)
199 my ($mxscore, $time, $tries, $totaltime) = @_;
200 my $score = $mxscore;
201 $time = 0 if $time < 0;
202 $time = 300 if $time > $totaltime;
203 $score = ($totaltime - $time) / $totaltime * $score;
204 $score -= $tries / 10 * $mxscore;
205 $score = $mxscore * 3 / 10 if $score < $mxscore * 3 / 10;
213 my @problems = map { $_->rawproblem } $self->contest_problems->search({contest
=> $ct}, {qw
/join problem order_by problem.value/});
214 my (%scores, %tries, %opens);
215 $opens{$_->rawproblem, $_->rawowner} = $_ for $self->opens->search({contest
=> $ct});
216 for my $job ($self->jobs->search({contest
=> $ct, result
=> {'!=', undef}}, {qw
/order_by me.id prefetch/ => [qw
/problem/]})) {
217 my $open = $opens{$job->rawproblem, $job->rawowner};
218 my $time = $job->date - ($open ?
$open->time : $self->start);
220 my $value = $job->problem->value;
221 my $factor = $job->result ?
0 : 1;
222 $factor = $1 / 100 if $job->result_text =~ /^(\d
+ )/s
;
223 $scores{$job->rawowner}{$job->rawproblem} = int ($factor * calc_score
($value, $time, $tries{$job->rawowner}{$job->rawproblem}++, $self->stop - $self->start));
226 my %user_to_name = map { $_->id => $_->name } $self->result_source->schema->users->all;
228 say STDERR
join "\n\n", @problems;
229 my @st = sort { $b->{score
} <=> $a->{score
} or $a->{user
} cmp $b->{user
} } map { ## no critic (ProhibitReverseSortBlock)
233 user_name
=> $user_to_name{$user},
234 score
=> sum
(values %{$scores{$user}}),
235 scores
=> [map { $scores{$user}{$_} // '-'} @problems],
239 $st[0]->{rank
} = 1 if @st;
240 $st[$_]->{rank
} = $st[$_ - 1]->{rank
} + ($st[$_]->{score
} < $st[$_ - 1]->{score
}) for 1 .. $#st;
250 =head2 is_pending(I<[$time]>)
252 Returns true if the contest is pending at time I<$time> (which defaults to C<time>).
254 =head2 is_finished(I<[$time]>)
256 Returns true if the contest is finished at time I<$time> (which defaults to C<time>).
258 =head2 is_running(I<[$time]>)
260 Returns true if the contest is running at time I<$time> (which defaults to C<time>).
264 Marius Gavrilescu E<lt>marius@ieval.roE<gt>
266 =head1 COPYRIGHT AND LICENSE
268 Copyright (C) 2014 by Marius Gavrilescu
270 This library is free software; you can redistribute it and/or modify
271 it under the same terms as Perl itself, either Perl version 5.18.1 or,
272 at your option, any later version of Perl 5 you may have available.
This page took 0.054334 seconds and 4 git commands to generate.