public function ajaxRejudgeAction()
 {
     // 获取参数
     $solutionId = (int) Request::getPOST('solution-id');
     $solutionInfo = OjSolutionInterface::getById(array('id' => $solutionId));
     if (empty($solutionInfo)) {
         $this->renderError('Solution不存在!');
     }
     // 竞赛管理员才可以重判,或者timeout
     if (!$this->isContestAdmin && $solutionInfo['result'] != StatusVars::TIME_OUT) {
         $this->renderError('你没有权限重判!');
     }
     // 重判
     OjSolutionInterface::rejudge(array('id' => $solutionId));
     $this->renderAjax(0);
 }
Beispiel #2
0
<?php

/**
 * 从各大oj同步数据到oj_solution表
 *
 * @notice  相同帐号在同一个时间提交代码,极有可能获取结果时混淆
 */
require_once __DIR__ . '/../../../bootstrap.php';
require_once INCLUDE_PATH . '/remote_judge/HduJudger.class.php';
require_once INCLUDE_PATH . '/remote_judge/PojJudger.class.php';
require_once INCLUDE_PATH . '/remote_judge/ZojJudger.class.php';
// 获取命令行参数
$solutionId = $argv[1];
$solutionInfo = OjSolutionInterface::getById(array('id' => $solutionId));
if (empty($solutionInfo)) {
    Logger::error('judge', "Solution不存在!solutionId={$solutionId}");
    exit(1);
}
// 并发的客户端数量
const MAX_HDU_RUNNING = 2;
const MAX_POJ_RUNNING = 2;
const MAX_ZOJ_RUNNING = 2;
try {
    if ($solutionInfo['remote'] == StatusVars::REMOTE_HDU) {
        if (empty($solutionInfo['run_id']) || $solutionInfo['remote_uid'] == -1) {
            $uid = $solutionId % MAX_HDU_RUNNING;
            $judge = new HduJudger($solutionId, $uid);
            $judge->run();
        } else {
            $uid = $solutionInfo['remote_uid'];
            $judge = new HduJudger($solutionId, $uid);
 public function ajaxHelpAction()
 {
     // 获取参数
     $solutionId = Request::getPOST('solution-id');
     $solutionInfo = OjSolutionInterface::getById(array('id' => $solutionId));
     if (empty($solutionInfo)) {
         $this->renderError('solution不存在!');
     }
     // 权限
     if (!$this->isOjAdmin && $solutionInfo['user_id'] != Arr::get('id', $this->loginUserInfo, 0)) {
         $this->renderError('你没有权限操作!');
     }
     $data = array('id' => $solutionId, 'share' => 1 - $solutionInfo['share']);
     OjSolutionInterface::save($data);
     $this->renderAjax(0);
 }
Beispiel #4
0
 /**
  * 同步数据到oj_solution
  *
  * @throws  Exception
  */
 public function sync()
 {
     $solutionInfo = OjSolutionInterface::getById(array('id' => $this->solutionId));
     if (empty($solutionInfo)) {
         Logger::error('judge', "SOLUTION_ID:{$this->solutionId},Solution不存在!");
         throw new Exception("SOLUTION_ID:{$this->solutionId},Solution不存在!");
     }
     if ($solutionInfo['remote'] != StatusVars::REMOTE_POJ) {
         Logger::error('judge', "SOLUTION_ID:{$this->solutionId},必须是POJ的Solution!");
         throw new Exception("SOLUTION_ID:{$this->solutionId},必须是POJ的Solution!");
     }
     if (empty($solutionInfo['run_id'])) {
         Logger::error('judge', "RUN_ID为0!");
         throw new Exception("SOLUTION_ID:{$this->solutionId},RUN_ID为0!");
     }
     if ($solutionInfo['remote_uid'] != -1 && $solutionInfo['remote_uid'] != $this->uid) {
         Logger::error('judge', "SOLUTION_ID:{$this->solutionId},当前uid不等于remote_uid,无法获取其他用户的状态!");
         throw new Exception("SOLUTION_ID:{$this->solutionId},当前uid不等于remote_uid,无法获取其他用户的状态!");
     }
     // 尝试多次获取结果
     $rowInfo = array();
     $i = 1;
     while ($i <= 10) {
         $rowInfo = $this->getResult($solutionInfo['run_id']);
         if (false === $rowInfo || in_array($rowInfo['result'], StatusVars::$pojResultMap)) {
             break;
         }
         $i > 5 ? sleep(2) : usleep(500000);
         $i++;
     }
     // 获取获取结果超时
     if (false === $rowInfo) {
         Logger::info('judge', "SOLUTION_ID:{$this->solutionId},获取结果失败2,写入TIME_OUT");
         $data = array('id' => $this->solutionId, 'result' => StatusVars::TIME_OUT, 'time_cost' => 0, 'memory_cost' => 0);
         OjSolutionInterface::save($data);
     } else {
         Logger::info('judge', "SOLUTION_ID:{$this->solutionId},POJ远程judge成功!尝试次数:{$i}");
         $trans = new Trans(DbConfig::$SERVER_TRANS);
         $trans->begin();
         $data = array('trans' => $trans, 'id' => $this->solutionId, 'result' => $rowInfo['result'], 'time_cost' => $rowInfo['time_cost'], 'memory_cost' => $rowInfo['memory_cost']);
         OjSolutionInterface::save($data);
         // 保存Log
         $dataLog = array('trans' => $trans, 'solution_id' => $this->solutionId, 'ce' => Arr::get('ce', $rowInfo['judge_log'], ''), 're' => Arr::get('re', $rowInfo['judge_log'], ''));
         OjSolutionLogInterface::save($dataLog);
         $trans->commit();
     }
 }