generated from NJUPTAAA/NOJ_Extension_Babel_Template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJudger.php
83 lines (73 loc) · 2.79 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
<?php
namespace App\Babel\Extension\uva;
use App\Babel\Submit\Curl;
use App\Models\Submission\SubmissionModel;
use App\Models\JudgerModel;
use App\Models\OJModel;
use Requests;
use Exception;
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",
];
private $list = [];
public function __construct()
{
$this->submissionModel = new SubmissionModel();
$this->judgerModel = new JudgerModel();
$this->list = [];
$earliest = $this->submissionModel->getEarliestSubmission(OJModel::oid('uva'));
if (!$earliest) return;
$judgerDetail = $this->judgerModel->detail($earliest['jid']);
$this->handle = $judgerDetail['handle'];
$response = $this->grab_page([
'site' => "https://uhunt.onlinejudge.org/api/subs-user/" . $judgerDetail['user_id'] . "/" . ($earliest['remote_id'] - 1),
'oj' => 'uva',
'handle' => $judgerDetail['handle'],
]);
$result = json_decode($response, true);
foreach ($result['subs'] as $i) {
$this->list[$i[0]] = ['time' => $i[3], 'verdict' => $i[2]];
}
}
public function judge($row)
{
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
return;
}
$sub['verdict'] = $this->verdict[$this->list[$row['remote_id']]['verdict']];
if ($sub['verdict'] === 'Compile Error') {
$response = $this->grab_page([
'site' => "https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=9&page=show_compilationerror&submission=$row[remote_id]",
'oj' => 'uva',
'handle' => $this->handle,
]);
if (preg_match('/<pre>([\s\S]*)<\/pre>/', $response, $match)) {
$sub['compile_info'] = trim($match[1]);
}
}
$sub['score'] = $sub['verdict'] == "Accepted" ? 1 : 0;
$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);
}
}
}