X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;f=lib%2FGruntmaster%2FData.pm;h=4393a62de6f687d724f8cab874b7e190cfd31283;hb=5bfe4fee59691741265842a2d06cf53a1d86aa6e;hp=2706f94338f643e17bd84c71f1b8e3cfb9ae1965;hpb=0fbf9cb886e53420d341836090614b0b3d6f92b1;p=gruntmaster-data.git diff --git a/lib/Gruntmaster/Data.pm b/lib/Gruntmaster/Data.pm index 2706f94..4393a62 100644 --- a/lib/Gruntmaster/Data.pm +++ b/lib/Gruntmaster/Data.pm @@ -1,10 +1,10 @@ package Gruntmaster::Data; -use v5.14; +use 5.014; use warnings; use parent qw/Exporter/; our $VERSION = '5999.000_013'; -our @EXPORT = qw/purge user_list user_entry problem_list problem_entry contest_list contest_entry contest_full contest_has_problem job_list job_entry job_full create_job standings update_status/; ## no critic (ProhibitAutomaticExportation) +our @EXPORT = qw/purge db user_list user_entry problem_list problem_entry contest_list contest_entry contest_full contest_has_problem job_list job_entry job_full create_job standings update_status rerun_job/; ## no critic (ProhibitAutomaticExportation) use JSON::MaybeXS qw/decode_json/; use HTTP::Tiny; @@ -38,9 +38,12 @@ my %statements = ( job_entry_sth => 'SELECT * FROM job_entry WHERE id = ?', job_full_sth => 'SELECT * FROM jobs WHERE id = ?', + + rerun_job_sth => 'UPDATE jobs SET daemon=NULL,result=-2,result_text=NULL,results=NULL,errors=NULL WHERE id = ?', ); our $db; +sub db () { $db } sub init { $db = DBIx::Simple->new(@_); @@ -51,7 +54,7 @@ sub purge; sub query { my ($stat, @extra) = @_; - $db->query($statements{$stat} // $stat, @extra) + $db->query($statements{$stat}, @extra) } my (%name_cache, %name_cache_time); @@ -70,10 +73,10 @@ sub object_name { } -sub add_names ($) { +sub add_names ($) { ## no critic (ProhibitSubroutinePrototypes) my ($el) = @_; if (ref $el eq 'ARRAY') { - &add_names ($_) for @$el + &add_names ($_) for @$el ## no critic (ProhibitAmpersandSigils) } else { for my $object (qw/contest owner problem/) { my $table = $object eq 'owner' ? 'users' : "${object}s"; @@ -84,7 +87,7 @@ sub add_names ($) { $el } -sub user_list { scalar query('user_list_sth')->hashes } +sub user_list { +{us => scalar query('user_list_sth')->hashes} } sub user_entry { my ($id) = @_; @@ -116,8 +119,8 @@ sub problem_list { } sub problem_entry { - my ($id, $contest, $user) = @_; - $contest &&= contest_entry $contest; + my ($id, $contest) = @_; + $contest = contest_entry ($contest) if $contest; my $ret = add_names query(problem_entry_sth => $id)->hash; my $limits = query(limits_sth => $id)->hashes; $ret->{limits} = $limits if @$limits; @@ -125,6 +128,7 @@ sub problem_entry { if ($contest) { $ret->{contest_start} = $contest->{start}; $ret->{contest_stop} = $contest->{stop}; + delete $ret->{solution} } $ret @@ -187,7 +191,7 @@ sub job_list { sub job_entry { my ($id) = @_; my $ret = add_names query(job_entry_sth => $id)->hash; - $ret->{results} &&= decode_json $ret->{results}; + $ret->{results} = decode_json $ret->{results} if $ret->{results}; $ret } @@ -206,8 +210,7 @@ sub create_job { sub calc_score { my ($mxscore, $time, $tries, $totaltime) = @_; my $score = $mxscore; - $time = 0 if $time < 0; - $time = 300 if $time > $totaltime; + $time = 300 if $time > $totaltime; # uncoverable branch true does not happen anymore (only possible if opens are broken) $score = ($totaltime - $time) / $totaltime * $score; $score -= $tries / 10 * $mxscore; $score = $mxscore * 3 / 10 if $score < $mxscore * 3 / 10; @@ -221,7 +224,6 @@ sub standings { my @problems = query(contest_problems_sth => $ct->{id})->flat; my $pblist = problem_list; my %values = query('problem_values_sth')->map; -# $values{$_} = $values{$_}->{value} for keys %values; my (%scores, %tries, %opens); my $opens = query(opens_sth => $ct->{id}); @@ -234,7 +236,7 @@ sub standings { while (my $job = $jobs->hash) { my $open = $opens{$job->{problem}, $job->{owner}} // $ct->{start}; my $time = $job->{date} - $open; - next if $time < 0; + next if $time < 0; # uncoverable branch true job sent before contest is deprecated my $value = $values{$job->{problem}}; my $factor = $job->{result} ? 0 : 1; $factor = $1 / 100 if $job->{result_text} =~ /^(\d+ )/s; @@ -260,7 +262,7 @@ sub standings { } sub update_status { - my $jobs = $db->select('jobs', 'id,owner,problem,result', {}, 'id'); + my $jobs = $db->select('jobs', 'id,owner,problem,result', {-not_bool => 'private'}, 'id'); my %hash; while ($jobs->into(my ($id, $owner, $problem, $result))) { @@ -282,6 +284,13 @@ sub update_status { $db->commit } +sub rerun_job { + my ($id) = @_; + $db->query(rerun_job_sth => $id); + purge '/log/'; + purge "/log/$id"; +} + my @PURGE_HOSTS = exists $ENV{PURGE_HOSTS} ? split ' ', $ENV{PURGE_HOSTS} : (); my $ht = HTTP::Tiny->new;