WriteMakefile(
NAME => 'Gruntmaster::Data',
VERSION_FROM => 'lib/Gruntmaster/Data.pm',
- EXE_FILES => [ qw/gruntmaster-contest gruntmaster-problem gruntmaster-job/ ],
ABSTRACT_FROM => 'lib/Gruntmaster/Data.pm',
AUTHOR => 'Marius Gavrilescu <marius@ieval.ro>',
MIN_PERL_VERSION => '5.14.0',
--- /dev/null
+CREATE TYPE ULEVEL AS ENUM ('Highschool', 'Undergraduate', 'Master', 'Doctorate', 'Other');
+CREATE TYPE PLEVEL AS ENUM ('beginner', 'easy', 'medium', 'hard');
+CREATE TYPE GENERATOR AS ENUM ('File', 'Run', 'Undef');
+CREATE TYPE RUNNER AS ENUM ('File', 'Verifier', 'Interactive');
+CREATE TYPE JUDGE AS ENUM ('Absolute', 'Points');
+
+CREATE TABLE users (
+ id TEXT PRIMARY KEY,
+ name TEXT, -- NOT NULL,
+ email TEXT, -- NOT NULL,
+ town TEXT, -- NOT NULL,
+ university TEXT, -- NOT NULL,
+ level TEXT, --ULEVEL NOT NULL,
+ lastjob BIGINT
+);
+
+CREATE TABLE contests (
+ id TEXT PRIMARY KEY,
+ name TEXT NOT NULL,
+ start INT NOT NULL,
+ stop INT NOT NULL,
+ owner TEXT NOT NULL REFERENCES users,
+ CONSTRAINT positive_duration CHECK (stop > start)
+);
+
+CREATE TABLE problems (
+ id TEXT PRIMARY KEY,
+ author TEXT NOT NULL,
+ generator GENERATOR NOT NULL,
+ judge JUDGE NOT NULL,
+ level PLEVEL NOT NULL,
+ name TEXT NOT NULL,
+ olimit INT,
+ owner TEXT NOT NULL REFERENCES users,
+ private BOOLEAN NOT NULL DEFAULT FALSE,
+ runner RUNNER NOT NULL,
+ statement TEXT NOT NULL,
+ testcnt INT NOT NULL,
+ timeout REAL NOT NULL,
+ value INT,
+ verformat TEXT,
+ versource TEXT
+);
+
+CREATE TABLE contest_problems (
+ contest TEXT REFERENCES contests,
+ problem TEXT NOT NULL REFERENCES problems,
+ PRIMARY KEY (contest, problem)
+);
+
+CREATE TABLE jobs (
+ id SERIAL PRIMARY KEY,
+ contest TEXT REFERENCES contests,
+ daemon TEXT,
+ date BIGINT NOT NULL,
+ errors TEXT,
+ extension TEXT NOT NULL,
+ format TEXT NOT NULL,
+ private BOOLEAN NOT NULL DEFAULT FALSE,
+ problem TEXT NOT NULL REFERENCES problems,
+ result INT,
+ result_text TEXT,
+ results JSON,
+ source TEXT NOT NULL,
+ owner TEXT NOT NULL REFERENCES users
+);
+
+CREATE TABLE opens (
+ contest TEXT NOT NULL REFERENCES contests,
+ problem TEXT NOT NULL REFERENCES problems,
+ owner TEXT NOT NULL REFERENCES users,
+ time BIGINT NOT NULL,
+ PRIMARY KEY (contest, problem, owner)
+);
+use utf8;
package Gruntmaster::Data;
-use v5.14;
+
+# Created by DBIx::Class::Schema::Loader
+# DO NOT MODIFY THE FIRST PART OF THIS FILE
+
+use strict;
use warnings;
-use parent qw/Exporter/;
-use JSON qw/encode_json decode_json/;
-use Redis;
-use Sub::Name qw/subname/;
+use base 'DBIx::Class::Schema';
+
+__PACKAGE__->load_namespaces;
-our $VERSION = '5999.000_002';
-our $contest;
-my $redis = Redis->new;
-my $pubsub = Redis->new;
+# Created by DBIx::Class::Schema::Loader v0.07039 @ 2014-03-05 13:11:39
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:dAEmtAexvUaNXLgYz2rNEg
+
+our $VERSION = 5999.000_003;
+
+use Lingua::EN::Inflect qw/PL_N/;
+use Sub::Name qw/subname/;
sub dynsub{
our ($name, $sub) = @_;
}
BEGIN {
- for my $cmd (qw/multi exec smembers get hget hgetall hdel hset sadd srem incr hmset hsetnx publish del/) {
- dynsub uc $cmd, sub { $redis->$cmd(@_) };
- }
-
- for my $cmd (qw/subscribe wait_for_messages/) {
- dynsub uc $cmd, sub { $pubsub->$cmd(@_) };
+ for my $rs (qw/contest contest_problem job open problem user/) {
+ my $rsname = ucfirst $rs;
+ $rsname =~ s/_([a-z])/\u$1/g;
+ dynsub PL_N($rs) => sub { $_[0]->resultset($rsname) };
+ dynsub $rs => sub { $_[0]->resultset($rsname)->find($_[1]) };
}
}
-sub cp { defined $contest ? "contest.$contest." : '' }
-
-sub problems () { SMEMBERS cp . 'problem' }
-sub contests () { SMEMBERS cp . 'contest' }
-sub users () { SMEMBERS cp . 'user' }
-sub jobcard () { GET cp . 'job' }
-
-sub job_results (_) { decode_json HGET cp . "job.$_[0]", 'results' }
-sub set_job_results ($+) { HSET cp . "job.$_[0]", 'results', encode_json $_[1] }
-sub job_inmeta (_) { decode_json HGET cp . "job.$_[0]", 'inmeta' }
-sub set_job_inmeta ($+) { HSET cp . "job.$_[0]", 'inmeta', encode_json $_[1] }
-sub problem_meta (_) { decode_json HGET cp . "problem.$_[0]", 'meta' }
-sub set_problem_meta ($+) { HSET cp . "problem.$_[0]", 'meta', encode_json $_[1] }
-sub job_daemon (_) { HGET cp . "job.$_[0]", 'daemon' }
-sub set_job_daemon ($$) { HSETNX cp . "job.$_[0]", 'daemon', $_[1] };
-
-sub defhash{
- my ($name, @keys) = @_;
- for my $key (@keys) {
- dynsub "${name}_$key", sub (_) { HGET cp . "$name.$_[0]", $key };
- dynsub "set_${name}_$key", sub ($$) { HSET cp . "$name.$_[0]", $key, $_[1] };
- }
-
- dynsub "edit_$name", sub {
- my ($key, %values) = @_;
- HMSET cp . "$name.$key", %values;
- };
-
- dynsub "insert_$name", sub {
- my ($key, %values) = @_;
- SADD cp . $name, $key or return;
- HMSET cp . "$name.$key", %values;
- };
- dynsub "remove_$name", sub (_) {
- my $key = shift;
- SREM cp . $name, $key;
- DEL cp . "$name.$key";
- };
-
- dynsub "push_$name", sub {
- my $nr = INCR cp . $name;
- HMSET cp . "$name.$nr", @_;
- $nr
- };
-}
-
-defhash problem => qw/name level difficulty statement owner author private generator runner judge testcnt timeout olimit/;
-defhash contest => qw/start end name owner description/;
-defhash job => qw/date errors extension filesize private problem result result_text user/;
-defhash user => qw/name email lastjob town university level/;
-
-sub clean_job (_){
- HDEL cp . "job.$_[0]", qw/result result_text results daemon/
-}
-
-sub mark_open {
- my ($problem, $user) = @_;
- HSETNX cp . 'open', "$problem.$user", time;
-}
-
-sub get_open {
- my ($problem, $user) = @_;
- HGET cp . 'open', "$problem.$user";
-}
-
-our @EXPORT = do {
- no strict 'refs';
- grep { $_ =~ /^[a-zA-Z]/ and exists &$_ } keys %{__PACKAGE__ . '::'};
-};
-
1;
-__END__
-
-=encoding utf-8
-
-=head1 NAME
-
-Gruntmaster::Data - Gruntmaster 6000 Online Judge -- database interface and tools
-
-=head1 SYNOPSIS
-
- for my $problem (problems) {
- say "Problem name: " . problem_name $problem;
- say "Problem level: " . problem_level $problem;
- ...
- }
-
-=head1 DESCRIPTION
-
-Gruntmaster::Data is the Redis interface used by the Gruntmaster 6000 Online Judge. It exports many functions for talking to the database. All functions are exported by default.
-
-The current contest is selected by setting the C<< $Gruntmaster::Data::contest >> variable.
-
- local $Gruntmaster::Data::contest = 'mycontest';
- say 'There are' . jobcard . ' jobs in my contest';
-
-=head1 FUNCTIONS
-
-=head2 Redis
-
-Gruntmaster::Data exports some functions for talking directly to the Redis server. These functions should not normally be used, except for B<MULTI>, B<EXEC>, B<PUBLISH>, B<SUBSCRIBE> and B<WAIT_FOR_MESSAGES>.
-
-These functions correspond to Redis commands. The current list is: B<< MULTI EXEC SMEMBERS GET HGET HGETALL HDEL HSET SADD SREM INCR HMSET HSETNX DEL PUBLISH SUBSCRIBE WAIT_FOR_MESSAGES >>.
-
-=head2 Problems
-
-=over
-
-=item B<problems>
-
-Returns a list of problems in the current contest.
-
-=item B<problem_meta> I<$problem>
-
-Returns a problem's meta.
-
-=item B<set_problem_meta> I<$problem>, I<$meta>
-
-Sets a problem's meta.
-
-=item B<problem_name> I<$problem>
-
-Returns a problem's name.
-
-=item B<set_problem_name> I<$problem>, I<$name>
-
-Sets a problem's name.
-
-=item B<problem_level> I<$problem>
-
-Returns a problem's level. The levels are beginner, easy, medium, hard.
-
-=item B<set_problem_level> I<$problem>, I<$level>
-
-Sets a problem's level. The levels are beginner, easy, medium, hard.
-
-=item B<problem_difficulty> I<$problem>
-
-Returns a problem's difficulty.
-
-=item B<set_problem_difficulty> I<$problem>, I<$name>
-
-Sets a problem's difficulty.
-
-=item B<problem_statement> I<$problem>
-
-Returns a problem's statement.
-
-=item B<set_problem_statement> I<$problem>, I<$statement>
-
-Sets a problem's statement.
-
-=item B<problem_owner> I<$problem>
-
-Returns a problem's owner.
-
-=item B<set_problem_owner> I<$problem>, I<$owner>
-
-Sets a problem's owner.
-
-=item B<problem_author> I<$problem>
-
-Returns a problem's author.
-
-=item B<set_problem_author> I<$problem>, I<$author>
-
-Sets a problem's author.
-
-=item B<problem_private> I<$problem>
-
-Returns a problem's private flag (true if the problem is private, false otherwise).
-
-=item B<set_problem_private> I<$problem>, I<$private>
-
-Sets a problem's private flag.
-
-=item B<problem_generator> I<$problem>
-
-Returns a problem's generator. The generators are File, Run and Undef. More might be added in the future.
-
-=item B<set_problem_generator> I<$problem>, I<$generator>
-
-Sets a problem's generator.
-
-=item B<problem_runner> I<$problem>
-
-Returns a problem's runner. The runners are File, Verifier and Interactive. More might be added in the future.
-
-=item B<set_problem_runner> I<$problem>, I<$runner>
-
-Sets a problem's runner.
-
-=item B<problem_judge> I<$problem>
-
-Returns a problem's judge. The judges are Absolute and Points. More might be added in the future.
-
-=item B<set_problem_judge> I<$problem>, I<$judge>
-
-Sets a problem's judge.
-
-=item B<problem_testcnt> I<$problem>
-
-Returns a problem's test count.
-
-=item B<set_problem_testcnt> I<$problem>, I<$testcnt>
-
-Sets a problem's test count.
-
-=item B<problem_timeout> I<$problem>
-
-Returns a problem's time limit, in seconds.
-
-=item B<set_problem_timeout> I<$problem>, I<$timeout>
-
-Sets a problem's time limit, in seconds.
-
-=item B<problem_olimit> I<$problem>
-
-Returns a problem's output limit, in bytes.
-
-=item B<set_problem_olimit> I<$problem>, I<$olimit>
-
-Sets a problem's output limit, in bytes.
-
-=item B<get_open> I<$problem>, I<$user>
-
-Returns the time when I<$user> opened I<$problem>.
-
-=item B<mark_open> I<$problem>, I<$user>
-
-Sets the time when I<$user> opened I<$problem> to the current time. Does nothing if I<$user> has already opened I<$problem>.
-
-=item B<insert_problem> I<$id>, I<$key> => I<$value>, ...
-
-Inserts a problem with id I<$id> and the given initial configuration. Does nothing if a problem with id I<$id> already exists. Returns true if the problem was added, false otherwise.
-
-=item B<edit_problem> I<$id>, I<$key> => I<$value>, ...
-
-Updates the configuration of a problem. The values of the given keys are updated. All other keys/values are left intact.
-
-=item B<remove_problem> I<$id>
-
-Removes a problem.
-
-=back
-
-=head2 Contests
-
-B<<< WARNING: these functions only work correctly when C<< $Gruntmaster::Data::contest >> is undef >>>
-
-=over
-
-=item B<contests>
-
-Returns a list of contests.
-
-=item B<contest_start> I<$contest>
-
-Returns a contest's start time.
-
-=item B<set_contest_start> I<$contest>, I<$start>
-
-Sets a contest's start time.
-
-=item B<contest_end> I<$contest>
-
-Returns a contest's end time.
-
-=item B<set_contest_end> I<$contest>, I<$end>
-
-Sets a contest's end time.
-
-=item B<contest_name> I<$contest>
-
-Returns a contest's name.
-
-=item B<set_contest_name> I<$contest>, I<$name>
-
-Sets a contest's name.
-
-=item B<contest_owner> I<$contest>
-
-Returns a contest's owner.
-
-=item B<set_contest_owner> I<$contest>, I<$owner>
-
-Sets a contest's owner.
-
-=item B<insert_contest> I<$id>, I<$key> => I<$value>, ...
-
-Inserts a contest with id I<$id> and the given initial configuration. Does nothing if a contest with id I<$id> already exists. Returns true if the contest was added, false otherwise.
-
-=item B<edit_contest> I<$id>, I<$key> => I<$value>, ...
-
-Updates the configuration of a contest. The values of the given keys are updated. All other keys/values are left intact.
-
-=item B<remove_contest> I<$id>
-
-Removes a contest.
-
-=back
-
-=head2 Jobs
-
-=over
-
-=item B<jobcard>
-
-Returns the number of jobs in the database.
-
-=item B<job_results> I<$job>
-
-Returns an array of job results. Each element corresponds to a test and is a hashref with keys B<id> (test number), B<result> (result code, see L<Gruntmaster::Daemon::Constants>), B<result_text> (result description) and B<time> (time taken).
-
-=item B<set_job_results> I<$job>, I<$results>
-
-Sets a job's results.
-
-=item B<job_inmeta> I<$job>
-
-Returns a job's meta.
-
-=item B<set_job_inmeta> I<$job>, I<$meta>
-
-Sets a job's meta.
-
-=item B<job_daemon> I<$job>
-
-Returns the hostname:pid of the daemon which ran this job.
-
-=item B<set_job_daemon> I<$job>, I<$hostname_and_pid>
-
-If the job has no associated daemon, it sets the daemon and returns true. Otherwise it returns false without setting the daemon.
-
-=item B<job_date> I<$job>
-
-Returns a job's submit date.
-
-=item B<set_job_date> I<$job>, I<$date>
-
-Sets a job's submit date.
-
-=item B<job_errors> I<$job>
-
-Returns a job's compile errors.
-
-=item B<set_job_errors> I<$job>, I<$errors>
-
-Sets a job's compile errors.
-
-=item B<job_extension> I<$job>
-
-Returns a job's file name extension (e.g. "cpp", "pl", "java").
-
-=item B<set_job_extension> I<$job>, I<$extension>
-
-Sets a job's file name extension.
-
-=item B<job_filesize> I<$job>
-
-Returns a job's source file size, in bytes.
-
-=item B<set_job_filesize> I<$job>, I<$filesize>
-
-Sets a job's source file size, in bytes.
-
-=item B<job_private> I<$job>
-
-Returns the value of a job's private flag.
-
-=item B<set_job_private> I<$job>, I<$private>
-
-Sets the value of a job's private flag.
-
-=item B<job_problem> I<$job>
-
-Returns a job's problem.
-
-=item B<set_job_problem> I<$job>, I<$problem>
-
-Sets a job's problem.
-
-=item B<job_result> I<$job>
-
-Returns a job's result code. Possible result codes are described in L<Gruntmaster::Daemon::Constants>
-
-=item B<set_job_result> I<$job>, I<$result>
-
-Sets a job's result code.
-
-=item B<job_result_text> I<$job>
-
-Returns a job's result text.
-
-=item B<set_job_result_text> I<$job>, I<$result_text>
-
-Sets a job's result text.
-
-=item B<job_user> I<$job>
-
-Returns the user who submitted a job.
-
-=item B<set_job_user> I<$job>, I<$user>
-
-Sets the suer who submitted a job.
-
-=item B<clean_job> I<$job>
-
-Removes a job's daemon, result code, result text and result array.
-
-=item B<push_job> I<$key> => I<$value>, ...
-
-Inserts a job with a given initial configuration. Returns the id of the newly-added job.
-
-=item B<edit_job> I<$id>, I<$key> => I<$value>, ...
-
-Updates the configuration of a job. The values of the given keys are updated. All other keys/values are left intact.
-
-=item B<remove_job> I<$id>
-
-Removes a job.
-
-=back
-
-=head2 Users
-
-B<<< WARNING: these functions only work correctly when C<< $Gruntmaster::Data::contest >> is undef >>>
-
-=over
-
-=item B<users>
-
-Returns a list of users.
-
-=item B<user_name> I<$user>
-
-Returns a user's full name.
-
-=item B<set_user_name> I<$user>, I<$name>
-
-Sets a user's full name.
-
-=item B<user_email> I<$user>
-
-Returns a user's email address.
-
-=item B<set_user_email> I<$user>, I<$email>
-
-Sets a user's email address.
-
-=item B<user_lastjob> I<$user>
-
-Returns the time (seconds since epoch) when the user last submitted a solution.
-
-=item B<set_user_lastjob> I<$user>, I<$lastjob>
-
-Sets the time (seconds since epoch) when the user last submitted a solution.
-
-=item B<user_town> I<$user>
-
-Returns a user's town.
-
-=item B<set_user_town> I<$user>, I<$town>
-
-Sets a user's town.
-
-=item B<user_university> I<$user>
-
-Returns a user's university/highschool/place of work/etc.
-
-=item B<set_user_university> I<$user>, I<$university>
-
-Sets a user's university, highschool/place of work/etc.
-
-=item B<user_level> I<$user>
-
-Returns a user's current level of study. One of 'Highschool', 'Undergraduate', 'Master', 'Doctorate' or 'Other'.
-
-=item B<set_user_level> I<$user>, I<$level>
-
-Sets a user's current level of study.
-
-=item B<insert_user> I<$id>, I<$key> => I<$value>, ...
-
-Inserts a user with id I<$id> and the given initial configuration. Does nothing if a user with id I<$id> already exists. Returns true if the user was added, false otherwise.
-
-=item B<edit_user> I<$id>, I<$key> => I<$value>, ...
-
-Updates the configuration of a user. The values of the given keys are updated. All other keys/values are left intact.
-
-=item B<remove_user> I<$id>
-
-Removes a user.
-
-=back
-
-=head1 AUTHOR
-
-Marius Gavrilescu E<lt>marius@ieval.roE<gt>
-
-=head1 COPYRIGHT AND LICENSE
-
-Copyright (C) 2014 by Marius Gavrilescu
-
-This library is free software: you can redistribute it and/or modify
-it under the terms of the GNU Affero General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-
-=cut
--- /dev/null
+use utf8;
+package Gruntmaster::Data::Result::Contest;
+
+# Created by DBIx::Class::Schema::Loader
+# DO NOT MODIFY THE FIRST PART OF THIS FILE
+
+=head1 NAME
+
+Gruntmaster::Data::Result::Contest
+
+=cut
+
+use strict;
+use warnings;
+
+use base 'DBIx::Class::Core';
+
+=head1 TABLE: C<contests>
+
+=cut
+
+__PACKAGE__->table("contests");
+
+=head1 ACCESSORS
+
+=head2 id
+
+ data_type: 'text'
+ is_nullable: 0
+
+=head2 name
+
+ data_type: 'text'
+ is_nullable: 0
+
+=head2 start
+
+ data_type: 'integer'
+ is_nullable: 0
+
+=head2 stop
+
+ data_type: 'integer'
+ is_nullable: 0
+
+=head2 owner
+
+ data_type: 'text'
+ is_foreign_key: 1
+ is_nullable: 0
+
+=cut
+
+__PACKAGE__->add_columns(
+ "id",
+ { data_type => "text", is_nullable => 0 },
+ "name",
+ { data_type => "text", is_nullable => 0 },
+ "start",
+ { data_type => "integer", is_nullable => 0 },
+ "stop",
+ { data_type => "integer", is_nullable => 0 },
+ "owner",
+ { data_type => "text", is_foreign_key => 1, is_nullable => 0 },
+);
+
+=head1 PRIMARY KEY
+
+=over 4
+
+=item * L</id>
+
+=back
+
+=cut
+
+__PACKAGE__->set_primary_key("id");
+
+=head1 RELATIONS
+
+=head2 contest_problems
+
+Type: has_many
+
+Related object: L<Gruntmaster::Data::Result::ContestProblem>
+
+=cut
+
+__PACKAGE__->has_many(
+ "contest_problems",
+ "Gruntmaster::Data::Result::ContestProblem",
+ { "foreign.contest" => "self.id" },
+ { cascade_copy => 0, cascade_delete => 0 },
+);
+
+=head2 jobs
+
+Type: has_many
+
+Related object: L<Gruntmaster::Data::Result::Job>
+
+=cut
+
+__PACKAGE__->has_many(
+ "jobs",
+ "Gruntmaster::Data::Result::Job",
+ { "foreign.contest" => "self.id" },
+ { cascade_copy => 0, cascade_delete => 0 },
+);
+
+=head2 opens
+
+Type: has_many
+
+Related object: L<Gruntmaster::Data::Result::Open>
+
+=cut
+
+__PACKAGE__->has_many(
+ "opens",
+ "Gruntmaster::Data::Result::Open",
+ { "foreign.contest" => "self.id" },
+ { cascade_copy => 0, cascade_delete => 0 },
+);
+
+=head2 owner
+
+Type: belongs_to
+
+Related object: L<Gruntmaster::Data::Result::User>
+
+=cut
+
+__PACKAGE__->belongs_to(
+ "owner",
+ "Gruntmaster::Data::Result::User",
+ { id => "owner" },
+ { is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" },
+);
+
+=head2 problems
+
+Type: many_to_many
+
+Composing rels: L</contest_problems> -> problem
+
+=cut
+
+__PACKAGE__->many_to_many("problems", "contest_problems", "problem");
+
+
+# Created by DBIx::Class::Schema::Loader v0.07039 @ 2014-03-06 12:41:16
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:T5tUpU1TOahLKzx9iVie3A
+
+
+# You can replace this text with custom code or comments, and it will be preserved on regeneration
+1;
--- /dev/null
+use utf8;
+package Gruntmaster::Data::Result::ContestProblem;
+
+# Created by DBIx::Class::Schema::Loader
+# DO NOT MODIFY THE FIRST PART OF THIS FILE
+
+=head1 NAME
+
+Gruntmaster::Data::Result::ContestProblem
+
+=cut
+
+use strict;
+use warnings;
+
+use base 'DBIx::Class::Core';
+
+=head1 TABLE: C<contest_problems>
+
+=cut
+
+__PACKAGE__->table("contest_problems");
+
+=head1 ACCESSORS
+
+=head2 contest
+
+ data_type: 'text'
+ is_foreign_key: 1
+ is_nullable: 0
+
+=head2 problem
+
+ data_type: 'text'
+ is_foreign_key: 1
+ is_nullable: 0
+
+=cut
+
+__PACKAGE__->add_columns(
+ "contest",
+ { data_type => "text", is_foreign_key => 1, is_nullable => 0 },
+ "problem",
+ { data_type => "text", is_foreign_key => 1, is_nullable => 0 },
+);
+
+=head1 PRIMARY KEY
+
+=over 4
+
+=item * L</contest>
+
+=item * L</problem>
+
+=back
+
+=cut
+
+__PACKAGE__->set_primary_key("contest", "problem");
+
+=head1 RELATIONS
+
+=head2 contest
+
+Type: belongs_to
+
+Related object: L<Gruntmaster::Data::Result::Contest>
+
+=cut
+
+__PACKAGE__->belongs_to(
+ "contest",
+ "Gruntmaster::Data::Result::Contest",
+ { id => "contest" },
+ { is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" },
+);
+
+=head2 problem
+
+Type: belongs_to
+
+Related object: L<Gruntmaster::Data::Result::Problem>
+
+=cut
+
+__PACKAGE__->belongs_to(
+ "problem",
+ "Gruntmaster::Data::Result::Problem",
+ { id => "problem" },
+ { is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" },
+);
+
+
+# Created by DBIx::Class::Schema::Loader v0.07039 @ 2014-03-06 12:41:16
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:2vVP0Z6QcLz8DiobdOceyQ
+
+
+# You can replace this text with custom code or comments, and it will be preserved on regeneration
+1;
--- /dev/null
+use utf8;
+package Gruntmaster::Data::Result::Job;
+
+# Created by DBIx::Class::Schema::Loader
+# DO NOT MODIFY THE FIRST PART OF THIS FILE
+
+=head1 NAME
+
+Gruntmaster::Data::Result::Job
+
+=cut
+
+use strict;
+use warnings;
+
+use base 'DBIx::Class::Core';
+
+=head1 TABLE: C<jobs>
+
+=cut
+
+__PACKAGE__->table("jobs");
+
+=head1 ACCESSORS
+
+=head2 id
+
+ data_type: 'integer'
+ is_auto_increment: 1
+ is_nullable: 0
+ sequence: 'jobs_id_seq'
+
+=head2 contest
+
+ data_type: 'text'
+ is_foreign_key: 1
+ is_nullable: 0
+
+=head2 daemon
+
+ data_type: 'text'
+ is_nullable: 1
+
+=head2 date
+
+ data_type: 'bigint'
+ is_nullable: 0
+
+=head2 errors
+
+ data_type: 'text'
+ is_nullable: 1
+
+=head2 extension
+
+ data_type: 'text'
+ is_nullable: 0
+
+=head2 format
+
+ data_type: 'text'
+ is_nullable: 0
+
+=head2 private
+
+ data_type: 'boolean'
+ default_value: false
+ is_nullable: 0
+
+=head2 problem
+
+ data_type: 'text'
+ is_foreign_key: 1
+ is_nullable: 0
+
+=head2 result
+
+ data_type: 'integer'
+ is_nullable: 1
+
+=head2 result_text
+
+ data_type: 'text'
+ is_nullable: 1
+
+=head2 results
+
+ data_type: 'json'
+ is_nullable: 1
+
+=head2 source
+
+ data_type: 'text'
+ is_nullable: 0
+
+=head2 owner
+
+ data_type: 'text'
+ is_foreign_key: 1
+ is_nullable: 0
+
+=cut
+
+__PACKAGE__->add_columns(
+ "id",
+ {
+ data_type => "integer",
+ is_auto_increment => 1,
+ is_nullable => 0,
+ sequence => "jobs_id_seq",
+ },
+ "contest",
+ { data_type => "text", is_foreign_key => 1, is_nullable => 0 },
+ "daemon",
+ { data_type => "text", is_nullable => 1 },
+ "date",
+ { data_type => "bigint", is_nullable => 0 },
+ "errors",
+ { data_type => "text", is_nullable => 1 },
+ "extension",
+ { data_type => "text", is_nullable => 0 },
+ "format",
+ { data_type => "text", is_nullable => 0 },
+ "private",
+ { data_type => "boolean", default_value => \"false", is_nullable => 0 },
+ "problem",
+ { data_type => "text", is_foreign_key => 1, is_nullable => 0 },
+ "result",
+ { data_type => "integer", is_nullable => 1 },
+ "result_text",
+ { data_type => "text", is_nullable => 1 },
+ "results",
+ { data_type => "json", is_nullable => 1 },
+ "source",
+ { data_type => "text", is_nullable => 0 },
+ "owner",
+ { data_type => "text", is_foreign_key => 1, is_nullable => 0 },
+);
+
+=head1 PRIMARY KEY
+
+=over 4
+
+=item * L</id>
+
+=back
+
+=cut
+
+__PACKAGE__->set_primary_key("id");
+
+=head1 RELATIONS
+
+=head2 contest
+
+Type: belongs_to
+
+Related object: L<Gruntmaster::Data::Result::Contest>
+
+=cut
+
+__PACKAGE__->belongs_to(
+ "contest",
+ "Gruntmaster::Data::Result::Contest",
+ { id => "contest" },
+ { is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" },
+);
+
+=head2 owner
+
+Type: belongs_to
+
+Related object: L<Gruntmaster::Data::Result::User>
+
+=cut
+
+__PACKAGE__->belongs_to(
+ "owner",
+ "Gruntmaster::Data::Result::User",
+ { id => "owner" },
+ { is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" },
+);
+
+=head2 problem
+
+Type: belongs_to
+
+Related object: L<Gruntmaster::Data::Result::Problem>
+
+=cut
+
+__PACKAGE__->belongs_to(
+ "problem",
+ "Gruntmaster::Data::Result::Problem",
+ { id => "problem" },
+ { is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" },
+);
+
+
+# Created by DBIx::Class::Schema::Loader v0.07039 @ 2014-03-06 12:41:16
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:lIETgGgMTSOUUuDuFa/+SQ
+
+
+# You can replace this text with custom code or comments, and it will be preserved on regeneration
+1;
--- /dev/null
+use utf8;
+package Gruntmaster::Data::Result::Open;
+
+# Created by DBIx::Class::Schema::Loader
+# DO NOT MODIFY THE FIRST PART OF THIS FILE
+
+=head1 NAME
+
+Gruntmaster::Data::Result::Open
+
+=cut
+
+use strict;
+use warnings;
+
+use base 'DBIx::Class::Core';
+
+=head1 TABLE: C<opens>
+
+=cut
+
+__PACKAGE__->table("opens");
+
+=head1 ACCESSORS
+
+=head2 contest
+
+ data_type: 'text'
+ is_foreign_key: 1
+ is_nullable: 0
+
+=head2 problem
+
+ data_type: 'text'
+ is_foreign_key: 1
+ is_nullable: 0
+
+=head2 owner
+
+ data_type: 'text'
+ is_foreign_key: 1
+ is_nullable: 0
+
+=head2 time
+
+ data_type: 'bigint'
+ is_nullable: 0
+
+=cut
+
+__PACKAGE__->add_columns(
+ "contest",
+ { data_type => "text", is_foreign_key => 1, is_nullable => 0 },
+ "problem",
+ { data_type => "text", is_foreign_key => 1, is_nullable => 0 },
+ "owner",
+ { data_type => "text", is_foreign_key => 1, is_nullable => 0 },
+ "time",
+ { data_type => "bigint", is_nullable => 0 },
+);
+
+=head1 PRIMARY KEY
+
+=over 4
+
+=item * L</contest>
+
+=item * L</problem>
+
+=item * L</owner>
+
+=back
+
+=cut
+
+__PACKAGE__->set_primary_key("contest", "problem", "owner");
+
+=head1 RELATIONS
+
+=head2 contest
+
+Type: belongs_to
+
+Related object: L<Gruntmaster::Data::Result::Contest>
+
+=cut
+
+__PACKAGE__->belongs_to(
+ "contest",
+ "Gruntmaster::Data::Result::Contest",
+ { id => "contest" },
+ { is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" },
+);
+
+=head2 owner
+
+Type: belongs_to
+
+Related object: L<Gruntmaster::Data::Result::User>
+
+=cut
+
+__PACKAGE__->belongs_to(
+ "owner",
+ "Gruntmaster::Data::Result::User",
+ { id => "owner" },
+ { is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" },
+);
+
+=head2 problem
+
+Type: belongs_to
+
+Related object: L<Gruntmaster::Data::Result::Problem>
+
+=cut
+
+__PACKAGE__->belongs_to(
+ "problem",
+ "Gruntmaster::Data::Result::Problem",
+ { id => "problem" },
+ { is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" },
+);
+
+
+# Created by DBIx::Class::Schema::Loader v0.07039 @ 2014-03-06 12:41:16
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:+zXnz+V4BYSNwxN65ovu2w
+
+
+# You can replace this text with custom code or comments, and it will be preserved on regeneration
+1;
--- /dev/null
+use utf8;
+package Gruntmaster::Data::Result::Problem;
+
+# Created by DBIx::Class::Schema::Loader
+# DO NOT MODIFY THE FIRST PART OF THIS FILE
+
+=head1 NAME
+
+Gruntmaster::Data::Result::Problem
+
+=cut
+
+use strict;
+use warnings;
+
+use base 'DBIx::Class::Core';
+
+=head1 TABLE: C<problems>
+
+=cut
+
+__PACKAGE__->table("problems");
+
+=head1 ACCESSORS
+
+=head2 id
+
+ data_type: 'text'
+ is_nullable: 0
+
+=head2 author
+
+ data_type: 'text'
+ is_nullable: 0
+
+=head2 generator
+
+ data_type: 'enum'
+ extra: {custom_type_name => "generator",list => ["File","Run","Undef"]}
+ is_nullable: 0
+
+=head2 judge
+
+ data_type: 'enum'
+ extra: {custom_type_name => "judge",list => ["Absolute","Points"]}
+ is_nullable: 0
+
+=head2 level
+
+ data_type: 'enum'
+ extra: {custom_type_name => "plevel",list => ["beginner","easy","medium","hard"]}
+ is_nullable: 0
+
+=head2 name
+
+ data_type: 'text'
+ is_nullable: 0
+
+=head2 olimit
+
+ data_type: 'integer'
+ is_nullable: 1
+
+=head2 owner
+
+ data_type: 'text'
+ is_foreign_key: 1
+ is_nullable: 0
+
+=head2 private
+
+ data_type: 'boolean'
+ is_nullable: 0
+
+=head2 runner
+
+ data_type: 'enum'
+ extra: {custom_type_name => "runner",list => ["File","Verifier","Interactive"]}
+ is_nullable: 0
+
+=head2 statement
+
+ data_type: 'text'
+ is_nullable: 0
+
+=head2 testcnt
+
+ data_type: 'integer'
+ is_nullable: 0
+
+=head2 timeout
+
+ data_type: 'real'
+ is_nullable: 0
+
+=head2 value
+
+ data_type: 'integer'
+ is_nullable: 1
+
+=head2 verformat
+
+ data_type: 'text'
+ is_nullable: 1
+
+=head2 versource
+
+ data_type: 'text'
+ is_nullable: 1
+
+=cut
+
+__PACKAGE__->add_columns(
+ "id",
+ { data_type => "text", is_nullable => 0 },
+ "author",
+ { data_type => "text", is_nullable => 0 },
+ "generator",
+ {
+ data_type => "enum",
+ extra => { custom_type_name => "generator", list => ["File", "Run", "Undef"] },
+ is_nullable => 0,
+ },
+ "judge",
+ {
+ data_type => "enum",
+ extra => { custom_type_name => "judge", list => ["Absolute", "Points"] },
+ is_nullable => 0,
+ },
+ "level",
+ {
+ data_type => "enum",
+ extra => {
+ custom_type_name => "plevel",
+ list => ["beginner", "easy", "medium", "hard"],
+ },
+ is_nullable => 0,
+ },
+ "name",
+ { data_type => "text", is_nullable => 0 },
+ "olimit",
+ { data_type => "integer", is_nullable => 1 },
+ "owner",
+ { data_type => "text", is_foreign_key => 1, is_nullable => 0 },
+ "private",
+ { data_type => "boolean", is_nullable => 0 },
+ "runner",
+ {
+ data_type => "enum",
+ extra => {
+ custom_type_name => "runner",
+ list => ["File", "Verifier", "Interactive"],
+ },
+ is_nullable => 0,
+ },
+ "statement",
+ { data_type => "text", is_nullable => 0 },
+ "testcnt",
+ { data_type => "integer", is_nullable => 0 },
+ "timeout",
+ { data_type => "real", is_nullable => 0 },
+ "value",
+ { data_type => "integer", is_nullable => 1 },
+ "verformat",
+ { data_type => "text", is_nullable => 1 },
+ "versource",
+ { data_type => "text", is_nullable => 1 },
+);
+
+=head1 PRIMARY KEY
+
+=over 4
+
+=item * L</id>
+
+=back
+
+=cut
+
+__PACKAGE__->set_primary_key("id");
+
+=head1 RELATIONS
+
+=head2 contest_problems
+
+Type: has_many
+
+Related object: L<Gruntmaster::Data::Result::ContestProblem>
+
+=cut
+
+__PACKAGE__->has_many(
+ "contest_problems",
+ "Gruntmaster::Data::Result::ContestProblem",
+ { "foreign.problem" => "self.id" },
+ { cascade_copy => 0, cascade_delete => 0 },
+);
+
+=head2 jobs
+
+Type: has_many
+
+Related object: L<Gruntmaster::Data::Result::Job>
+
+=cut
+
+__PACKAGE__->has_many(
+ "jobs",
+ "Gruntmaster::Data::Result::Job",
+ { "foreign.problem" => "self.id" },
+ { cascade_copy => 0, cascade_delete => 0 },
+);
+
+=head2 opens
+
+Type: has_many
+
+Related object: L<Gruntmaster::Data::Result::Open>
+
+=cut
+
+__PACKAGE__->has_many(
+ "opens",
+ "Gruntmaster::Data::Result::Open",
+ { "foreign.problem" => "self.id" },
+ { cascade_copy => 0, cascade_delete => 0 },
+);
+
+=head2 owner
+
+Type: belongs_to
+
+Related object: L<Gruntmaster::Data::Result::User>
+
+=cut
+
+__PACKAGE__->belongs_to(
+ "owner",
+ "Gruntmaster::Data::Result::User",
+ { id => "owner" },
+ { is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" },
+);
+
+=head2 contests
+
+Type: many_to_many
+
+Composing rels: L</contest_problems> -> contest
+
+=cut
+
+__PACKAGE__->many_to_many("contests", "contest_problems", "contest");
+
+
+# Created by DBIx::Class::Schema::Loader v0.07039 @ 2014-03-06 12:41:16
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:y1LUGcxNJxUMgMXqvAkKYQ
+
+
+# You can replace this text with custom code or comments, and it will be preserved on regeneration
+1;
--- /dev/null
+use utf8;
+package Gruntmaster::Data::Result::User;
+
+# Created by DBIx::Class::Schema::Loader
+# DO NOT MODIFY THE FIRST PART OF THIS FILE
+
+=head1 NAME
+
+Gruntmaster::Data::Result::User
+
+=cut
+
+use strict;
+use warnings;
+
+use base 'DBIx::Class::Core';
+
+=head1 TABLE: C<users>
+
+=cut
+
+__PACKAGE__->table("users");
+
+=head1 ACCESSORS
+
+=head2 id
+
+ data_type: 'text'
+ is_nullable: 0
+
+=head2 name
+
+ data_type: 'text'
+ is_nullable: 1
+
+=head2 email
+
+ data_type: 'text'
+ is_nullable: 1
+
+=head2 town
+
+ data_type: 'text'
+ is_nullable: 1
+
+=head2 university
+
+ data_type: 'text'
+ is_nullable: 1
+
+=head2 level
+
+ data_type: 'text'
+ is_nullable: 1
+
+=head2 lastjob
+
+ data_type: 'bigint'
+ is_nullable: 1
+
+=cut
+
+__PACKAGE__->add_columns(
+ "id",
+ { data_type => "text", is_nullable => 0 },
+ "name",
+ { data_type => "text", is_nullable => 1 },
+ "email",
+ { data_type => "text", is_nullable => 1 },
+ "town",
+ { data_type => "text", is_nullable => 1 },
+ "university",
+ { data_type => "text", is_nullable => 1 },
+ "level",
+ { data_type => "text", is_nullable => 1 },
+ "lastjob",
+ { data_type => "bigint", is_nullable => 1 },
+);
+
+=head1 PRIMARY KEY
+
+=over 4
+
+=item * L</id>
+
+=back
+
+=cut
+
+__PACKAGE__->set_primary_key("id");
+
+=head1 RELATIONS
+
+=head2 contests
+
+Type: has_many
+
+Related object: L<Gruntmaster::Data::Result::Contest>
+
+=cut
+
+__PACKAGE__->has_many(
+ "contests",
+ "Gruntmaster::Data::Result::Contest",
+ { "foreign.owner" => "self.id" },
+ { cascade_copy => 0, cascade_delete => 0 },
+);
+
+=head2 jobs
+
+Type: has_many
+
+Related object: L<Gruntmaster::Data::Result::Job>
+
+=cut
+
+__PACKAGE__->has_many(
+ "jobs",
+ "Gruntmaster::Data::Result::Job",
+ { "foreign.owner" => "self.id" },
+ { cascade_copy => 0, cascade_delete => 0 },
+);
+
+=head2 opens
+
+Type: has_many
+
+Related object: L<Gruntmaster::Data::Result::Open>
+
+=cut
+
+__PACKAGE__->has_many(
+ "opens",
+ "Gruntmaster::Data::Result::Open",
+ { "foreign.owner" => "self.id" },
+ { cascade_copy => 0, cascade_delete => 0 },
+);
+
+=head2 problems
+
+Type: has_many
+
+Related object: L<Gruntmaster::Data::Result::Problem>
+
+=cut
+
+__PACKAGE__->has_many(
+ "problems",
+ "Gruntmaster::Data::Result::Problem",
+ { "foreign.owner" => "self.id" },
+ { cascade_copy => 0, cascade_delete => 0 },
+);
+
+
+# Created by DBIx::Class::Schema::Loader v0.07039 @ 2014-03-06 12:41:16
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:CHRtUlZf3hs+lg6Nqi2LPA
+
+
+# You can replace this text with custom code or comments, and it will be preserved on regeneration
+1;
--- /dev/null
+package Gruntmaster::OldData;
+use v5.14;
+use warnings;
+use parent qw/Exporter/;
+
+use JSON qw/encode_json decode_json/;
+use Redis;
+use Sub::Name qw/subname/;
+
+our $VERSION = '5999.000_002';
+
+our $contest;
+my $redis = Redis->new;
+my $pubsub = Redis->new;
+
+sub dynsub{
+ our ($name, $sub) = @_;
+ no strict 'refs';
+ *$name = subname $name => $sub
+}
+
+BEGIN {
+ for my $cmd (qw/multi exec smembers get hget hgetall hdel hset sadd srem incr hmset hsetnx publish del/) {
+ dynsub uc $cmd, sub { $redis->$cmd(@_) };
+ }
+
+ for my $cmd (qw/subscribe wait_for_messages/) {
+ dynsub uc $cmd, sub { $pubsub->$cmd(@_) };
+ }
+}
+
+sub cp { defined $contest ? "contest.$contest." : '' }
+
+sub problems () { SMEMBERS cp . 'problem' }
+sub contests () { SMEMBERS cp . 'contest' }
+sub users () { SMEMBERS cp . 'user' }
+sub jobcard () { GET cp . 'job' }
+
+sub job_results (_) { decode_json HGET cp . "job.$_[0]", 'results' }
+sub set_job_results ($+) { HSET cp . "job.$_[0]", 'results', encode_json $_[1] }
+sub job_inmeta (_) { decode_json HGET cp . "job.$_[0]", 'inmeta' }
+sub set_job_inmeta ($+) { HSET cp . "job.$_[0]", 'inmeta', encode_json $_[1] }
+sub problem_meta (_) { decode_json HGET cp . "problem.$_[0]", 'meta' }
+sub set_problem_meta ($+) { HSET cp . "problem.$_[0]", 'meta', encode_json $_[1] }
+sub job_daemon (_) { HGET cp . "job.$_[0]", 'daemon' }
+sub set_job_daemon ($$) { HSETNX cp . "job.$_[0]", 'daemon', $_[1] };
+
+sub defhash{
+ my ($name, @keys) = @_;
+ for my $key (@keys) {
+ dynsub "${name}_$key", sub (_) { HGET cp . "$name.$_[0]", $key };
+ dynsub "set_${name}_$key", sub ($$) { HSET cp . "$name.$_[0]", $key, $_[1] };
+ }
+
+ dynsub "edit_$name", sub {
+ my ($key, %values) = @_;
+ HMSET cp . "$name.$key", %values;
+ };
+
+ dynsub "insert_$name", sub {
+ my ($key, %values) = @_;
+ SADD cp . $name, $key or return;
+ HMSET cp . "$name.$key", %values;
+ };
+ dynsub "remove_$name", sub (_) {
+ my $key = shift;
+ SREM cp . $name, $key;
+ DEL cp . "$name.$key";
+ };
+
+ dynsub "push_$name", sub {
+ my $nr = INCR cp . $name;
+ HMSET cp . "$name.$nr", @_;
+ $nr
+ };
+}
+
+defhash problem => qw/name level difficulty statement owner author private generator runner judge testcnt timeout olimit/;
+defhash contest => qw/start end name owner/;
+defhash job => qw/date errors extension filesize private problem result result_text user/;
+defhash user => qw/name email lastjob town university level/;
+
+sub clean_job (_){
+ HDEL cp . "job.$_[0]", qw/result result_text results daemon/
+}
+
+sub mark_open {
+ my ($problem, $user) = @_;
+ HSETNX cp . 'open', "$problem.$user", time;
+}
+
+sub get_open {
+ my ($problem, $user) = @_;
+ HGET cp . 'open', "$problem.$user";
+}
+
+our @EXPORT = do {
+ no strict 'refs';
+ grep { $_ =~ /^[a-zA-Z]/ and exists &$_ } keys %{__PACKAGE__ . '::'};
+};
+
+1;
+__END__
+
+=encoding utf-8
+
+=head1 NAME
+
+Gruntmaster::Data - Gruntmaster 6000 Online Judge -- database interface and tools
+
+=head1 SYNOPSIS
+
+ for my $problem (problems) {
+ say "Problem name: " . problem_name $problem;
+ say "Problem level: " . problem_level $problem;
+ ...
+ }
+
+=head1 DESCRIPTION
+
+Gruntmaster::Data is the Redis interface used by the Gruntmaster 6000 Online Judge. It exports many functions for talking to the database. All functions are exported by default.
+
+The current contest is selected by setting the C<< $Gruntmaster::Data::contest >> variable.
+
+ local $Gruntmaster::Data::contest = 'mycontest';
+ say 'There are' . jobcard . ' jobs in my contest';
+
+=head1 FUNCTIONS
+
+=head2 Redis
+
+Gruntmaster::Data exports some functions for talking directly to the Redis server. These functions should not normally be used, except for B<MULTI>, B<EXEC>, B<PUBLISH>, B<SUBSCRIBE> and B<WAIT_FOR_MESSAGES>.
+
+These functions correspond to Redis commands. The current list is: B<< MULTI EXEC SMEMBERS GET HGET HGETALL HDEL HSET SADD SREM INCR HMSET HSETNX DEL PUBLISH SUBSCRIBE WAIT_FOR_MESSAGES >>.
+
+=head2 Problems
+
+=over
+
+=item B<problems>
+
+Returns a list of problems in the current contest.
+
+=item B<problem_meta> I<$problem>
+
+Returns a problem's meta.
+
+=item B<set_problem_meta> I<$problem>, I<$meta>
+
+Sets a problem's meta.
+
+=item B<problem_name> I<$problem>
+
+Returns a problem's name.
+
+=item B<set_problem_name> I<$problem>, I<$name>
+
+Sets a problem's name.
+
+=item B<problem_level> I<$problem>
+
+Returns a problem's level. The levels are beginner, easy, medium, hard.
+
+=item B<set_problem_level> I<$problem>, I<$level>
+
+Sets a problem's level. The levels are beginner, easy, medium, hard.
+
+=item B<problem_difficulty> I<$problem>
+
+Returns a problem's difficulty.
+
+=item B<set_problem_difficulty> I<$problem>, I<$name>
+
+Sets a problem's difficulty.
+
+=item B<problem_statement> I<$problem>
+
+Returns a problem's statement.
+
+=item B<set_problem_statement> I<$problem>, I<$statement>
+
+Sets a problem's statement.
+
+=item B<problem_owner> I<$problem>
+
+Returns a problem's owner.
+
+=item B<set_problem_owner> I<$problem>, I<$owner>
+
+Sets a problem's owner.
+
+=item B<problem_author> I<$problem>
+
+Returns a problem's author.
+
+=item B<set_problem_author> I<$problem>, I<$author>
+
+Sets a problem's author.
+
+=item B<problem_private> I<$problem>
+
+Returns a problem's private flag (true if the problem is private, false otherwise).
+
+=item B<set_problem_private> I<$problem>, I<$private>
+
+Sets a problem's private flag.
+
+=item B<problem_generator> I<$problem>
+
+Returns a problem's generator. The generators are File, Run and Undef. More might be added in the future.
+
+=item B<set_problem_generator> I<$problem>, I<$generator>
+
+Sets a problem's generator.
+
+=item B<problem_runner> I<$problem>
+
+Returns a problem's runner. The runners are File, Verifier and Interactive. More might be added in the future.
+
+=item B<set_problem_runner> I<$problem>, I<$runner>
+
+Sets a problem's runner.
+
+=item B<problem_judge> I<$problem>
+
+Returns a problem's judge. The judges are Absolute and Points. More might be added in the future.
+
+=item B<set_problem_judge> I<$problem>, I<$judge>
+
+Sets a problem's judge.
+
+=item B<problem_testcnt> I<$problem>
+
+Returns a problem's test count.
+
+=item B<set_problem_testcnt> I<$problem>, I<$testcnt>
+
+Sets a problem's test count.
+
+=item B<problem_timeout> I<$problem>
+
+Returns a problem's time limit, in seconds.
+
+=item B<set_problem_timeout> I<$problem>, I<$timeout>
+
+Sets a problem's time limit, in seconds.
+
+=item B<problem_olimit> I<$problem>
+
+Returns a problem's output limit, in bytes.
+
+=item B<set_problem_olimit> I<$problem>, I<$olimit>
+
+Sets a problem's output limit, in bytes.
+
+=item B<get_open> I<$problem>, I<$user>
+
+Returns the time when I<$user> opened I<$problem>.
+
+=item B<mark_open> I<$problem>, I<$user>
+
+Sets the time when I<$user> opened I<$problem> to the current time. Does nothing if I<$user> has already opened I<$problem>.
+
+=item B<insert_problem> I<$id>, I<$key> => I<$value>, ...
+
+Inserts a problem with id I<$id> and the given initial configuration. Does nothing if a problem with id I<$id> already exists. Returns true if the problem was added, false otherwise.
+
+=item B<edit_problem> I<$id>, I<$key> => I<$value>, ...
+
+Updates the configuration of a problem. The values of the given keys are updated. All other keys/values are left intact.
+
+=item B<remove_problem> I<$id>
+
+Removes a problem.
+
+=back
+
+=head2 Contests
+
+B<<< WARNING: these functions only work correctly when C<< $Gruntmaster::Data::contest >> is undef >>>
+
+=over
+
+=item B<contests>
+
+Returns a list of contests.
+
+=item B<contest_start> I<$contest>
+
+Returns a contest's start time.
+
+=item B<set_contest_start> I<$contest>, I<$start>
+
+Sets a contest's start time.
+
+=item B<contest_end> I<$contest>
+
+Returns a contest's end time.
+
+=item B<set_contest_end> I<$contest>, I<$end>
+
+Sets a contest's end time.
+
+=item B<contest_name> I<$contest>
+
+Returns a contest's name.
+
+=item B<set_contest_name> I<$contest>, I<$name>
+
+Sets a contest's name.
+
+=item B<contest_owner> I<$contest>
+
+Returns a contest's owner.
+
+=item B<set_contest_owner> I<$contest>, I<$owner>
+
+Sets a contest's owner.
+
+=item B<insert_contest> I<$id>, I<$key> => I<$value>, ...
+
+Inserts a contest with id I<$id> and the given initial configuration. Does nothing if a contest with id I<$id> already exists. Returns true if the contest was added, false otherwise.
+
+=item B<edit_contest> I<$id>, I<$key> => I<$value>, ...
+
+Updates the configuration of a contest. The values of the given keys are updated. All other keys/values are left intact.
+
+=item B<remove_contest> I<$id>
+
+Removes a contest.
+
+=back
+
+=head2 Jobs
+
+=over
+
+=item B<jobcard>
+
+Returns the number of jobs in the database.
+
+=item B<job_results> I<$job>
+
+Returns an array of job results. Each element corresponds to a test and is a hashref with keys B<id> (test number), B<result> (result code, see L<Gruntmaster::Daemon::Constants>), B<result_text> (result description) and B<time> (time taken).
+
+=item B<set_job_results> I<$job>, I<$results>
+
+Sets a job's results.
+
+=item B<job_inmeta> I<$job>
+
+Returns a job's meta.
+
+=item B<set_job_inmeta> I<$job>, I<$meta>
+
+Sets a job's meta.
+
+=item B<job_daemon> I<$job>
+
+Returns the hostname:pid of the daemon which ran this job.
+
+=item B<set_job_daemon> I<$job>, I<$hostname_and_pid>
+
+If the job has no associated daemon, it sets the daemon and returns true. Otherwise it returns false without setting the daemon.
+
+=item B<job_date> I<$job>
+
+Returns a job's submit date.
+
+=item B<set_job_date> I<$job>, I<$date>
+
+Sets a job's submit date.
+
+=item B<job_errors> I<$job>
+
+Returns a job's compile errors.
+
+=item B<set_job_errors> I<$job>, I<$errors>
+
+Sets a job's compile errors.
+
+=item B<job_extension> I<$job>
+
+Returns a job's file name extension (e.g. "cpp", "pl", "java").
+
+=item B<set_job_extension> I<$job>, I<$extension>
+
+Sets a job's file name extension.
+
+=item B<job_filesize> I<$job>
+
+Returns a job's source file size, in bytes.
+
+=item B<set_job_filesize> I<$job>, I<$filesize>
+
+Sets a job's source file size, in bytes.
+
+=item B<job_private> I<$job>
+
+Returns the value of a job's private flag.
+
+=item B<set_job_private> I<$job>, I<$private>
+
+Sets the value of a job's private flag.
+
+=item B<job_problem> I<$job>
+
+Returns a job's problem.
+
+=item B<set_job_problem> I<$job>, I<$problem>
+
+Sets a job's problem.
+
+=item B<job_result> I<$job>
+
+Returns a job's result code. Possible result codes are described in L<Gruntmaster::Daemon::Constants>
+
+=item B<set_job_result> I<$job>, I<$result>
+
+Sets a job's result code.
+
+=item B<job_result_text> I<$job>
+
+Returns a job's result text.
+
+=item B<set_job_result_text> I<$job>, I<$result_text>
+
+Sets a job's result text.
+
+=item B<job_user> I<$job>
+
+Returns the user who submitted a job.
+
+=item B<set_job_user> I<$job>, I<$user>
+
+Sets the suer who submitted a job.
+
+=item B<clean_job> I<$job>
+
+Removes a job's daemon, result code, result text and result array.
+
+=item B<push_job> I<$key> => I<$value>, ...
+
+Inserts a job with a given initial configuration. Returns the id of the newly-added job.
+
+=item B<edit_job> I<$id>, I<$key> => I<$value>, ...
+
+Updates the configuration of a job. The values of the given keys are updated. All other keys/values are left intact.
+
+=item B<remove_job> I<$id>
+
+Removes a job.
+
+=back
+
+=head2 Users
+
+B<<< WARNING: these functions only work correctly when C<< $Gruntmaster::Data::contest >> is undef >>>
+
+=over
+
+=item B<users>
+
+Returns a list of users.
+
+=item B<user_name> I<$user>
+
+Returns a user's full name.
+
+=item B<set_user_name> I<$user>, I<$name>
+
+Sets a user's full name.
+
+=item B<user_email> I<$user>
+
+Returns a user's email address.
+
+=item B<set_user_email> I<$user>, I<$email>
+
+Sets a user's email address.
+
+=item B<user_lastjob> I<$user>
+
+Returns the time (seconds since epoch) when the user last submitted a solution.
+
+=item B<set_user_lastjob> I<$user>, I<$lastjob>
+
+Sets the time (seconds since epoch) when the user last submitted a solution.
+
+=item B<user_town> I<$user>
+
+Returns a user's town.
+
+=item B<set_user_town> I<$user>, I<$town>
+
+Sets a user's town.
+
+=item B<user_university> I<$user>
+
+Returns a user's university/highschool/place of work/etc.
+
+=item B<set_user_university> I<$user>, I<$university>
+
+Sets a user's university, highschool/place of work/etc.
+
+=item B<user_level> I<$user>
+
+Returns a user's current level of study. One of 'Highschool', 'Undergraduate', 'Master', 'Doctorate' or 'Other'.
+
+=item B<set_user_level> I<$user>, I<$level>
+
+Sets a user's current level of study.
+
+=item B<insert_user> I<$id>, I<$key> => I<$value>, ...
+
+Inserts a user with id I<$id> and the given initial configuration. Does nothing if a user with id I<$id> already exists. Returns true if the user was added, false otherwise.
+
+=item B<edit_user> I<$id>, I<$key> => I<$value>, ...
+
+Updates the configuration of a user. The values of the given keys are updated. All other keys/values are left intact.
+
+=item B<remove_user> I<$id>
+
+Removes a user.
+
+=back
+
+=head1 AUTHOR
+
+Marius Gavrilescu E<lt>marius@ieval.roE<gt>
+
+=head1 COPYRIGHT AND LICENSE
+
+Copyright (C) 2014 by Marius Gavrilescu
+
+This library is free software: you can redistribute it and/or modify
+it under the terms of the GNU Affero General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+
+=cut
--- /dev/null
+#!/usr/bin/perl -w
+use v5.14;
+use Gruntmaster::Data;
+use Gruntmaster::OldData;
+
+use JSON qw/encode_json/;
+
+my $db = Gruntmaster::Data->connect('dbi:Pg:');
+
+for (users) {
+ $db->users->create({
+ id => $_,
+ name => user_name,
+ email => user_email,
+ town => user_town,
+ university => user_university,
+ level => user_level,
+ user_lastjob() ? (lastjob => user_lastjob) : ()
+ })
+}
+
+my @jobs;
+
+for (problems) {
+ my $meta = problem_meta;
+ $db->problems->create({
+ id => $_,
+ author => problem_author,
+ generator => problem_generator() // $meta->{generator},
+ judge => problem_judge() // $meta->{judge},
+ level => problem_level,
+ name => problem_name,
+ olimit => problem_olimit() // $meta->{olimit},
+ owner => problem_owner,
+ private => (problem_private() ? 1 : 0),
+ runner => problem_runner() // $meta->{runner},
+ statement => problem_statement,
+ testcnt => problem_testcnt() // $meta->{testcnt},
+ timeout => problem_timeout() // $meta->{timeout},
+ exists $meta->{files} ? (versource => $meta->{files}{ver}{content}, verformat => $meta->{files}{ver}{format}) : ()
+ })
+}
+
+for (contests) {
+ $db->contests->create({
+ id => $_,
+ name => contest_name,
+ start => contest_start,
+ stop => contest_end,
+ owner => contest_owner,
+ });
+ local $Gruntmaster::OldData::contest = $_;
+ for (problems) {
+ $db->contest_problems->create({
+ contest => $Gruntmaster::OldData::contest,
+ problem => $_,
+ });
+ }
+ for (1 .. jobcard) {
+ eval {
+ my $meta = job_inmeta;
+ push @jobs, {
+ contest => $Gruntmaster::OldData::contest,
+ daemon => job_daemon,
+ date => job_date,
+ defined job_errors() ? (errors => job_errors) : (),
+ extension => job_extension,
+ format => $meta->{files}{prog}{format},
+ job_private() ? (private => job_private) : (),
+ problem => job_problem,
+ result => job_result,
+ result_text => job_result_text,
+ results => encode_json job_results,
+ source => $meta->{files}{prog}{content},
+ owner => job_user,
+ };
+ }
+ }
+}
+
+for (1 .. jobcard) {
+ eval{
+ my $meta = job_inmeta;
+ push @jobs, {
+ daemon => job_daemon,
+ date => job_date,
+ defined job_errors() ? (errors => job_errors) : (),
+ extension => job_extension,
+ format => $meta->{files}{prog}{format},
+ job_private() ? (private => job_private) : (),
+ problem => job_problem,
+ result => job_result,
+ result_text => job_result_text,
+ results => encode_json job_results,
+ source => $meta->{files}{prog}{content},
+ owner => job_user,
+ };
+ }
+}
+
+@jobs = map { $_->{owner} = $_->{owner} eq 'S7012MY' ? 'Petru' : $_->{owner}; $_} @jobs;
+$db->jobs->create($_) for sort {$a->{date} <=> $b->{date}} @jobs;