Remove support for archive standings
[gruntmaster-data.git] / gruntmaster-problem
CommitLineData
014ee8a6
MG
1#!/usr/bin/perl -w
2use v5.14;
3
4use Gruntmaster::Data;
014ee8a6
MG
5
6use IO::Prompter [ -style => 'bold', '-stdio', '-verbatim' ];
7use File::Slurp qw/read_file/;
756368d0 8use JSON qw/encode_json/;
014ee8a6 9use Term::ANSIColor qw/RED RESET/;
0d2f8987 10use Getopt::Long qw/:config require_order/;
014ee8a6 11
aaa9eb7d
MG
12use constant LEVEL_VALUES => {
13 beginner => 100,
14 easy => 250,
15 medium => 500,
16 hard => 1000,
17};
18
014ee8a6
MG
19##################################################
20
30e287c3
MG
21my $dsn = $ENV{GRUNTMASTER_DSN} // 'dbi:Pg:';
22my $db = Gruntmaster::Data->connect($dsn);
014ee8a6
MG
23
24sub cmd_help{
25 exec perldoc => $0
26}
27
014ee8a6
MG
28sub cmd_add{
29 my $id = shift;
30 my $name = prompt 'Problem name';
646feed4 31 my $private = prompt('Private?', '-yn') eq 'y';
756368d0 32 my $contest = prompt 'Contest';
014ee8a6 33 my $author = prompt 'Problem author (full name)';
6544497e 34 my $writer = prompt 'Problem statement writer (full name)';
014ee8a6
MG
35 my $owner = prompt 'Problem owner (username)';
36 my $level = prompt 'Problem level', -menu => "beginner\neasy\nmedium\nhard";
aaa9eb7d 37 my $value = LEVEL_VALUES->{$level};
014ee8a6 38 my $statement = read_file prompt 'File with problem statement', -complete => 'filenames';
cd25d613
MG
39 my $generator = prompt 'Generator', -menu => "File\nRun\nUndef";
40 my $runner = prompt 'Runner', -menu => "File\nVerifier\nInteractive";
41 my $judge = prompt 'Judge', -menu => "Absolute\nPoints";
42 my $testcnt = prompt 'Test count', '-i';
014ee8a6 43
cd25d613
MG
44 my $timeout = prompt 'Time limit (seconds)', '-n';
45 my $olimit = prompt 'Output limit (bytes)', '-i';
014ee8a6
MG
46 say 'Memory limits are broken, so I won\'t ask you for one';
47
756368d0 48 my (@tests, $gensource, $genformat, $versource, $verformat);
014ee8a6 49
756368d0
MG
50 if ($generator eq 'Run') {
51 $gensource = read_file prompt, '[Generator::Run] Generator file name', -complete => 'filenames';
52 $genformat = prompt '[Generator::Run] Generator format', -menu => [qw/C CPP MONO JAVA PASCAL PERL PYTHON/];
014ee8a6
MG
53 }
54
756368d0
MG
55 if ($runner eq 'File') {
56 my $default = $judge eq 'Points' ? 10 : 'Ok';
57 $tests[$_ - 1] = prompt "[Runner::File] Score for test ${_} [$default]", -default => $default for 1 .. $testcnt;
58 }
014ee8a6 59
756368d0
MG
60 if ($runner eq 'Verifier' || $runner eq 'Interactive') {
61 say RED, 'WARNING: Runner::Interactive is experimental', RESET if $runner eq 'Interactive';
62 $versource = prompt "[Runner::$runner] Verifier file name", -complete => 'filenames';
63 $verformat = prompt "[Runner::$runner] Verifier format", -menu => [qw/C CPP MONO JAVA PASCAL PERL PYTHON/];
014ee8a6
MG
64 }
65
4af36605 66 my %options = (
756368d0 67 id => $id,
646feed4
MG
68 name => $name,
69 level => $level,
aaa9eb7d 70 value => $value,
646feed4
MG
71 statement => $statement,
72 author => $author,
6544497e 73 writer => $writer,
646feed4
MG
74 owner => $owner,
75 generator => $generator,
76 runner => $runner,
77 judge => $judge,
78 testcnt => $testcnt,
4af36605
MG
79 );
80 $options{private} = $private if $private;
81 $options{timeout} = $timeout if $timeout;
82 $options{olimit} = $olimit if $olimit;
83 $options{tests} = encode_json \@tests if @tests;
84 $options{gensource} = $gensource if $gensource;
85 $options{genformat} = $genformat if $genformat;
86 $options{versource} = $versource if $versource;
87 $options{verformat} = $verformat if $verformat;
88 $db->problems->create (\%options);
756368d0
MG
89
90 $db->contest_problems->create({problem => $id, contest => $contest}) if $contest;
014ee8a6
MG
91}
92
93sub cmd_set{
94 my $file;
95 GetOptions ( 'file!' => \$file );
4af36605 96 my ($id, %values) = @_;
014ee8a6 97 %values = map { $_ => scalar read_file $values{$_} } keys %values if $file;
4af36605 98 $db->problem($id)->update(\%values)
014ee8a6
MG
99}
100
5214523a 101sub cmd_get{
4af36605 102 my ($id, $col) = @_;
5214523a
MG
103 say $db->problem($id)->get_column($col)
104}
105
014ee8a6
MG
106sub cmd_list{
107 local $, = "\n";
4af36605 108 say map {$_->id} $db->problems->all
014ee8a6
MG
109}
110
111sub cmd_rm{
4af36605 112 $db->problem(shift)->delete
014ee8a6
MG
113}
114
115sub cmd_show{
4af36605
MG
116 my %columns = $db->problem(shift)->get_columns;
117 print <<END
118Name: $columns{name}
119Author: $columns{author}
120Statement written by: $columns{writer}
121Owner: $columns{owner}
122Level: $columns{level}
123Output limit: $columns{olimit}
124Time limit: $columns{timeout}
125Test count: $columns{testcnt}
126Generator: $columns{generator}
127Runner: $columns{runner}
128Judge: $columns{judge}
129Private: $columns{private}
130END
014ee8a6
MG
131}
132
133##################################################
134
014ee8a6
MG
135my $cmd = 'cmd_' . shift;
136cmd_help unless exists $main::{$cmd};
137no strict 'refs';
756368d0 138$cmd->(@ARGV);
014ee8a6
MG
139
1401;
141__END__
142
143=encoding utf-8
144
145=head1 NAME
146
147gruntmaster-problem - shell interface to Gruntmaster 6000 problems
148
149=head1 SYNOPSIS
150
5214523a
MG
151 gruntmaster-problem add problem_id
152 gruntmaster-problem list
153 gruntmaster-problem rm problem_id
154 gruntmaster-problem show problem_id
155 gruntmaster-problem set [--file] problem_id key value
156 gruntmaster-problem get problem_id key
014ee8a6
MG
157
158=head1 DESCRIPTION
159
e90402be
MG
160gruntmaster-problem is a tool for managing problems.
161
e90402be
MG
162=over
163
164=item B<list>
165
166Prints the list of problems in the selected contest.
167
168=item B<show> I<id>
169
170Prints detailed information about problem I<id>.
171
172=item B<add> I<id>
173
174Adds a new problem with id I<id>.
175
176=item B<rm> I<id>
177
178Removes the problem with id I<id>.
179
180=item B<set> I<id> I<key> I<value>
181
182Sets the I<key> configuration option of problem I<id> to I<value>.
183
5214523a
MG
184=item B<get> I<id> I<key>
185
186Get the value of the I<key> configuration option of problem I<id>
187
e90402be
MG
188=item B<set> --file I<id> I<key> I<file>
189
190Sets the I<key> configuration option of problem I<id> to the contents of the file I<file>.
191
192=back
193
194=head1 AUTHOR
195
196Marius Gavrilescu E<lt>marius@ieval.roE<gt>
197
198=head1 COPYRIGHT AND LICENSE
199
200Copyright (C) 2014 by Marius Gavrilescu
201
4af36605
MG
202This library is free software; you can redistribute it and/or modify
203it under the same terms as Perl itself, either Perl version 5.18.1 or,
204at your option, any later version of Perl 5 you may have available.
014ee8a6
MG
205
206
207=cut
This page took 0.026658 seconds and 4 git commands to generate.