示例#1
0
 /**
  * Runs all the set hooks for the given problem. 
  */
 function run_hooks()
 {
     $sub = SubmissionTable::get_submission($this->id);
     $this->info['problem'] = $sub->problemid;
     $xml = new DOMDocument();
     $xml_path = ProblemTable::get_problem_xml_file($sub->problemid);
     if (empty($xml_path) or !is_file($xml_path)) {
         return;
     }
     $xml->load($xml_path);
     $xp = new DOMXPath($xml);
     $res = $xp->query("/problem/hook");
     foreach ($res as $hook) {
         $this->run_single_hook($hook->nodeValue);
     }
     /* run hooks on the submission file */
     $xml = new DOMDocument();
     $xml_path = SubmissionTable::get_submission_xml_file($this->id);
     if (empty($xml_path) or !is_file($xml_path)) {
         return;
     }
     $xml->load($xml_path);
     $xp = new DOMXPath($xml);
     $res = $xp->query("/submission/hook");
     foreach ($res as $hook) {
         $this->run_single_hook($hook->nodeValue);
     }
 }
示例#2
0
	/**
	 * @dataProvider provider
	 */
	public function testSubmission ($a, $b, $c)
	{	
		$cwd = realpath(getcwd());
		$sub = SubmissionTable::get_submission ($a);
		if (is_file ($sub->getXmlFile()))
		    $oldResult = file_get_contents ($sub->getXmlFile ());
		else $oldResult = "";
		SubmissionTable::set_score($a, 23);
		$sp = new SubmissionProcessor();
		$sp->process ($a);
		$db = contestDB::get_zend_db ();
		$res = $db->select()->from("submissionqueue")->where("id=$a")->query();
		$row = $res->fetch();
		$this->assertEquals (array ($b, $c), 
				array ($row->score, $row->state));

		$sub = SubmissionTable::get_submission ($a);
		$this->assertNotEquals ($oldResult,
			file_get_contents ($sub->getXmlFile ()));
		$sub->validateResultXML ();
	}
示例#3
0
	/**
	 * @dataProvider provider
	 */
	public function testUpload ($user, $prob, $lang, $source, $owner, $score, $result)
	{	

		ob_start ();
		$a = UploadSubmission::upload ($user, $prob, $lang, $source, $owner);
		ob_end_clean ();

		$this->assertGreaterThan (0, $a);
		$b = $score;

		ob_start ();
		$sp = new SubmissionProcessor();
		$sp->process ($a);
		ob_end_clean ();
		$db = contestDB::get_zend_db ();
		$res = $db->select()->from("submissionqueue")->where("id=$a")->query();
		$row = $res->fetch();
		$this->assertEquals (array($b, $result), 
					array($row->score, $row->state));
		$sub = SubmissionTable::get_submission ($a);
		$this->assertNotEquals ($sub, NULL);
		$this->assertTrue ($sub->validateResultXML ());
	}
示例#4
0
 public function indexAction()
 {
     $uid = Zend_Auth::getInstance();
     if (!$uid->hasIdentity()) {
         $this->_forward("login", "error", null, array());
         return;
     }
     $user = User::factory($uid->getIdentity());
     $this->contestmodel = new ContestModel();
     $this->state = $this->contestmodel->getContestState(webconfig::getContestId());
     $is_admin = $user->isAdmin();
     if (!$is_admin and $this->state == "pending_result") {
         $this->_forward("pending", "error", null, array());
         return;
     }
     $this->view->id = (int) $this->getRequest()->get("id");
     $download = $this->getRequest()->get("download");
     $this->view->sub = SubmissionTable::get_submission($this->view->id);
     if (empty($this->view->sub)) {
         $this->_forward("404", "error");
         return;
     }
     $this->view->user = Zend_Auth::getInstance()->getIdentity();
     $this->view->admin = User::factory($this->view->user)->isAdmin();
     if (empty($this->view->sub) or $this->view->user != $this->view->sub->uid and !$this->view->admin) {
         $this->_forward("illegal", "error");
         return;
     }
     if ($download == "true") {
         $this->_helper->layout->disableLayout();
         $this->view->download = true;
         $this->_response->setHeader("Content-Type", "text/src");
     } else {
         $this->view->download = false;
     }
 }
示例#5
0
 */
chdir(dirname($argv[0]));
require_once "../config.inc";
require_once "lib/db.inc";
ob_implicit_flush(true);
$user = $argv[1];
$prob = $argv[2];
$db = contestDB::get_zend_db();
$tmp = $db->select()->from('submissionqueue', 'max(id)')->where('team = ?', $user)->where('problemid = ?', $prob)->where("state <> 'Compile Error'")->where("state <> 'waiting'")->query()->fetch();
$id = $tmp->max;
if (empty($id)) {
    printf("%-15sNo valid submission\t  0\n", $user);
    exit(0);
}
require_once "lib/submissions.inc";
$sub = SubmissionTable::get_submission($id);
//print_r($sub);
$dom = new DomDocument();
$dom->load($sub->getPathToResult());
$xp = new DOMXPath($dom);
printf("%-15s", $user);
$score = 0.0;
$testar = $xp->query("/judge/testcase");
foreach ($testar as $test) {
    $exec_status = $xp->query("exec/status", $test)->item(0)->nodeValue;
    if ($exec_status != "success") {
        if ($exec_status == "TLE") {
            echo "T";
        } else {
            echo "E";
        }
示例#6
0
 /**
  * Process a submission by its submission ID
  * 
  * @param $id string Submission id
  */
 function start_process_submission($id)
 {
     $this->id = $id;
     $logger = Logger::get_logger();
     $info = array("id" => $id);
     $res = SubmissionTable::set_state($id, SUBMISSION_STATE_RUNNING, SUBMISSION_STATE_WAITING);
     if (!$res) {
         $logger->log("Processing {$id} skipped, another process took charge.", Zend_Log::INFO);
         return true;
     }
     $logger->log("Processing {$id}", Zend_Log::INFO);
     exec(get_file_name("programs/submissions.php") . " {$id} 2>/dev/null", $output, $ret);
     if ($ret) {
         SubmissionTable::set_state($id, SUBMISSION_STATE_FATAL);
         $logger->alert("FATAL ERROR: Submission ID {$id} could not be run!");
         $logger->log("exec: returned {$ret}", Zend_Log::ERR);
         $logger->log("Program returned: {$output}", Zend_Log::ERR);
         Logger::flush();
         $info['state'] = 'fatal';
         $agent = new HookAgent($id, $this->info);
         $agent->run_hooks();
         return false;
     }
     $agent = new HookAgent($id, $this->info);
     $agent->run_hooks();
     return true;
 }