From f7e9da17d2a51800b190c6475ef41a07af0d4e2f Mon Sep 17 00:00:00 2001 From: Marius Gavrilescu Date: Fri, 25 Sep 2015 12:30:51 +0300 Subject: [PATCH] Add open_problem function --- lib/Gruntmaster/Data.pm | 20 +++++++++++++++++++- t/Gruntmaster-Data.t | 7 ++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/lib/Gruntmaster/Data.pm b/lib/Gruntmaster/Data.pm index 2468d03..3fed5b3 100644 --- a/lib/Gruntmaster/Data.pm +++ b/lib/Gruntmaster/Data.pm @@ -4,7 +4,7 @@ use warnings; use parent qw/Exporter/; our $VERSION = '5999.000_013'; -our @EXPORT = qw/dbinit purge db user_list user_entry problem_list problem_entry contest_list contest_entry contest_has_problem job_list job_entry create_job standings update_status rerun_job take_job finish_job/; ## no critic (ProhibitAutomaticExportation) +our @EXPORT = qw/dbinit purge db user_list user_entry problem_list problem_entry contest_list contest_entry contest_has_problem job_list job_entry create_job standings update_status rerun_job take_job finish_job open_problem/; ## no critic (ProhibitAutomaticExportation) our @EXPORT_OK = @EXPORT; use JSON::MaybeXS qw/decode_json/; @@ -276,6 +276,17 @@ sub finish_job { purge '/us/' . $job->{owner}; } +sub open_problem { + my ($contest, $problem, $owner, $time) = @_; + my $ct = contest_entry($contest); + return unless $ct->{id} && $time >= $ct->{start} && $time < $ct->{stop}; + eval { db->insert(opens => { + contest => $contest, + problem => $problem, + owner => $owner, + time => $time}) }; +} + my @PURGE_HOSTS = exists $ENV{PURGE_HOSTS} ? split ' ', $ENV{PURGE_HOSTS} : (); my $ht = HTTP::Tiny->new; @@ -441,6 +452,13 @@ describing the job, or undef if no job was available. Updates the job $job with the results in %results. If $private is false, also updates the problem_status table. +=item B(I<$contest>, I<$problem>, I<$owner>, I<$time>) + +Notes that I<$owner> has opened the problem I<$problem> of contest +I<$contest> at time I<$time>. If the C table already contains +this (I<$contest>, I<$problem>, I<$owner>) triplet, this function does +nothing. + =back =head1 AUTHOR diff --git a/t/Gruntmaster-Data.t b/t/Gruntmaster-Data.t index ff39701..0c77a41 100644 --- a/t/Gruntmaster-Data.t +++ b/t/Gruntmaster-Data.t @@ -101,8 +101,13 @@ is_deeply $x->{results}, [], 'job_entry results'; $x = job_entry 7; ok !defined $x->{result}, 'job_entry 7 has NULL result'; +open_problem qw/fc fca MGV/, contest_entry('fc')->{start} + 300; + $x = standings 'fc'; + is_deeply $x, [ - {rank => 1, user => 'MGV', user_name => undef, score => 50, scores => [50]}, + {rank => 1, user => 'MGV', user_name => undef, score => 80, scores => [80]}, {rank => 2, user => 'nobody', user_name => undef, score => 40, scores => [40]}, ], 'standings fc'; + +db->delete('opens', {contest => 'fc', problem => 'fca', owner => 'MGV'}); -- 2.39.2