X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;f=gruntmaster-problem;h=1b240e0c4b3772973ac5d53f66d140b4bf961acd;hb=5214523a16467b3ce47a7b5783f5171c419e80a5;hp=a03b09396b3e490330f02bb9ce233951aa3c8850;hpb=0d2f89871c26e28abeee506b4cc1741d94e436ca;p=gruntmaster-data.git diff --git a/gruntmaster-problem b/gruntmaster-problem index a03b093..1b240e0 100755 --- a/gruntmaster-problem +++ b/gruntmaster-problem @@ -2,72 +2,81 @@ use v5.14; use Gruntmaster::Data; -use Gruntmaster::Page::Submit; use IO::Prompter [ -style => 'bold', '-stdio', '-verbatim' ]; use File::Slurp qw/read_file/; +use JSON qw/encode_json/; use Term::ANSIColor qw/RED RESET/; use Getopt::Long qw/:config require_order/; ################################################## -my $contest; +my $db = Gruntmaster::Data->connect('dbi:Pg:'); sub cmd_help{ exec perldoc => $0 } -sub prompt_file{ - my ($meta, $name, $prefix) = @_; - my $filename = prompt '$prefix filename', -complete => 'filenames'; - $meta->{files}{$name}{content} = read_file $filename; - $meta->{files}{$name}{format} = prompt '$prefix format', -menu => Gruntmaster::Page::Submit::FORMATS; - $meta->{files}{$name}{name} = prompt "$prefix filename [$filename]", -default => $filename; -} - sub cmd_add{ my $id = shift; my $name = prompt 'Problem name'; + my $private = prompt('Private?', '-yn') eq 'y'; + my $contest = prompt 'Contest'; my $author = prompt 'Problem author (full name)'; my $owner = prompt 'Problem owner (username)'; my $level = prompt 'Problem level', -menu => "beginner\neasy\nmedium\nhard"; my $statement = read_file prompt 'File with problem statement', -complete => 'filenames'; - my %meta; - $meta{generator} = prompt 'Generator', -menu => "File\nRun\nUndef"; - $meta{runner} = prompt 'Runner', -menu => "File\nVerifier\nInteractive"; - $meta{judge} = prompt 'Judge', -menu => "Absolute\nPoints"; - $meta{testcnt} = prompt 'Test count', '-i'; - - $meta{timeout} = prompt 'Time limit (seconds)', '-n'; - delete $meta{timeout} unless $meta{timeout}; - $meta{olimit} = prompt 'Output limit (bytes)', '-i'; - delete $meta{olimit} unless $meta{olimit}; - say 'Memory limits are broken, so I won\'t ask you for one'; + my $generator = prompt 'Generator', -menu => "File\nRun\nUndef"; + my $runner = prompt 'Runner', -menu => "File\nVerifier\nInteractive"; + my $judge = prompt 'Judge', -menu => "Absolute\nPoints"; + my $testcnt = prompt 'Test count', '-i'; - if ($meta{generator} eq 'File') { - my $prefix = prompt '[Generator::File] Input file prefix'; - $meta{infile}[$_ - 1] = read_file "$prefix$_.in" for 1 .. $meta{testcnt}; - } + my $timeout = prompt 'Time limit (seconds)', '-n'; + my $olimit = prompt 'Output limit (bytes)', '-i'; + say 'Memory limits are broken, so I won\'t ask you for one'; - prompt_file \%meta, gen => '[Generator::Run] Generator' if $meta{generator} eq 'Run'; + my (@tests, $gensource, $genformat, $versource, $verformat); - if ($meta{runner} eq 'File') { - my $prefix = prompt '[Runner::File] Output file prefix'; - $meta{okfile}[$_ - 1] = read_file "$prefix$_.ok" for 1 .. $meta{testcnt}; - $meta{tests}[$_ - 1] = prompt "[Runner::File] Score for test ${_} [10]", '-i', -default => 10 for 1 .. $meta{testcnt}; + if ($generator eq 'Run') { + $gensource = read_file prompt, '[Generator::Run] Generator file name', -complete => 'filenames'; + $genformat = prompt '[Generator::Run] Generator format', -menu => [qw/C CPP MONO JAVA PASCAL PERL PYTHON/]; } - prompt_file \%meta, ver => '[Runner::Verifier] Verifier' if $meta{runner} eq 'Verifier'; + if ($runner eq 'File') { + my $default = $judge eq 'Points' ? 10 : 'Ok'; + $tests[$_ - 1] = prompt "[Runner::File] Score for test ${_} [$default]", -default => $default for 1 .. $testcnt; + } - if ($meta{runner} eq 'Interactive') { - say RED, 'WARNING: Runner::Interactive is experimental', RESET; - prompt_file int => '[Runner::Interactive] Interactive verifier'; + if ($runner eq 'Verifier' || $runner eq 'Interactive') { + say RED, 'WARNING: Runner::Interactive is experimental', RESET if $runner eq 'Interactive'; + $versource = prompt "[Runner::$runner] Verifier file name", -complete => 'filenames'; + $verformat = prompt "[Runner::$runner] Verifier format", -menu => [qw/C CPP MONO JAVA PASCAL PERL PYTHON/]; } - insert_problem $id => name => $name, level => $level, statement => $statement, author => $author, owner => $owner; - set_problem_meta $id => \%meta; - PUBLISH genpage => $contest ? "ct/$contest/pb/index.html" : 'pb/index.html'; - PUBLISH genpage => $contest ? "ct/$contest/pb/$id.html" : "pb/$id.html"; + $db->problems->create ({ + id => $id, + name => $name, + level => $level, + statement => $statement, + author => $author, + owner => $owner, + generator => $generator, + runner => $runner, + judge => $judge, + testcnt => $testcnt, + (private => $private)x!! $private, + (timeout => $timeout)x!! $timeout, + (olimit => $olimit)x!! $olimit, + (tests => encode_json \@tests)x!! @tests, + (gensource => $gensource)x!! $gensource, + (genformat => $genformat)x!! $genformat, + (versource => $versource)x!! $versource, + (verformat => $verformat)x!! $verformat, + }); + + $db->contest_problems->create({problem => $id, contest => $contest}) if $contest; + #PUBLISH genpage => $contest ? "ct/$contest/pb/index.html" : 'pb/index.html'; + #PUBLISH genpage => $contest ? "ct/$contest/pb/$id.html" : "pb/$id.html"; } sub cmd_set{ @@ -75,19 +84,24 @@ sub cmd_set{ GetOptions ( 'file!' => \$file ); my ($id, %values) = @ARGV; %values = map { $_ => scalar read_file $values{$_} } keys %values if $file; - edit_problem $id => %values; - PUBLISH genpage => 'pb/index.html'; - PUBLISH genpage => "pb/$id.html"; + $db->problem($id)->update(\%values); + #PUBLISH genpage => 'pb/index.html'; + #PUBLISH genpage => "pb/$id.html"; +} + +sub cmd_get{ + my ($id, $col) = @ARGV; + say $db->problem($id)->get_column($col) } sub cmd_list{ local $, = "\n"; - say problems; + say map {$_->id} $db->problems->all; } sub cmd_rm{ - remove_problem shift; - PUBLISH genpage => $contest ? "ct/$contest/pb/index.html" : 'pb/index.html'; + $db->problem(shift)->delete; + #PUBLISH genpage => $contest ? "ct/$contest/pb/index.html" : 'pb/index.html'; } sub cmd_show{ @@ -96,12 +110,10 @@ sub cmd_show{ ################################################## -GetOptions ( 'contest=s' => \$contest ); -local $Gruntmaster::Data::contest = $contest; my $cmd = 'cmd_' . shift; cmd_help unless exists $main::{$cmd}; no strict 'refs'; -$cmd->(@ARGV) if exists $main::{$cmd}; +$cmd->(@ARGV); 1; __END__ @@ -114,11 +126,12 @@ gruntmaster-problem - shell interface to Gruntmaster 6000 problems =head1 SYNOPSIS - gruntmaster-problem [--contest=mycontest] add problem_id - gruntmaster-problem [--contest=mycontest] list - gruntmaster-problem [--contest=mycontest] rm problem_id - gruntmaster-problem [--contest=mycontest] show problem_id - gruntmaster-problem [--contest=mycontest] set [--file] problem_id key value + gruntmaster-problem add problem_id + gruntmaster-problem list + gruntmaster-problem rm problem_id + gruntmaster-problem show problem_id + gruntmaster-problem set [--file] problem_id key value + gruntmaster-problem get problem_id key =head1 DESCRIPTION @@ -148,6 +161,10 @@ Removes the problem with id I. Sets the I configuration option of problem I to I. +=item B I I + +Get the value of the I configuration option of problem I + =item B --file I I I Sets the I configuration option of problem I to the contents of the file I.