generated from NJUPTAAA/NOJ_Extension_Babel_Template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Judger.php
98 lines (85 loc) · 3.36 KB
/
Judger.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
namespace App\Babel\Extension\noiopen;
use App\Babel\Submit\Curl;
use App\Models\Submission\SubmissionModel;
use App\Models\Eloquent\Problem;
use KubAT\PhpSimple\HtmlDomParser;
use App\Models\JudgerModel;
use Requests;
use Exception;
use Log;
class Judger extends Curl
{
public $verdict=[
'Accepted'=>"Accepted",
'Wrong Answer'=>"Wrong Answer",
"Presentation Error"=>"Presentation Error",
'Time Limit Exceeded'=>"Time Limit Exceed",
"Memory Limit Exceeded"=>"Memory Limit Exceed",
'Runtime Error'=>"Runtime Error",
'Output Limit Exceeded'=>"Output Limit Exceeded",
'Compile Error'=>"Compile Error",
'System Error'=>"System Error",
];
private $model=[];
private $noiopen=[];
public function __construct()
{
$this->model["submissionModel"]=new SubmissionModel();
$this->model["judgerModel"]=new JudgerModel();
}
public function judge($row)
{
$sub=[];
if (!isset($this->noiopen[$row['remote_id']])) {
$judgerDetail=$this->model["judgerModel"]->detail($row['jid']);
$this->appendNOIOpenStatus($judgerDetail['handle'], $row['pid'], $row['remote_id']);
if (!isset($this->noiopen[$row['remote_id']])) {
return;
}
}
$status=$this->noiopen[$row['remote_id']];
if(!isset($this->verdict[$status['verdict']])) {
return ;
}
if($status['verdict']=='Waiting'){
return ;
}
$sub['verdict']=$this->verdict[$status['verdict']];
$sub['compile_info']=$status['compile_info'];
$sub["score"]=$sub['verdict']=="Accepted" ? 1 : 0;
$sub['time']=$status['time'];
$sub['memory']=$status['memory'];
$sub['remote_id']=$row['remote_id'];
$this->model["submissionModel"]->updateSubmission($row['sid'], $sub);
}
private function appendNOIOpenStatus($judger, $pid, $remoteID)
{
$origin = Problem::findOrFail($pid)->origin;
$contestChar = explode('/', explode('http://noi.openjudge.cn/', $origin, 2)[1], 2)[0];
$submissionDetailHTML=$this->grab_page([
'site' => "http://noi.openjudge.cn/$contestChar/solution/$remoteID/",
'oj' => 'noiopen',
'handle' => $judger,
]);
$submissionDetail=HtmlDomParser::str_get_html($submissionDetailHTML, true, true, DEFAULT_TARGET_CHARSET, false);
$compileDetailHTML=$submissionDetail->find('div.compile-info dl', 0)->innertext;
$memory=0;
$time=0;
if(mb_strpos($compileDetailHTML,'<dt>内存:</dt>')!==false) {
$memory=(explode('<dd>', explode('kB</dd>', explode('<dt>内存:</dt>', $compileDetailHTML, 2)[1], 2)[0], 2)[1]);
}
if(mb_strpos($compileDetailHTML,'<dt>时间:</dt>')!==false) {
$time=(explode('<dd>', explode('ms</dd>', explode('<dt>时间:</dt>', $compileDetailHTML, 2)[1], 2)[0], 2)[1]);
}
$this->noiopen[$remoteID]=[
'verdict'=>trim($submissionDetail->find('p.compile-status a', 0)->plaintext),
'memory'=>$memory,
'time'=>$time,
'compile_info'=>null,
];
if ($this->noiopen[$remoteID]['verdict']=='Compile Error') {
$this->noiopen[$remoteID]['compile_info']=$submissionDetail->find('pre', 0)->innertext;
}
}
}