]> iEval git - gruntmaster-data.git/blobdiff - gruntmaster-problem
Simplify user_list
[gruntmaster-data.git] / gruntmaster-problem
index 7e979cdc05164e6c8c4788efb6d19756e7ada04b..0f45fe80dcf4a13015b95532453366ab2c91d859 100755 (executable)
@@ -7,7 +7,8 @@ use File::Temp qw/tempfile/;
 
 use IO::Prompter [ -style => 'bold', '-stdio', '-verbatim' ];
 use File::Slurp qw/read_file write_file/;
-use JSON qw/encode_json/;
+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/;
 
@@ -112,7 +113,7 @@ sub cmd_edit{
        close $fh;
        my $editor = $ENV{EDITOR} // 'editor';
        system $editor, $file;
-       $db->problem($id)->update({$col => read_file $file});
+       $db->problem($id)->update({$col => scalar read_file $file}) or die "$!";
 }
 
 sub cmd_list{
@@ -143,8 +144,55 @@ Private: $columns{private}
 END
 }
 
+sub cmd_check {
+       my ($set, $clear);
+       GetOptions ( 'set|s' => \$set, 'clear|c' => \$clear );
+       my ($id) = @ARGV;
+       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 (%pass, %fail, $fail);
+
+       for (@jobs) {
+               $_->discard_changes;
+               my $time = max map { $_->{time} } @{decode_json $_->results};
+               $pass{$_->format} = max ($pass{$_->format} // (), $time) if $_->reference == 0;
+               $fail{$_->format} = max ($fail{$_->format} // (), $time) if $_->reference == 3;
+               if ($_->result == $_->reference) {
+                       say 'Job ' . $_->id . ' OK'
+               } else {
+                       say 'Job ' . $_->id . ' got ' . $_->result . ' instead of ' . $_->reference;
+                       $fail = 1;
+               }
+       }
+
+       printf "Min timeout for %s: %.2fs\n", $_, $pass{$_} for keys %pass;
+       printf "Max timeout for %s: %.2fs\n", $_, $fail{$_} for keys %fail;
+       say $fail ? 'Test failed' : 'Test successful';
+
+       if ($clear) {
+               $db->limits->search({problem => $id})->delete;
+               say 'Cleared time limits';
+       }
+
+       if ($set) {
+               for (keys %pass) {
+                       my $time = $pass{$_};
+                       $time = sprintf '%.1f', $time * 3/2 + 0.1;
+                       next if $time eq $db->problem($id)->timeout;
+                       $db->limits->create({problem => $id, format => $_, timeout => $time});
+                       say "Set time limit for $_ to $time";
+               }
+       }
+
+       exit $fail if $fail;
+}
+
 ##################################################
 
+Getopt::Long::Configure 'bundling';
 my $cmd = 'cmd_' . shift;
 cmd_help unless exists $main::{$cmd};
 no strict 'refs';
@@ -168,6 +216,7 @@ gruntmaster-problem - shell interface to Gruntmaster 6000 problems
   gruntmaster-problem set [--file] problem_id key value
   gruntmaster-problem get problem_id key
   gruntmaster-problem edit problem_id key
+  gruntmaster-problem check [-cs] [--clear] [--set] problem_id
 
 =head1 DESCRIPTION
 
@@ -207,6 +256,14 @@ Opens an editor with the value of the I<key> configuration option. After the edi
 
 Sets the I<key> configuration option of problem I<id> to the contents of the file I<file>.
 
+=item B<check> [args] I<id>
+
+Rerun all reference jobs for problem I<id> and check their results.
+
+With the I<--clear> or I<-c> argument, removes all time limit overrides for this problem.
+
+With the I<--set> or I<-s> argument, automatically adds time limit overrides based on the times used by the reference solutions.
+
 =back
 
 =head1 AUTHOR
This page took 0.028027 seconds and 4 git commands to generate.