Skip to content

Commit

Permalink
Store hashes for tests (klenin#210)
Browse files Browse the repository at this point in the history
  • Loading branch information
AleksandraZh committed Mar 2, 2018
1 parent ef94e96 commit 4442889
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 3 deletions.
17 changes: 17 additions & 0 deletions cgi-bin/CATS/ApiJudge.pm
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,23 @@ sub insert_req_details {
print_json({ ok => 1 });
}

sub get_input_hash {
bad_judge and return -1;
my ($p) = @_;

print_json({ hash => CATS::JudgeDB::get_input_hash($p->{problem_id}, $p->{test_rank}) });
}

sub save_input_hash {
bad_judge and return -1;
my ($p) = @_;

CATS::JudgeDB::save_input_hash(
$p->{problem_id}, $p->{test_rank}, $p->{hash}});

print_json({ ok => 1 });
}

sub save_input_test_data {
bad_judge and return -1;
my ($p) = @_;
Expand Down
5 changes: 3 additions & 2 deletions cgi-bin/CATS/Problem/Storage.pm
Original file line number Diff line number Diff line change
Expand Up @@ -442,8 +442,8 @@ sub insert_problem_content {
$c = $dbh->prepare(q~
INSERT INTO tests (
problem_id, rank, input_validator_id, generator_id, param, std_solution_id, in_file, out_file,
points, gen_group
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)~
points, gen_group, in_file_hash
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)~
);

for (sort { $a->{rank} <=> $b->{rank} } values %{$problem->{tests}}) {
Expand All @@ -457,6 +457,7 @@ sub insert_problem_content {
$c->bind_param(8, $_->{out_file}, { ora_type => 113 });
$c->bind_param(9, $_->{points});
$c->bind_param(10, $_->{gen_group});
$c->bind_param(11, $_->{hash});
$c->execute
or $self->error("Can not add test $_->{rank}: $dbh->errstr");
$self->note("Test $_->{rank} added");
Expand Down
11 changes: 11 additions & 0 deletions cgi-bin/CATS/Router.pm
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,17 @@ $api_judge_routes = {
],
api_judge_delete_req_details => [ \&CATS::ApiJudge::delete_req_details, req_id => integer, ],
api_judge_insert_req_details => [ \&CATS::ApiJudge::insert_req_details, params => str, ],
api_judge_get_input_hash => [
\&CATS::ApiJudge::get_input_hash,
problem_id => integer,
test_rank => integer,
],
api_judge_save_input_hash => [
\&CATS::ApiJudge::save_input_hash,
problem_id => integer,
test_rank => integer,
hash => undef,
],
api_judge_save_input_test_data => [
\&CATS::ApiJudge::save_input_test_data,
problem_id => integer,
Expand Down
3 changes: 2 additions & 1 deletion sql/interbase/init_relations.sql
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,8 @@ CREATE TABLE tests (
out_file BLOB, /* For generated answer, length = min(out_file_size, save_answer_prefix). */
out_file_size INTEGER, /* Size of generated answer, else NULL. */
points INTEGER,
gen_group INTEGER
gen_group INTEGER,
in_file_hash VARCHAR(100) DEFAULT NULL
);

CREATE TABLE testsets (
Expand Down
2 changes: 2 additions & 0 deletions sql/interbase/migrations/20180226-tests-hash.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE tests
ADD in_file_hash VARCHAR(100) DEFAULT NULL;

0 comments on commit 4442889

Please sign in to comment.