From: Marius Gavrilescu Date: Mon, 1 Dec 2014 12:42:46 +0000 (+0200) Subject: Make problem value NOT NULL X-Git-Tag: 5999.000_011~4 X-Git-Url: http://git.ieval.ro/?a=commitdiff_plain;h=aaa9eb7d81598848183239016890f3a851082154;p=gruntmaster-data.git Make problem value NOT NULL --- diff --git a/db.sql b/db.sql index d065217..0daf347 100644 --- a/db.sql +++ b/db.sql @@ -36,7 +36,7 @@ CREATE TABLE problems ( testcnt INT NOT NULL, tests TEXT, timeout REAL NOT NULL, - value INT, + value INT NOT NULL, genformat TEXT, gensource TEXT, verformat TEXT, diff --git a/gruntmaster-problem b/gruntmaster-problem index fa1403e..5d18b2b 100755 --- a/gruntmaster-problem +++ b/gruntmaster-problem @@ -9,6 +9,13 @@ use JSON qw/encode_json/; use Term::ANSIColor qw/RED RESET/; use Getopt::Long qw/:config require_order/; +use constant LEVEL_VALUES => { + beginner => 100, + easy => 250, + medium => 500, + hard => 1000, +}; + ################################################## my $dsn = $ENV{GRUNTMASTER_DSN} // 'dbi:Pg:'; @@ -27,6 +34,7 @@ sub cmd_add{ my $writer = prompt 'Problem statement writer (full name)'; my $owner = prompt 'Problem owner (username)'; my $level = prompt 'Problem level', -menu => "beginner\neasy\nmedium\nhard"; + my $value = LEVEL_VALUES->{$level}; my $statement = read_file prompt 'File with problem statement', -complete => 'filenames'; my $generator = prompt 'Generator', -menu => "File\nRun\nUndef"; my $runner = prompt 'Runner', -menu => "File\nVerifier\nInteractive"; @@ -59,6 +67,7 @@ sub cmd_add{ id => $id, name => $name, level => $level, + value => $value, statement => $statement, author => $author, writer => $writer, diff --git a/lib/Gruntmaster/Data.pm b/lib/Gruntmaster/Data.pm index 9b38389..949e1a4 100644 --- a/lib/Gruntmaster/Data.pm +++ b/lib/Gruntmaster/Data.pm @@ -42,13 +42,6 @@ BEGIN { } } -use constant LEVEL_VALUES => { - beginner => 100, - easy => 250, - medium => 500, - hard => 1000, -}; - sub calc_score{ my ($mxscore, $time, $tries, $totaltime) = @_; my $score = $mxscore; @@ -71,7 +64,7 @@ sub standings { my $open = $self->opens->find($ct->id, $job->problem->id, $job->owner->id); my $time = $job->date - ($open ? $open->time : $ct->start); next if $time < 0; - my $value = $job->problem->value // LEVEL_VALUES->{$job->problem->level}; + my $value = $job->problem->value; my $factor = $job->result ? 0 : 1; $factor = $1 / 100 if $job->result_text =~ /^(\d+ )/; $scores{$job->owner->id}{$job->problem->id} = int ($factor * calc_score ($value, $time, $tries{$job->owner->id}{$job->problem->id}++, $ct->stop - $ct->start)); diff --git a/lib/Gruntmaster/Data/Result/Problem.pm b/lib/Gruntmaster/Data/Result/Problem.pm index 5b84391..0f4667e 100644 --- a/lib/Gruntmaster/Data/Result/Problem.pm +++ b/lib/Gruntmaster/Data/Result/Problem.pm @@ -103,7 +103,7 @@ __PACKAGE__->table("problems"); =head2 value data_type: 'integer' - is_nullable: 1 + is_nullable: 0 =head2 genformat @@ -159,7 +159,7 @@ __PACKAGE__->add_columns( "timeout", { data_type => "real", is_nullable => 0 }, "value", - { data_type => "integer", is_nullable => 1 }, + { data_type => "integer", is_nullable => 0 }, "genformat", { data_type => "text", is_nullable => 1 }, "gensource", @@ -255,8 +255,8 @@ Composing rels: L -> contest __PACKAGE__->many_to_many("contests", "contest_problems", "contest"); -# Created by DBIx::Class::Schema::Loader v0.07039 @ 2014-05-16 15:03:32 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:tvap77v0faSMxFiLu1uggQ +# Created by DBIx::Class::Schema::Loader v0.07042 @ 2014-12-01 14:39:28 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:/p3BIfVYSG5AKSSgVgOoOQ sub is_private { my ($self, $time) = @_; diff --git a/t/Gruntmaster-Data.t b/t/Gruntmaster-Data.t index b8f28d7..e9d20ac 100644 --- a/t/Gruntmaster-Data.t +++ b/t/Gruntmaster-Data.t @@ -19,7 +19,7 @@ ok $db->contest('fc')->is_finished(25), 'is_finished'; ok !$db->contest('rc')->is_finished(25), '!is_finished'; ok $db->contest('rc')->is_running(25), 'is_running'; -$db->problems->create({id => 'pb', name => 'Problem', generator => 'Undef', runner => 'File', judge => 'Absolute', level => 'beginner', owner => 'MGV', statement => '...', testcnt => 1, timeout => 1, private => 0}); +$db->problems->create({id => 'pb', name => 'Problem', generator => 'Undef', runner => 'File', judge => 'Absolute', level => 'beginner', value => 100, owner => 'MGV', statement => '...', testcnt => 1, timeout => 1, private => 0}); ok !$db->problem('pb')->is_private(25), '!is_private'; $db->problem('pb')->update({private => 1}); diff --git a/t/tools.t b/t/tools.t index e812737..3d9f525 100644 --- a/t/tools.t +++ b/t/tools.t @@ -102,7 +102,7 @@ is `$perl gruntmaster-problem get pb author`, "Marius Gavrilescu\n", 'gruntmaste system $perl, 'gruntmaster-problem', 'set', 'pb', 'owner', 'nobody'; withdb { is $db->problem('pb')->owner->id, 'nobody', 'gruntmaster-problem set' }; -withdb { $db->problems->create({id => 'dummy', name => 'Dummy', generator => 'Undef', runner => 'File', judge => 'Absolute', level => 'beginner', owner => 'MGV', statement => '...', testcnt => 1, timeout => 1}) }; +withdb { $db->problems->create({id => 'dummy', name => 'Dummy', generator => 'Undef', runner => 'File', judge => 'Absolute', level => 'beginner', value => 100, owner => 'MGV', statement => '...', testcnt => 1, timeout => 1}) }; @list = sort `$perl gruntmaster-problem list`; chomp @list;