Skip to content

Commit

Permalink
remake Judger stripped out unavailabled API usage
Browse files Browse the repository at this point in the history
  • Loading branch information
ZsgsDesign committed Oct 23, 2021
1 parent 2ee5e96 commit 590c7e7
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 32 deletions.
73 changes: 42 additions & 31 deletions Judger.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,67 +4,81 @@
use App\Babel\Submit\Curl;
use App\Models\Submission\SubmissionModel;
use App\Models\JudgerModel;
use App\Models\OJModel;
use Requests;
use Exception;
use KubAT\PhpSimple\HtmlDomParser;
use Log;

class Judger extends Curl
{

public $verdict = [
10 => 'Submission Error',
15 => 'Submission Error', // Can't be judged
// 20 In queue
30 => "Compile Error",
35 => "Compile Error", // Restricted function
40 => "Runtime Error",
45 => "Output Limit Exceeded",
50 => "Time Limit Exceed",
60 => "Memory Limit Exceed",
70 => "Wrong Answer",
80 => "Presentation Error",
90 => "Accepted",
"Compilation error" => "Compile Error",
"Wrong answer" => "Wrong Answer",
"Accepted" => "Accepted",
"Time limit exceeded" => "Time Limit Exceed",
"Runtime error" => "Runtime Error",
'Submission error' => 'Submission Error',
"Output limit exceeded" => "Output Limit Exceeded",
"Memory limit exceed" => "Memory Limit Exceed",
];
private $list = [];
private $proceedJID = [];
private $judgerDetails = [];


public function __construct()
{
$this->submissionModel = new SubmissionModel();
$this->judgerModel = new JudgerModel();
}

$this->list = [];
$earliest = $this->submissionModel->getEarliestSubmission(OJModel::oid('uvalive'));
if (!$earliest) return;

$judgerDetail = $this->judgerModel->detail($earliest['jid']);
$this->handle = $judgerDetail['handle'];

private function fetchRemoteVerdictList($judgerDetail)
{
if(in_array($judgerDetail['jid'], $this->proceedJID)) {
return true;
}
$this->proceedJID[] = $judgerDetail['jid'];
$response = $this->grab_page([
'site' => "https://icpcarchive.ecs.baylor.edu/uhunt/api/subs-user/" . $judgerDetail['user_id'] . "/" . ($earliest['remote_id'] - 1),
'site' => "https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=9&limit=100&limitstart=0",
'oj' => 'uvalive',
'handle' => $judgerDetail['handle'],
]);
$result = json_decode($response, true);
foreach ($result['subs'] as $i) {
$this->list[$i[0]] = ['time' => $i[3], 'verdict' => $i[2]];
$submissionsDOM = HtmlDomParser::str_get_html($response, true, true, DEFAULT_TARGET_CHARSET, false);
foreach ($submissionsDOM->find('td.maincontent tr') as $verdictDOM) {
if(in_array($verdictDOM->class, ['sectiontableentry1', 'sectiontableentry2'])) {
$remoteID = $verdictDOM->find('td', 0)->plaintext;
$verdict = trim($verdictDOM->find('td', 3)->plaintext);
$time = trim($verdictDOM->find('td', 5)->plaintext) * 1000;
$this->list[$remoteID] = [
'time' => $time,
'verdict' => $verdict
];
}
}
}

private function getJudgerDetails($JID)
{
if(!isset($this->judgerDetails[$JID])) {
$this->judgerDetails[$JID] = $this->judgerModel->detail($JID);
}
return $this->judgerDetails[$JID];
}

public function judge($row)
{
$judgerDetail = $this->getJudgerDetails($row['jid']);
$this->fetchRemoteVerdictList($judgerDetail);
if (array_key_exists($row['remote_id'], $this->list)) {
$sub = [];
if (!isset($this->verdict[$this->list[$row['remote_id']]['verdict']])) { // Sometimes verdict is 0 and i have no idea why
if (!isset($this->verdict[$this->list[$row['remote_id']]['verdict']])) {
return;
}
$sub['verdict'] = $this->verdict[$this->list[$row['remote_id']]['verdict']];
if ($sub['verdict'] === 'Compile Error') {
$response = $this->grab_page([
'site' => "https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=9&page=show_compilationerror&submission=$row[remote_id]",
'oj' => 'uvalive',
'handle' => $this->handle,
'handle' => $judgerDetail['handle'],
]);
if (preg_match('/<pre>([\s\S]*)<\/pre>/', $response, $match)) {
$sub['compile_info'] = trim($match[1]);
Expand All @@ -74,9 +88,6 @@ public function judge($row)
$sub['remote_id'] = $row['remote_id'];
$sub['time'] = $this->list[$row['remote_id']]['time'];

// $ret[$row['sid']]=[
// "verdict"=>$sub['verdict']
// ];
$this->submissionModel->updateSubmission($row['sid'], $sub);
}
}
Expand Down
2 changes: 1 addition & 1 deletion babel.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"description": "UVaLive interface for NOJ",
"license": "MIT",
"repository":"https://github.com/NJUPTAAA/NOJ_Extension_UVaLive",
"version":"0.2.0",
"version":"0.2.1",
"website":"https://icpcarchive.ecs.baylor.edu/",
"provider":{
"judger":"Judger",
Expand Down

0 comments on commit 590c7e7

Please sign in to comment.