Example #1
0
function judge_a_single_submission()
{
    // Clear all caches, otherwise we would use old data!
    Entity::clear_cache();
    // Retrieve a submission
    global $self;
    $subm = Submission::get_pending_submission($self->name . micro_nonce());
    if (!$subm) {
        // no submissions right now
        sleep(DAEMON_SLEEP_TIME);
        return;
    }
    // Some information on this submission
    if (VERBOSE) {
        echo "\n";
        echo "Submission id: ", $subm->submissionid, "\n";
        echo "Submission to: ", $subm->entity_path, "\n";
        echo "Submited on:   ", format_date($subm->time), "\n";
        echo "Submission by: ", User::names_text($subm->users()), "\n";
        // this slows things down
    }
    // Let's judge it
    try {
        $judgement = new SubmissionJudgement($subm);
        $judgement->judge();
    } catch (Exception $e) {
        Log::error($e, $subm->entity_path, $self->name);
        echo "Error during judging!\n", $e;
    }
    if (VERBOSE) {
        echo "Result:        ", Status::to_text($subm), "\n";
    }
    // free up some memory
    unset($judgement);
    unset($subm);
    if (function_exists('gc_collect_cycles')) {
        // this doesn't exist in PHP < 5.3.0 :(
        gc_collect_cycles();
    }
    if (VERBOSE) {
        echo "Memory usage: ", memory_get_usage(), "\n";
    }
}
Example #2
0
 function write_print_submission($subm)
 {
     // include this submission?
     if (!isset($_REQUEST['include_failed'])) {
         if (!Status::is_passed($subm->status) and !$subm->status == Status::MISSED_DEADLINE) {
             return;
         }
     }
     // does it match a user filter?
     if (@$_REQUEST['user_filter'] != '') {
         $match = stripos(User::names_text($subm->users()), $_REQUEST['user_filter']);
         if ($match === false) {
             return;
         }
     }
     // submission header
     echo '<div class="submission">';
     echo '<div class="submission-head">';
     echo "<table><tr><td>Submission</td><td>#" . $subm->submissionid . " for <tt>" . htmlspecialchars($subm->entity_path) . "</tt></td></tr>";
     echo "<tr><td>by</td><td>" . User::names_html($subm->users()) . "</td></tr>";
     echo "<tr><td>on</td><td>" . format_date($subm->time) . "</td></tr>";
     if (!Status::is_passed($subm->status)) {
         echo "<tr><td>status</td><td><strong>" . strtoupper(Status::to_text($subm)) . "</strong></td></tr>";
     }
     echo "</table>";
     echo "</div>\n";
     if ($subm->is_archived()) {
         // file header
         echo "<div class=\"file\">";
         echo '<div class="file-head">';
         echo 'This submission has been archived';
         echo '</div></div>';
     } else {
         // submission files
         foreach ($subm->get_code_filenames() as $code_name => $filename) {
             $this->write_print_file($filename, $subm->get_file($code_name));
         }
     }
     echo "</div>\n";
 }
    die("This program must be started from the console.");
}
if (count($_SERVER['argv']) < 2) {
    die("Usage: try_to_judge_submission <SUBMISSIONID>.\n\n" . "For debug purposes, try to judge a submission and don't discard the temporary files.\n");
} else {
    $submissionid = $_SERVER['argv'][1];
}
try {
    // Retrieve the submission
    $subm = Submission::by_id($submissionid);
    // Some information on this submission
    echo "\n";
    echo "Submission id: ", $subm->submissionid, "\n";
    echo "Submission to: ", $subm->entity_path, "\n";
    echo "Submited on:   ", format_date($subm->time), "\n";
    echo "Submission by: ", User::names_text($subm->users()), "\n";
    // this slows things down
    echo "\n";
    // Let's judge it
    try {
        $judgement = new SubmissionJudgement($subm);
        $judgement->judge(false);
    } catch (Exception $e) {
        echo "Error during judging!\n", $e;
    }
    echo "\n";
    echo "Source files:  ", implode("\n               ", $judgement->get_source_file_names()), "\n";
    echo "Exe file:      ", $judgement->get_exe_file_name(), "\n";
    echo "Tempdir:       ", $judgement->get_and_keep_tempdir(), "\n";
    echo "\n";
    echo "Done. The tempdir contains all files created and used during judging.";
Example #4
0
 function write_print_submission($subm)
 {
     // include this submission?
     if (!isset($_REQUEST['include_failed'])) {
         if (!Status::is_passed($subm->status)) {
             return;
         }
     }
     // does it match a user filter?
     if (@$_REQUEST['user_filter'] != '') {
         $match = stripos(User::names_text($subm->users()), $_REQUEST['user_filter']);
         if ($match === false) {
             return;
         }
     }
     // submission header
     echo "\\section*{Submission \\#" . $subm->submissionid . " for " . htmlspecialchars($subm->entity_path) . "}\n";
     echo "by " . User::names_html($subm->users()) . ", ";
     echo "on " . format_date($subm->time) . "\n\n";
     if (!Status::is_passed($subm->status)) {
         echo "(status " . Status::to_text($subm) . ")";
     }
     // submission files
     foreach ($subm->get_code_filenames() as $code_name => $filename) {
         $this->write_print_file($filename, $subm->get_file($code_name));
     }
     echo "\\cleardoublepage\n";
 }