use Gruntmaster::Data;
+use File::Temp qw/tempfile/;
+
use IO::Prompter [ -style => 'bold', '-stdio', '-verbatim' ];
-use File::Slurp qw/read_file/;
-use JSON qw/encode_json/;
+use File::Slurp qw/read_file write_file/;
+use JSON qw/decode_json encode_json/;
+use List::Util qw/max min/;
use Term::ANSIColor qw/RED RESET/;
use Getopt::Long qw/:config require_order/;
sub cmd_set{
my $file;
GetOptions ( 'file!' => \$file );
- my ($id, %values) = @_;
+ my ($id, %values) = @ARGV;
%values = map { $_ => scalar read_file $values{$_} } keys %values if $file;
- $db->problem($id)->update(\%values)
+ $db->problem($id)->update(\%values);
}
sub cmd_get{
say $db->problem($id)->get_column($col)
}
+sub cmd_edit{
+ my ($id, $col) = @_;
+ my ($fh, $file) = tempfile 'gruntmaster-problem-editXXXX', TMPDIR => 1, UNLINK => 1;
+ write_file $fh, $db->problem($id)->get_column($col);
+ close $fh;
+ my $editor = $ENV{EDITOR} // 'editor';
+ system $editor, $file;
+ $db->problem($id)->update({$col => scalar read_file $file}) or die "$!";
+}
+
sub cmd_list{
local $, = "\n";
say map {$_->id} $db->problems->all
}
sub cmd_rm{
- $db->problem(shift)->delete
+ my ($id) = @_;
+ $db->problem($id)->delete;
}
sub cmd_show{
END
}
+sub cmd_check {
+ my ($id) = @_;
+ my @jobs = $db->jobs->search({problem => $id, reference => { '!=', undef }})->all;
+ say 'Rerunning ' . @jobs . ' reference jobs...';
+ $_->rerun for @jobs;
+ sleep 1 while $db->jobs->search({problem => $id, result_text => undef})->count;
+
+ my (@good_times, @fail_times, $fail);
+
+ for (@jobs) {
+ $_->discard_changes;
+ my @times = map { $_->{time} } @{decode_json $_->results};
+ push @good_times, @times if $_->reference == 0;
+ push @fail_times, @times if $_->reference == 3;
+ if ($_->result == $_->reference) {
+ say 'Job ' . $_->id . ' OK'
+ } else {
+ say 'Job ' . $_->id . ' got ' . $_->result . ' instead of ' . $_->reference;
+ $fail = 1;
+ }
+ }
+
+ say 'Max time for AC: ' . max @good_times if @good_times;
+ say 'Min time for TLE: ' . min @fail_times if @fail_times;
+ say $fail ? 'Test failed' : 'Test successful';
+ exit $fail if $fail;
+}
+
##################################################
my $cmd = 'cmd_' . shift;
gruntmaster-problem show problem_id
gruntmaster-problem set [--file] problem_id key value
gruntmaster-problem get problem_id key
+ gruntmaster-problem edit problem_id key
=head1 DESCRIPTION
Get the value of the I<key> configuration option of problem I<id>
+=item B<edit> I<id> I<key>
+
+Opens an editor with the value of the I<key> configuration option. After the editor exits, the option is updated to the value of the file.
+
=item B<set> --file I<id> I<key> I<file>
Sets the I<key> configuration option of problem I<id> to the contents of the file I<file>.