]>
iEval git - gruntmaster-data.git/blob - gruntmaster-problem
0f45fe80dcf4a13015b95532453366ab2c91d859
6 use File
::Temp qw
/tempfile/;
8 use IO
::Prompter
[ -style
=> 'bold', '-stdio', '-verbatim' ];
9 use File
::Slurp qw
/read_file write_file/;
10 use JSON qw
/decode_json encode_json/;
11 use List
::Util qw
/max min/;
12 use Term
::ANSIColor qw
/RED RESET/;
13 use Getopt
::Long qw
/:config require_order/;
15 use constant LEVEL_VALUES
=> {
22 ##################################################
24 my $dsn = $ENV{GRUNTMASTER_DSN
} // 'dbi:Pg:';
25 my $db = Gruntmaster
::Data
->connect($dsn);
33 my $name = prompt
'Problem name';
34 my $private = prompt
('Private?', '-yn') eq 'y';
35 my $contest = prompt
'Contest';
36 my $author = prompt
'Problem author (full name)';
37 my $writer = prompt
'Problem statement writer (full name)';
38 my $owner = prompt
'Problem owner (username)';
39 my $level = prompt
'Problem level', -menu
=> "beginner\neasy\nmedium\nhard";
40 my $value = LEVEL_VALUES
->{$level};
41 my $statement = read_file prompt
'File with problem statement', -complete
=> 'filenames';
42 my $generator = prompt
'Generator', -menu
=> "File\nRun\nUndef";
43 my $runner = prompt
'Runner', -menu
=> "File\nVerifier\nInteractive";
44 my $judge = prompt
'Judge', -menu
=> "Absolute\nPoints";
45 my $testcnt = prompt
'Test count', '-i';
47 my $timeout = prompt
'Time limit (seconds)', '-n';
48 my $olimit = prompt
'Output limit (bytes)', '-i';
49 say 'Memory limits are broken, so I won\'t ask you for one';
51 my (@tests, $gensource, $genformat, $versource, $verformat);
53 if ($generator eq 'Run') {
54 $gensource = read_file prompt
, '[Generator::Run] Generator file name', -complete
=> 'filenames';
55 $genformat = prompt
'[Generator::Run] Generator format', -menu
=> [qw
/C CPP MONO JAVA PASCAL PERL PYTHON/];
58 if ($runner eq 'File') {
59 my $default = $judge eq 'Points' ?
10 : 'Ok';
60 $tests[$_ - 1] = prompt
"[Runner::File] Score for test ${_} [$default]", -default => $default for 1 .. $testcnt;
63 if ($runner eq 'Verifier' || $runner eq 'Interactive') {
64 say RED
, 'WARNING: Runner::Interactive is experimental', RESET
if $runner eq 'Interactive';
65 $versource = prompt
"[Runner::$runner] Verifier file name", -complete
=> 'filenames';
66 $verformat = prompt
"[Runner::$runner] Verifier format", -menu
=> [qw
/C CPP MONO JAVA PASCAL PERL PYTHON/];
74 statement
=> $statement,
78 generator
=> $generator,
83 $options{private
} = $private if $private;
84 $options{timeout
} = $timeout if $timeout;
85 $options{olimit
} = $olimit if $olimit;
86 $options{tests
} = encode_json \
@tests if @tests;
87 $options{gensource
} = $gensource if $gensource;
88 $options{genformat
} = $genformat if $genformat;
89 $options{versource
} = $versource if $versource;
90 $options{verformat
} = $verformat if $verformat;
91 $db->problems->create (\
%options);
93 $db->contest_problems->create({problem
=> $id, contest
=> $contest}) if $contest;
98 GetOptions
( 'file!' => \
$file );
99 my ($id, %values) = @ARGV;
100 %values = map { $_ => scalar read_file
$values{$_} } keys %values if $file;
101 $db->problem($id)->update(\
%values);
106 say $db->problem($id)->get_column($col)
111 my ($fh, $file) = tempfile
'gruntmaster-problem-editXXXX', TMPDIR
=> 1, UNLINK
=> 1;
112 write_file
$fh, $db->problem($id)->get_column($col);
114 my $editor = $ENV{EDITOR
} // 'editor';
115 system $editor, $file;
116 $db->problem($id)->update({$col => scalar read_file
$file}) or die "$!";
121 say map {$_->id} $db->problems->all
126 $db->problem($id)->delete;
130 my %columns = $db->problem(shift)->get_columns;
133 Author: $columns{author}
134 Statement written by: $columns{writer}
135 Owner: $columns{owner}
136 Level: $columns{level}
137 Output limit: $columns{olimit}
138 Time limit: $columns{timeout}
139 Test count: $columns{testcnt}
140 Generator: $columns{generator}
141 Runner: $columns{runner}
142 Judge: $columns{judge}
143 Private: $columns{private}
149 GetOptions
( 'set|s' => \
$set, 'clear|c' => \
$clear );
151 my @jobs = $db->jobs->search({problem
=> $id, reference
=> { '!=', undef }})->all;
152 say 'Rerunning ' . @jobs . ' reference jobs...';
154 sleep 1 while $db->jobs->search({problem
=> $id, result_text
=> undef})->count;
156 my (%pass, %fail, $fail);
160 my $time = max
map { $_->{time} } @
{decode_json
$_->results};
161 $pass{$_->format} = max
($pass{$_->format} // (), $time) if $_->reference == 0;
162 $fail{$_->format} = max
($fail{$_->format} // (), $time) if $_->reference == 3;
163 if ($_->result == $_->reference) {
164 say 'Job ' . $_->id . ' OK'
166 say 'Job ' . $_->id . ' got ' . $_->result . ' instead of ' . $_->reference;
171 printf "Min timeout for %s: %.2fs\n", $_, $pass{$_} for keys %pass;
172 printf "Max timeout for %s: %.2fs\n", $_, $fail{$_} for keys %fail;
173 say $fail ?
'Test failed' : 'Test successful';
176 $db->limits->search({problem
=> $id})->delete;
177 say 'Cleared time limits';
182 my $time = $pass{$_};
183 $time = sprintf '%.1f', $time * 3/2 + 0.1;
184 next if $time eq $db->problem($id)->timeout;
185 $db->limits->create({problem
=> $id, format
=> $_, timeout
=> $time});
186 say "Set time limit for $_ to $time";
193 ##################################################
195 Getopt
::Long
::Configure
'bundling';
196 my $cmd = 'cmd_' . shift;
197 cmd_help
unless exists $main::{$cmd};
208 gruntmaster-problem - shell interface to Gruntmaster 6000 problems
212 gruntmaster-problem add problem_id
213 gruntmaster-problem list
214 gruntmaster-problem rm problem_id
215 gruntmaster-problem show problem_id
216 gruntmaster-problem set [--file] problem_id key value
217 gruntmaster-problem get problem_id key
218 gruntmaster-problem edit problem_id key
219 gruntmaster-problem check [-cs] [--clear] [--set] problem_id
223 gruntmaster-problem is a tool for managing problems.
229 Prints the list of problems in the selected contest.
233 Prints detailed information about problem I<id>.
237 Adds a new problem with id I<id>.
241 Removes the problem with id I<id>.
243 =item B<set> I<id> I<key> I<value>
245 Sets the I<key> configuration option of problem I<id> to I<value>.
247 =item B<get> I<id> I<key>
249 Get the value of the I<key> configuration option of problem I<id>
251 =item B<edit> I<id> I<key>
253 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.
255 =item B<set> --file I<id> I<key> I<file>
257 Sets the I<key> configuration option of problem I<id> to the contents of the file I<file>.
259 =item B<check> [args] I<id>
261 Rerun all reference jobs for problem I<id> and check their results.
263 With the I<--clear> or I<-c> argument, removes all time limit overrides for this problem.
265 With the I<--set> or I<-s> argument, automatically adds time limit overrides based on the times used by the reference solutions.
271 Marius Gavrilescu E<lt>marius@ieval.roE<gt>
273 =head1 COPYRIGHT AND LICENSE
275 Copyright (C) 2014 by Marius Gavrilescu
277 This library is free software; you can redistribute it and/or modify
278 it under the same terms as Perl itself, either Perl version 5.18.1 or,
279 at your option, any later version of Perl 5 you may have available.
This page took 0.070633 seconds and 3 git commands to generate.