+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 base 'DBIx::Class::Schema';
+
+__PACKAGE__->load_namespaces;
-use Redis;
-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_004';
+
+use Lingua::EN::Inflect qw/PL_N/;
+use Sub::Name qw/subname/;
sub dynsub{
+ our ($name, $sub) = @_;
no strict 'refs';
- *{$_[0]} = $_[1];
+ *$name = subname $name => $sub
}
BEGIN {
- for my $cmd (qw/multi exec smembers get hget 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 multi () { MULTI }
-sub rexec () { EXEC }
-
-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] };
- }
+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
- };
-}
+__END__
-defhash problem => qw/name level statement owner author/;
-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 town university level/;
+=encoding utf-8
-sub clean_job (_){
- HDEL cp . "job.$_[0]", qw/result result_text results daemon/
-}
+=head1 NAME
-sub mark_open {
- my ($problem, $user) = @_;
- HSETNX cp . 'open', "$problem.$user", time;
-}
+Gruntmaster::Data - Gruntmaster 6000 Online Judge -- database interface and tools
-sub get_open {
- my ($problem, $user) = @_;
- HGET cp . 'open', "$problem.$user";
-}
+=head1 SYNOPSIS
+
+ my $db = Gruntmaster::Data->connect('dbi:Pg:');
+
+ my $problem = $db->problem('my_problem');
+ $problem->update({timeout => 2.5}); # Set time limit to 2.5 seconds
+ $problem->rerun; # And rerun all jobs for this problem
+
+ # ...
+
+ my $contest = $db->contests->create({ # Create a new contest
+ id => 'my_contest',
+ name => 'My Awesome Contest',
+ start => time + 100,
+ end => time + 1900,
+ });
+ $db->contest_problems->create({ # Add a problem to the contest
+ contest => 'my_contest',
+ problem => 'my_problem',
+ });
+
+ say 'The contest has not started yet' if $contest->is_pending;
+
+ # ...
+
+ my @jobs = $db->jobs->search({contest => 'my_contest', owner => 'MGV'})->all;
+ $_->rerun for @jobs; # Rerun all jobs sent by MGV in my_contest
+
+=head1 DESCRIPTION
+
+Gruntmaster::Data is the interface to the Gruntmaster 6000 database. Read the L<DBIx::Class> documentation for usage information.
+
+In addition to the typical DBIx::Class::Schema methods, this module contains several convenience methods:
+
+=over
+
+=item contests
+
+Equivalent to C<< $schema->resultset('Contest') >>
+
+=item contest_problems
+
+Equivalent to C<< $schema->resultset('ContestProblem') >>
+
+=item jobs
+
+Equivalent to C<< $schema->resultset('Job') >>
+
+=item problems
+
+Equivalent to C<< $schema->resultset('Problem') >>
+
+=item users
+
+Equivalent to C<< $schema->resultset('User') >>
+
+=item contest($id)
+
+Equivalent to C<< $schema->resultset('Contest')->find($id) >>
+
+=item job($id)
+
+Equivalent to C<< $schema->resultset('Job')->find($id) >>
+
+=item problem($id)
+
+Equivalent to C<< $schema->resultset('Problem')->find($id) >>
+
+=item user($id)
+
+Equivalent to C<< $schema->resultset('User')->find($id) >>
+
+=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 same terms as Perl itself, either Perl version 5.18.1 or,
+at your option, any later version of Perl 5 you may have available.
-our @EXPORT = do {
- no strict 'refs';
- grep { $_ =~ /^[a-zA-Z]/ and exists &$_ } keys %{__PACKAGE__ . '::'};
-};
-1
+=cut