@@ -5,7 +5,7 @@ discard block |
||
| 5 | 5 | use App\Http\Controllers\VirtualCrawler\CrawlerBase; |
| 6 | 6 | use App\Models\ProblemModel; |
| 7 | 7 | use KubAT\PhpSimple\HtmlDomParser; |
| 8 | -use Auth,Requests,Exception; |
|
| 8 | +use Auth, Requests, Exception; |
|
| 9 | 9 | |
| 10 | 10 | class Vijos extends CrawlerBase |
| 11 | 11 | { |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * |
| 17 | 17 | * @return Response |
| 18 | 18 | */ |
| 19 | - public function __construct($action = 'crawl_problem', $con = 'all', $cached = false) |
|
| 19 | + public function __construct($action='crawl_problem', $con='all', $cached=false) |
|
| 20 | 20 | { |
| 21 | 21 | set_time_limit(0); // Pandora's box, engage! |
| 22 | 22 | if ($action=='judge_level') { |
@@ -33,38 +33,38 @@ discard block |
||
| 33 | 33 | |
| 34 | 34 | public function crawling($con) |
| 35 | 35 | { |
| 36 | - if ($con == 'all') { |
|
| 36 | + if ($con=='all') { |
|
| 37 | 37 | // TODO |
| 38 | 38 | return; |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | try { |
| 42 | - $dom = HtmlDomParser::file_get_html('https://vijos.org/p/'.$con, false, null, 0, -1, true, true, DEFAULT_TARGET_CHARSET, false); |
|
| 42 | + $dom=HtmlDomParser::file_get_html('https://vijos.org/p/'.$con, false, null, 0, -1, true, true, DEFAULT_TARGET_CHARSET, false); |
|
| 43 | 43 | } |
| 44 | 44 | catch (Exception $e) { |
| 45 | - if (strpos($e->getMessage(), '404 Not Found') !== false) { |
|
| 45 | + if (strpos($e->getMessage(), '404 Not Found')!==false) { |
|
| 46 | 46 | header('HTTP/1.1 404 Not Found'); |
| 47 | 47 | die(); |
| 48 | 48 | } |
| 49 | - if (strpos($e->getMessage(), '403 Forbidden') !== false) { |
|
| 49 | + if (strpos($e->getMessage(), '403 Forbidden')!==false) { |
|
| 50 | 50 | header('HTTP/1.1 403 Forbidden'); |
| 51 | 51 | die(); |
| 52 | 52 | } |
| 53 | 53 | throw $e; |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | - $mainDiv = $dom->find(".section__body", 0); |
|
| 56 | + $mainDiv=$dom->find(".section__body", 0); |
|
| 57 | 57 | |
| 58 | - $eles = $mainDiv->children(); |
|
| 58 | + $eles=$mainDiv->children(); |
|
| 59 | 59 | array_push($eles, null); |
| 60 | - $this->pro['description'] = null; |
|
| 61 | - $this->pro['input'] = null; |
|
| 62 | - $this->pro['output'] = null; |
|
| 63 | - $this->pro['sample'] = []; |
|
| 64 | - $this->pro['note'] = null; |
|
| 65 | - $this->pro['sampleDesc'] = null; |
|
| 66 | - $this->pro['limit'] = null; |
|
| 67 | - $patterns = [ |
|
| 60 | + $this->pro['description']=null; |
|
| 61 | + $this->pro['input']=null; |
|
| 62 | + $this->pro['output']=null; |
|
| 63 | + $this->pro['sample']=[]; |
|
| 64 | + $this->pro['note']=null; |
|
| 65 | + $this->pro['sampleDesc']=null; |
|
| 66 | + $this->pro['limit']=null; |
|
| 67 | + $patterns=[ |
|
| 68 | 68 | 'description' => '<h1>描述</h1>', |
| 69 | 69 | '_format' => '<h1>格式</h1>', |
| 70 | 70 | 'input' => '<h2>输入格式</h2>', |
@@ -77,78 +77,78 @@ discard block |
||
| 77 | 77 | 'sampleDesc' => '/<h1>样例(说明|解释)<\/h1>|<h2>样例说明1<\/h2>/', // P2036 has <h2>样例说明1</h2> |
| 78 | 78 | 'source' => '<h1>来源</h1>', |
| 79 | 79 | ]; |
| 80 | - $lastPart = ''; |
|
| 81 | - $content = ''; |
|
| 82 | - $cursample = []; |
|
| 80 | + $lastPart=''; |
|
| 81 | + $content=''; |
|
| 82 | + $cursample=[]; |
|
| 83 | 83 | foreach ($eles as $ele) { |
| 84 | - $html = $ele ? $ele->outertext : null; |
|
| 85 | - $match = !$ele; |
|
| 84 | + $html=$ele ? $ele->outertext : null; |
|
| 85 | + $match=!$ele; |
|
| 86 | 86 | if (!$match) { |
| 87 | 87 | foreach ($patterns as $key=>$value) { |
| 88 | - if ($value[0] != '/' && $html == $value || $value[0] == '/' && preg_match($value, $html)) { |
|
| 89 | - $match = $key; |
|
| 88 | + if ($value[0]!='/' && $html==$value || $value[0]=='/' && preg_match($value, $html)) { |
|
| 89 | + $match=$key; |
|
| 90 | 90 | break; |
| 91 | 91 | } |
| 92 | 92 | } |
| 93 | 93 | } |
| 94 | 94 | if (!$lastPart) { |
| 95 | - if ($match) $lastPart = $match; |
|
| 95 | + if ($match) $lastPart=$match; |
|
| 96 | 96 | continue; |
| 97 | 97 | } |
| 98 | 98 | if ($match) { |
| 99 | - if ($lastPart[0] != '_') { |
|
| 100 | - $this->pro[$lastPart] = $content; |
|
| 101 | - $content = ''; |
|
| 102 | - } else if ($lastPart == '__sampleOutput') { // Assume output always follows by input |
|
| 99 | + if ($lastPart[0]!='_') { |
|
| 100 | + $this->pro[$lastPart]=$content; |
|
| 101 | + $content=''; |
|
| 102 | + } else if ($lastPart=='__sampleOutput') { // Assume output always follows by input |
|
| 103 | 103 | array_push($this->pro['sample'], $cursample); |
| 104 | - $cursample = []; |
|
| 104 | + $cursample=[]; |
|
| 105 | 105 | } |
| 106 | - $lastPart = $match; |
|
| 106 | + $lastPart=$match; |
|
| 107 | 107 | } else { |
| 108 | - if ($lastPart[1] != '_') { |
|
| 109 | - if ($lastPart != 'source') $content .= $html; |
|
| 110 | - else $content .= $ele->innertext; |
|
| 108 | + if ($lastPart[1]!='_') { |
|
| 109 | + if ($lastPart!='source') $content.=$html; |
|
| 110 | + else $content.=$ele->innertext; |
|
| 111 | 111 | } else { // Code |
| 112 | - $code = trim($ele->find('code', 0)->innertext); |
|
| 113 | - if ($lastPart == '__sampleInput') { if (isset($cursample['sampleInput'])) die($con); } |
|
| 112 | + $code=trim($ele->find('code', 0)->innertext); |
|
| 113 | + if ($lastPart=='__sampleInput') { if (isset($cursample['sampleInput'])) die($con); } |
|
| 114 | 114 | else { if (isset($cursample['sampleOutput'])) die($con); } |
| 115 | - if (count($ele->children()) != 1) die($con); |
|
| 116 | - if ($lastPart == '__sampleInput') $cursample['sample_input'] = $code; |
|
| 117 | - else $cursample['sample_output'] = $code; |
|
| 115 | + if (count($ele->children())!=1) die($con); |
|
| 116 | + if ($lastPart=='__sampleInput') $cursample['sample_input']=$code; |
|
| 117 | + else $cursample['sample_output']=$code; |
|
| 118 | 118 | } |
| 119 | 119 | } |
| 120 | 120 | if (!$ele) break; |
| 121 | 121 | } |
| 122 | 122 | |
| 123 | - $this->pro['time_limit'] = 1000; |
|
| 124 | - $this->pro['memory_limit'] = 262144; |
|
| 123 | + $this->pro['time_limit']=1000; |
|
| 124 | + $this->pro['memory_limit']=262144; |
|
| 125 | 125 | if ($this->pro['sampleDesc']) { |
| 126 | - $this->pro['note'] = '<h3>样例说明</h3>'.$this->pro['sampleDesc'].$this->pro['note']; |
|
| 126 | + $this->pro['note']='<h3>样例说明</h3>'.$this->pro['sampleDesc'].$this->pro['note']; |
|
| 127 | 127 | } |
| 128 | 128 | if ($this->pro['limit']) { |
| 129 | - $this->pro['note'] = $this->pro['limit'].$this->pro['note']; |
|
| 130 | - $this->pro['time_limit'] = 0; |
|
| 131 | - $this->pro['memory_limit'] = 0; |
|
| 129 | + $this->pro['note']=$this->pro['limit'].$this->pro['note']; |
|
| 130 | + $this->pro['time_limit']=0; |
|
| 131 | + $this->pro['memory_limit']=0; |
|
| 132 | 132 | } |
| 133 | 133 | |
| 134 | - $title = $dom->find('.section__header', 0)->find('h1', 0)->innertext; |
|
| 135 | - $this->pro['pcode'] = 'VIJ'.$con; |
|
| 136 | - $this->pro['OJ'] = $this->oid; |
|
| 137 | - $this->pro['contest_id'] = null; |
|
| 138 | - $this->pro['index_id'] = $con; |
|
| 139 | - $this->pro['origin'] = 'https://vijos.org/p/'.$con; |
|
| 140 | - $this->pro['title'] = $title; |
|
| 141 | - $this->pro['input_type'] = 'standard input'; |
|
| 142 | - $this->pro['output_type'] = 'standard output'; |
|
| 134 | + $title=$dom->find('.section__header', 0)->find('h1', 0)->innertext; |
|
| 135 | + $this->pro['pcode']='VIJ'.$con; |
|
| 136 | + $this->pro['OJ']=$this->oid; |
|
| 137 | + $this->pro['contest_id']=null; |
|
| 138 | + $this->pro['index_id']=$con; |
|
| 139 | + $this->pro['origin']='https://vijos.org/p/'.$con; |
|
| 140 | + $this->pro['title']=$title; |
|
| 141 | + $this->pro['input_type']='standard input'; |
|
| 142 | + $this->pro['output_type']='standard output'; |
|
| 143 | 143 | |
| 144 | - $this->pro['markdown'] = 0; |
|
| 145 | - $this->pro['tot_score'] = 100; |
|
| 146 | - $this->pro["partial"] = 1; |
|
| 147 | - $this->pro['source'] = "P{$con} {$title}"; |
|
| 144 | + $this->pro['markdown']=0; |
|
| 145 | + $this->pro['tot_score']=100; |
|
| 146 | + $this->pro["partial"]=1; |
|
| 147 | + $this->pro['source']="P{$con} {$title}"; |
|
| 148 | 148 | |
| 149 | - $info = $dom->find(".horizontal", 0); |
|
| 149 | + $info=$dom->find(".horizontal", 0); |
|
| 150 | 150 | preg_match('/<dt>已通过<\/dt>[\s\S]*<dd>(\d+)<\/dd>/', $info->innertext, $match); |
| 151 | - $this->pro['solved_count'] = $match[1]; |
|
| 151 | + $this->pro['solved_count']=$match[1]; |
|
| 152 | 152 | |
| 153 | 153 | $problemModel=new ProblemModel(); |
| 154 | 154 | $problem=$problemModel->pid($this->pro['pcode']); |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | $new_pid=$this->insert_problem($this->oid); |
| 161 | 161 | } |
| 162 | 162 | |
| 163 | - $tags = $info->find('.hasjs--hide', 0); |
|
| 163 | + $tags=$info->find('.hasjs--hide', 0); |
|
| 164 | 164 | if ($tags) { |
| 165 | 165 | foreach ($tags->find('a') as $tag) { |
| 166 | 166 | $problemModel->addTags($new_pid, $tag->innertext); |
@@ -21,11 +21,11 @@ discard block |
||
| 21 | 21 | private function ojLogin() |
| 22 | 22 | { |
| 23 | 23 | $response=$this->grab_page('https://vijos.org', 'vijos'); |
| 24 | - if (strpos($response, '登出') === false) { |
|
| 24 | + if (strpos($response, '登出')===false) { |
|
| 25 | 25 | |
| 26 | 26 | $judger=new JudgerModel(); |
| 27 | 27 | $judger_list=$judger->list(5); |
| 28 | - $params = [ |
|
| 28 | + $params=[ |
|
| 29 | 29 | 'uname' => $judger_list[0]["handle"], |
| 30 | 30 | 'password' => $judger_list[0]["password"], |
| 31 | 31 | 'rememberme' => 'on', |
@@ -36,9 +36,9 @@ discard block |
||
| 36 | 36 | |
| 37 | 37 | private function submitSolution() |
| 38 | 38 | { |
| 39 | - $compilerModel = new CompilerModel(); |
|
| 40 | - $lang = $compilerModel->detail($this->post_data["coid"]); |
|
| 41 | - $pid = $this->post_data['iid']; |
|
| 39 | + $compilerModel=new CompilerModel(); |
|
| 40 | + $lang=$compilerModel->detail($this->post_data["coid"]); |
|
| 41 | + $pid=$this->post_data['iid']; |
|
| 42 | 42 | $this->sub['language']=$lang['display_name']; |
| 43 | 43 | $this->sub['solution']=$this->post_data["solution"]; |
| 44 | 44 | $this->sub['pid']=$this->post_data["pid"]; |
@@ -52,16 +52,16 @@ discard block |
||
| 52 | 52 | $response=$this->grab_page("https://vijos.org/p/{$pid}/submit", 'vijos'); |
| 53 | 53 | preg_match('/"csrf_token":"([0-9a-f]{64})"/', $response, $match); |
| 54 | 54 | |
| 55 | - $params = [ |
|
| 55 | + $params=[ |
|
| 56 | 56 | 'lang' => $lang['lcode'], |
| 57 | 57 | 'code' => $this->post_data["solution"], |
| 58 | 58 | 'csrf_token' => $match[1], |
| 59 | 59 | ]; |
| 60 | 60 | $response=$this->post_data("https://vijos.org/p/{$pid}/submit", http_build_query($params), "vijos", true, false); |
| 61 | 61 | if (preg_match('/\nLocation: \/records\/(.+)/i', $response, $match)) { |
| 62 | - $this->sub['remote_id'] = $match[1]; |
|
| 62 | + $this->sub['remote_id']=$match[1]; |
|
| 63 | 63 | } else { |
| 64 | - $this->sub['verdict'] = 'Submission Error'; |
|
| 64 | + $this->sub['verdict']='Submission Error'; |
|
| 65 | 65 | } |
| 66 | 66 | } |
| 67 | 67 | |
@@ -30,8 +30,8 @@ discard block |
||
| 30 | 30 | "COMPILATION_ERROR"=>"Compile Error", |
| 31 | 31 | "RUNTIME_ERROR"=> "Runtime Error", |
| 32 | 32 | "WRONG_ANSWER"=> "Wrong Answer", |
| 33 | - "TIME_LIMIT_EXCEEDED"=>"Time Limit Exceed" , |
|
| 34 | - "OK"=>"Accepted" , |
|
| 33 | + "TIME_LIMIT_EXCEEDED"=>"Time Limit Exceed", |
|
| 34 | + "OK"=>"Accepted", |
|
| 35 | 35 | "MEMORY_LIMIT_EXCEEDED"=>"Memory Limit Exceed", |
| 36 | 36 | "PRESENTATION_ERROR"=>"Presentation Error"]; |
| 37 | 37 | |
@@ -100,96 +100,96 @@ discard block |
||
| 100 | 100 | if ($row['oid']==2) { |
| 101 | 101 | if (isset($codeforces_v[$cf[$i][2]])) { |
| 102 | 102 | |
| 103 | - $sub['verdict'] = $codeforces_v[$cf[$i][2]]; |
|
| 104 | - $sub["score"]=$sub['verdict']=="Accepted"?1:0; |
|
| 105 | - $sub['time'] = $cf[$i][0]; |
|
| 106 | - $sub['memory'] = $cf[$i][1]; |
|
| 107 | - $sub['remote_id'] = $cf[$i][3]; |
|
| 103 | + $sub['verdict']=$codeforces_v[$cf[$i][2]]; |
|
| 104 | + $sub["score"]=$sub['verdict']=="Accepted" ? 1 : 0; |
|
| 105 | + $sub['time']=$cf[$i][0]; |
|
| 106 | + $sub['memory']=$cf[$i][1]; |
|
| 107 | + $sub['remote_id']=$cf[$i][3]; |
|
| 108 | 108 | |
| 109 | - $ret[$row['sid']] = [ |
|
| 109 | + $ret[$row['sid']]=[ |
|
| 110 | 110 | "verdict"=>$sub['verdict'] |
| 111 | 111 | ]; |
| 112 | 112 | |
| 113 | 113 | $this->MODEL->update_submission($row['sid'], $sub); |
| 114 | 114 | } |
| 115 | 115 | $i++; |
| 116 | - } else if ($row['oid'] == 3) { |
|
| 116 | + } else if ($row['oid']==3) { |
|
| 117 | 117 | try { |
| 118 | - $res = Requests::get('http://contest-hunter.org:83/record/'.$row['remote_id']); |
|
| 118 | + $res=Requests::get('http://contest-hunter.org:83/record/'.$row['remote_id']); |
|
| 119 | 119 | preg_match('/<dt>状态<\/dt>[\s\S]*?<dd class=".*?">(.*?)<\/dd>/m', $res->body, $match); |
| 120 | - $status = $match[1]; |
|
| 120 | + $status=$match[1]; |
|
| 121 | 121 | if (!array_key_exists($status, $contesthunter_v)) continue; |
| 122 | - $sub['verdict'] = $contesthunter_v[$status]; |
|
| 123 | - $sub["score"]=$sub['verdict']=="Accepted"?1:0; |
|
| 124 | - $sub['remote_id'] = $row['remote_id']; |
|
| 125 | - if ($sub['verdict'] != "Submission Error" && $sub['verdict'] != "Compile Error") { |
|
| 122 | + $sub['verdict']=$contesthunter_v[$status]; |
|
| 123 | + $sub["score"]=$sub['verdict']=="Accepted" ? 1 : 0; |
|
| 124 | + $sub['remote_id']=$row['remote_id']; |
|
| 125 | + if ($sub['verdict']!="Submission Error" && $sub['verdict']!="Compile Error") { |
|
| 126 | 126 | preg_match('/占用内存[\s\S]*?(\d+).*?KiB/m', $res->body, $match); |
| 127 | - $sub['memory'] = $match[1]; |
|
| 128 | - $maxtime = 0; |
|
| 127 | + $sub['memory']=$match[1]; |
|
| 128 | + $maxtime=0; |
|
| 129 | 129 | preg_match_all('/<span class="pull-right muted">(\d+) ms \/ \d+ KiB<\/span>/', $res->body, $matches); |
| 130 | 130 | foreach ($matches[1] as $time) { |
| 131 | - if ($time < $maxtime) $maxtime = $time; |
|
| 131 | + if ($time<$maxtime) $maxtime=$time; |
|
| 132 | 132 | } |
| 133 | - $sub['time'] = $maxtime; |
|
| 133 | + $sub['time']=$maxtime; |
|
| 134 | 134 | } else { |
| 135 | - $sub['memory'] = 0; |
|
| 136 | - $sub['time'] = 0; |
|
| 135 | + $sub['memory']=0; |
|
| 136 | + $sub['time']=0; |
|
| 137 | 137 | } |
| 138 | 138 | |
| 139 | - $ret[$row['sid']] = [ |
|
| 139 | + $ret[$row['sid']]=[ |
|
| 140 | 140 | "verdict"=>$sub['verdict'] |
| 141 | 141 | ]; |
| 142 | 142 | $this->MODEL->update_submission($row['sid'], $sub); |
| 143 | 143 | } |
| 144 | - catch(Exception $e) {} |
|
| 145 | - } else if ($row['oid'] == 4) { |
|
| 144 | + catch (Exception $e) {} |
|
| 145 | + } else if ($row['oid']==4) { |
|
| 146 | 146 | if (!isset($poj[$row['remote_id']])) { |
| 147 | 147 | $this->appendPOJStatus($poj, $pojJudgerName, $row['remote_id']); |
| 148 | 148 | if (!isset($poj[$row['remote_id']])) continue; |
| 149 | 149 | } |
| 150 | - $status = $poj[$row['remote_id']]; |
|
| 151 | - $sub['verdict'] = $poj_v[$status['verdict']]; |
|
| 152 | - $sub["score"]=$sub['verdict']=="Accepted"?1:0; |
|
| 153 | - $sub['time'] = $status['time']; |
|
| 154 | - $sub['memory'] = $status['memory']; |
|
| 155 | - $sub['remote_id'] = $row['remote_id']; |
|
| 156 | - |
|
| 157 | - $ret[$row['sid']] = [ |
|
| 150 | + $status=$poj[$row['remote_id']]; |
|
| 151 | + $sub['verdict']=$poj_v[$status['verdict']]; |
|
| 152 | + $sub["score"]=$sub['verdict']=="Accepted" ? 1 : 0; |
|
| 153 | + $sub['time']=$status['time']; |
|
| 154 | + $sub['memory']=$status['memory']; |
|
| 155 | + $sub['remote_id']=$row['remote_id']; |
|
| 156 | + |
|
| 157 | + $ret[$row['sid']]=[ |
|
| 158 | 158 | "verdict"=>$sub['verdict'] |
| 159 | 159 | ]; |
| 160 | 160 | $this->MODEL->update_submission($row['sid'], $sub); |
| 161 | - } else if ($row['oid'] == 5) { |
|
| 161 | + } else if ($row['oid']==5) { |
|
| 162 | 162 | try { |
| 163 | - $res = Requests::get('https://vijos.org/records/'.$row['remote_id']); |
|
| 163 | + $res=Requests::get('https://vijos.org/records/'.$row['remote_id']); |
|
| 164 | 164 | preg_match('/<span class="record-status--text \w*">\s*(.*?)\s*<\/span>/', $res->body, $match); |
| 165 | - $status = $match[1]; |
|
| 165 | + $status=$match[1]; |
|
| 166 | 166 | if (!array_key_exists($status, $vijos_v)) continue; |
| 167 | - $sub['verdict'] = $vijos_v[$status]; |
|
| 167 | + $sub['verdict']=$vijos_v[$status]; |
|
| 168 | 168 | preg_match('/<dt>分数<\/dt>\s*<dd>(\d+)<\/dd>/', $res->body, $match); |
| 169 | - $sub['score'] = $match[1]; |
|
| 170 | - $sub['remote_id'] = $row['remote_id']; |
|
| 171 | - if ($sub['verdict'] != "Submission Error" && $sub['verdict'] != "Compile Error") { |
|
| 172 | - $maxtime = 0; |
|
| 169 | + $sub['score']=$match[1]; |
|
| 170 | + $sub['remote_id']=$row['remote_id']; |
|
| 171 | + if ($sub['verdict']!="Submission Error" && $sub['verdict']!="Compile Error") { |
|
| 172 | + $maxtime=0; |
|
| 173 | 173 | preg_match_all('/<td class="col--time">(?:≥)?(\d+)ms<\/td>/', $res->body, $matches); |
| 174 | 174 | foreach ($matches as $match) { |
| 175 | - if ($match[1] > $maxtime) $maxtime = $match[1]; |
|
| 175 | + if ($match[1]>$maxtime) $maxtime=$match[1]; |
|
| 176 | 176 | } |
| 177 | - $sub['time'] = $maxtime; |
|
| 177 | + $sub['time']=$maxtime; |
|
| 178 | 178 | preg_match('/<dt>峰值内存<\/dt>\s*<dd>(?:≥)?([\d.]+) ([KM])iB<\/dd>/', $res->body, $match); |
| 179 | - $memory = $match[1]; |
|
| 180 | - if ($match[2] == 'M') $memory *= 1024; |
|
| 181 | - $sub['memory'] = intval($memory); |
|
| 179 | + $memory=$match[1]; |
|
| 180 | + if ($match[2]=='M') $memory*=1024; |
|
| 181 | + $sub['memory']=intval($memory); |
|
| 182 | 182 | } else { |
| 183 | - $sub['memory'] = 0; |
|
| 184 | - $sub['time'] = 0; |
|
| 183 | + $sub['memory']=0; |
|
| 184 | + $sub['time']=0; |
|
| 185 | 185 | } |
| 186 | 186 | |
| 187 | - $ret[$row['sid']] = [ |
|
| 187 | + $ret[$row['sid']]=[ |
|
| 188 | 188 | "verdict"=>$sub['verdict'] |
| 189 | 189 | ]; |
| 190 | 190 | $this->MODEL->update_submission($row['sid'], $sub); |
| 191 | 191 | } |
| 192 | - catch(Exception $e) {} |
|
| 192 | + catch (Exception $e) {} |
|
| 193 | 193 | } |
| 194 | 194 | // if ($row['oid']=='Spoj') { |
| 195 | 195 | // if (isset($spoj_v[$sj[$j][2]])) { |
@@ -241,7 +241,7 @@ discard block |
||
| 241 | 241 | return $ret; |
| 242 | 242 | } |
| 243 | 243 | $response=$this->grab_page('https://uva.onlinejudge.org', 'uva'); |
| 244 | - if (!(strpos($response, 'UVa Online Judge - Offline') !== false)) { |
|
| 244 | + if (!(strpos($response, 'UVa Online Judge - Offline')!==false)) { |
|
| 245 | 245 | $this->uva_live_login('https://uva.onlinejudge.org', 'https://uva.onlinejudge.org/index.php?option=com_comprofiler&task=login', 'uva'); |
| 246 | 246 | } else { |
| 247 | 247 | return $ret; |
@@ -251,24 +251,24 @@ discard block |
||
| 251 | 251 | while (true) { |
| 252 | 252 | $response=$this->grab_page("https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=9&limit=50&limitstart={$i}", 'uva'); |
| 253 | 253 | |
| 254 | - $exploded = explode('<table cellpadding="4" cellspacing="0" border="0" width="100%">', $response); |
|
| 255 | - $table = explode('</table>', $exploded[1])[0]; |
|
| 254 | + $exploded=explode('<table cellpadding="4" cellspacing="0" border="0" width="100%">', $response); |
|
| 255 | + $table=explode('</table>', $exploded[1])[0]; |
|
| 256 | 256 | |
| 257 | - $table = explode('<tr class="sectiontableentry', $table); |
|
| 257 | + $table=explode('<tr class="sectiontableentry', $table); |
|
| 258 | 258 | |
| 259 | - for ($j=1;$j<count($table);$j++) { |
|
| 259 | + for ($j=1; $j<count($table); $j++) { |
|
| 260 | 260 | $num--; |
| 261 | 261 | $sub=$table[$j]; |
| 262 | 262 | |
| 263 | - $sub = explode('<td>', $sub); |
|
| 263 | + $sub=explode('<td>', $sub); |
|
| 264 | 264 | $verdict=explode('</td>', $sub[3])[0]; |
| 265 | 265 | $time=explode('</td>', $sub[5])[0]; |
| 266 | 266 | |
| 267 | - if ((strpos($verdict, '<a href=') !== false)) { |
|
| 267 | + if ((strpos($verdict, '<a href=')!==false)) { |
|
| 268 | 268 | $verdict=explode('</a', explode('>', explode('<a href=', $verdict)[1])[1])[0]; |
| 269 | 269 | } |
| 270 | 270 | |
| 271 | - array_push($ret, array($time*1000,-1,$verdict)); |
|
| 271 | + array_push($ret, array($time * 1000, -1, $verdict)); |
|
| 272 | 272 | |
| 273 | 273 | if ($num==0) { |
| 274 | 274 | return array_reverse($ret); |
@@ -298,24 +298,24 @@ discard block |
||
| 298 | 298 | while (true) { |
| 299 | 299 | $response=$this->grab_page("https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=9&limit=50&limitstart={$i}", 'uvalive'); |
| 300 | 300 | |
| 301 | - $exploded = explode('<table cellpadding="4" cellspacing="0" border="0" width="100%">', $response); |
|
| 302 | - $table = explode('</table>', $exploded[1])[0]; |
|
| 301 | + $exploded=explode('<table cellpadding="4" cellspacing="0" border="0" width="100%">', $response); |
|
| 302 | + $table=explode('</table>', $exploded[1])[0]; |
|
| 303 | 303 | |
| 304 | - $table = explode('<tr class="sectiontableentry', $table); |
|
| 304 | + $table=explode('<tr class="sectiontableentry', $table); |
|
| 305 | 305 | |
| 306 | - for ($j=1;$j<count($table);$j++) { |
|
| 306 | + for ($j=1; $j<count($table); $j++) { |
|
| 307 | 307 | $num--; |
| 308 | 308 | $sub=$table[$j]; |
| 309 | 309 | |
| 310 | - $sub = explode('<td>', $sub); |
|
| 310 | + $sub=explode('<td>', $sub); |
|
| 311 | 311 | $verdict=explode('</td>', $sub[3])[0]; |
| 312 | 312 | $time=explode('</td>', $sub[5])[0]; |
| 313 | 313 | |
| 314 | - if ((strpos($verdict, '<a href=') !== false)) { |
|
| 314 | + if ((strpos($verdict, '<a href=')!==false)) { |
|
| 315 | 315 | $verdict=explode('</a', explode('>', explode('<a href=', $verdict)[1])[1])[0]; |
| 316 | 316 | } |
| 317 | 317 | |
| 318 | - array_push($ret, array($time*1000,-1,$verdict)); |
|
| 318 | + array_push($ret, array($time * 1000, -1, $verdict)); |
|
| 319 | 319 | |
| 320 | 320 | if ($num==0) { |
| 321 | 321 | return array_reverse($ret); |
@@ -348,11 +348,11 @@ discard block |
||
| 348 | 348 | curl_close($ch); |
| 349 | 349 | $result=json_decode($response, true); |
| 350 | 350 | if ($result["status"]=="OK") { |
| 351 | - for ($i=0;$i<$num;$i++) { |
|
| 351 | + for ($i=0; $i<$num; $i++) { |
|
| 352 | 352 | if (!isset($result["result"][$i]["verdict"])) { |
| 353 | 353 | return array_reverse($ret); |
| 354 | 354 | } |
| 355 | - array_push($ret, array($result["result"][$i]["timeConsumedMillis"],$result["result"][$i]["memoryConsumedBytes"]/1000,$result["result"][$i]["verdict"],$result["result"][$i]["id"])); |
|
| 355 | + array_push($ret, array($result["result"][$i]["timeConsumedMillis"], $result["result"][$i]["memoryConsumedBytes"] / 1000, $result["result"][$i]["verdict"], $result["result"][$i]["id"])); |
|
| 356 | 356 | } |
| 357 | 357 | } |
| 358 | 358 | return array_reverse($ret); |
@@ -377,22 +377,22 @@ discard block |
||
| 377 | 377 | $response=file_get_contents("http://www.spoj.com/status/our_judge/all/start={$i}"); |
| 378 | 378 | |
| 379 | 379 | |
| 380 | - $exploded = explode('<table class="problems table newstatus">', $response); |
|
| 381 | - $table = explode('</table>', $exploded[1])[0]; |
|
| 380 | + $exploded=explode('<table class="problems table newstatus">', $response); |
|
| 381 | + $table=explode('</table>', $exploded[1])[0]; |
|
| 382 | 382 | |
| 383 | - $table = explode('<td class="statustext text-center">', $table); |
|
| 383 | + $table=explode('<td class="statustext text-center">', $table); |
|
| 384 | 384 | |
| 385 | - for ($j=1;$j<count($table);$j++) { |
|
| 385 | + for ($j=1; $j<count($table); $j++) { |
|
| 386 | 386 | $num--; |
| 387 | 387 | $sub=$table[$j]; |
| 388 | 388 | |
| 389 | 389 | |
| 390 | 390 | $verdict=explode('</td>', explode('manual="0">', explode('<td class="statusres text-center"', $sub)[1])[1])[0]; |
| 391 | - if ((strpos($verdict, '<strong>') !== false)) { |
|
| 391 | + if ((strpos($verdict, '<strong>')!==false)) { |
|
| 392 | 392 | $verdict=explode('</strong>', explode('<strong>', $verdict)[1])[0]; |
| 393 | 393 | } |
| 394 | 394 | |
| 395 | - if ((strpos($verdict, '(') !== false)) { |
|
| 395 | + if ((strpos($verdict, '(')!==false)) { |
|
| 396 | 396 | $verdict=explode('(', $verdict)[0]; |
| 397 | 397 | } |
| 398 | 398 | if (is_numeric(trim($verdict))) { |
@@ -413,7 +413,7 @@ discard block |
||
| 413 | 413 | $memory=substr($memory, 0, strlen($memory)-1); |
| 414 | 414 | } |
| 415 | 415 | |
| 416 | - array_push($ret, array($time*1000,$memory*1000,trim($verdict))); |
|
| 416 | + array_push($ret, array($time * 1000, $memory * 1000, trim($verdict))); |
|
| 417 | 417 | if ($num==0) { |
| 418 | 418 | return array_reverse($ret); |
| 419 | 419 | } |
@@ -422,13 +422,13 @@ discard block |
||
| 422 | 422 | } |
| 423 | 423 | } |
| 424 | 424 | |
| 425 | - private function appendPOJStatus(&$results, $judger, $first = null) |
|
| 425 | + private function appendPOJStatus(&$results, $judger, $first=null) |
|
| 426 | 426 | { |
| 427 | - if ($first !== null) $first++; |
|
| 428 | - $res = Requests::get("http://poj.org/status?user_id={$judger}&top={$first}"); |
|
| 429 | - $rows = preg_match_all('/<tr align=center><td>(\d+)<\/td><td>.*?<\/td><td>.*?<\/td><td>.*?<font color=.*?>(.*?)<\/font>.*?<\/td><td>(\d*)K?<\/td><td>(\d*)(?:MS)?<\/td>/', $res->body, $matches); |
|
| 430 | - for ($i = 0; $i < $rows; $i++) { |
|
| 431 | - $results[$matches[1][$i]] = [ |
|
| 427 | + if ($first!==null) $first++; |
|
| 428 | + $res=Requests::get("http://poj.org/status?user_id={$judger}&top={$first}"); |
|
| 429 | + $rows=preg_match_all('/<tr align=center><td>(\d+)<\/td><td>.*?<\/td><td>.*?<\/td><td>.*?<font color=.*?>(.*?)<\/font>.*?<\/td><td>(\d*)K?<\/td><td>(\d*)(?:MS)?<\/td>/', $res->body, $matches); |
|
| 430 | + for ($i=0; $i<$rows; $i++) { |
|
| 431 | + $results[$matches[1][$i]]=[ |
|
| 432 | 432 | 'verdict'=>$matches[2][$i], |
| 433 | 433 | 'memory'=>$matches[3][$i] ? $matches[3][$i] : 0, |
| 434 | 434 | 'time'=>$matches[4][$i] ? $matches[4][$i] : 0, |
@@ -118,7 +118,9 @@ discard block |
||
| 118 | 118 | $res = Requests::get('http://contest-hunter.org:83/record/'.$row['remote_id']); |
| 119 | 119 | preg_match('/<dt>状态<\/dt>[\s\S]*?<dd class=".*?">(.*?)<\/dd>/m', $res->body, $match); |
| 120 | 120 | $status = $match[1]; |
| 121 | - if (!array_key_exists($status, $contesthunter_v)) continue; |
|
| 121 | + if (!array_key_exists($status, $contesthunter_v)) { |
|
| 122 | + continue; |
|
| 123 | + } |
|
| 122 | 124 | $sub['verdict'] = $contesthunter_v[$status]; |
| 123 | 125 | $sub["score"]=$sub['verdict']=="Accepted"?1:0; |
| 124 | 126 | $sub['remote_id'] = $row['remote_id']; |
@@ -128,7 +130,9 @@ discard block |
||
| 128 | 130 | $maxtime = 0; |
| 129 | 131 | preg_match_all('/<span class="pull-right muted">(\d+) ms \/ \d+ KiB<\/span>/', $res->body, $matches); |
| 130 | 132 | foreach ($matches[1] as $time) { |
| 131 | - if ($time < $maxtime) $maxtime = $time; |
|
| 133 | + if ($time < $maxtime) { |
|
| 134 | + $maxtime = $time; |
|
| 135 | + } |
|
| 132 | 136 | } |
| 133 | 137 | $sub['time'] = $maxtime; |
| 134 | 138 | } else { |
@@ -140,12 +144,13 @@ discard block |
||
| 140 | 144 | "verdict"=>$sub['verdict'] |
| 141 | 145 | ]; |
| 142 | 146 | $this->MODEL->update_submission($row['sid'], $sub); |
| 143 | - } |
|
| 144 | - catch(Exception $e) {} |
|
| 147 | + } catch(Exception $e) {} |
|
| 145 | 148 | } else if ($row['oid'] == 4) { |
| 146 | 149 | if (!isset($poj[$row['remote_id']])) { |
| 147 | 150 | $this->appendPOJStatus($poj, $pojJudgerName, $row['remote_id']); |
| 148 | - if (!isset($poj[$row['remote_id']])) continue; |
|
| 151 | + if (!isset($poj[$row['remote_id']])) { |
|
| 152 | + continue; |
|
| 153 | + } |
|
| 149 | 154 | } |
| 150 | 155 | $status = $poj[$row['remote_id']]; |
| 151 | 156 | $sub['verdict'] = $poj_v[$status['verdict']]; |
@@ -163,7 +168,9 @@ discard block |
||
| 163 | 168 | $res = Requests::get('https://vijos.org/records/'.$row['remote_id']); |
| 164 | 169 | preg_match('/<span class="record-status--text \w*">\s*(.*?)\s*<\/span>/', $res->body, $match); |
| 165 | 170 | $status = $match[1]; |
| 166 | - if (!array_key_exists($status, $vijos_v)) continue; |
|
| 171 | + if (!array_key_exists($status, $vijos_v)) { |
|
| 172 | + continue; |
|
| 173 | + } |
|
| 167 | 174 | $sub['verdict'] = $vijos_v[$status]; |
| 168 | 175 | preg_match('/<dt>分数<\/dt>\s*<dd>(\d+)<\/dd>/', $res->body, $match); |
| 169 | 176 | $sub['score'] = $match[1]; |
@@ -172,12 +179,16 @@ discard block |
||
| 172 | 179 | $maxtime = 0; |
| 173 | 180 | preg_match_all('/<td class="col--time">(?:≥)?(\d+)ms<\/td>/', $res->body, $matches); |
| 174 | 181 | foreach ($matches as $match) { |
| 175 | - if ($match[1] > $maxtime) $maxtime = $match[1]; |
|
| 182 | + if ($match[1] > $maxtime) { |
|
| 183 | + $maxtime = $match[1]; |
|
| 184 | + } |
|
| 176 | 185 | } |
| 177 | 186 | $sub['time'] = $maxtime; |
| 178 | 187 | preg_match('/<dt>峰值内存<\/dt>\s*<dd>(?:≥)?([\d.]+) ([KM])iB<\/dd>/', $res->body, $match); |
| 179 | 188 | $memory = $match[1]; |
| 180 | - if ($match[2] == 'M') $memory *= 1024; |
|
| 189 | + if ($match[2] == 'M') { |
|
| 190 | + $memory *= 1024; |
|
| 191 | + } |
|
| 181 | 192 | $sub['memory'] = intval($memory); |
| 182 | 193 | } else { |
| 183 | 194 | $sub['memory'] = 0; |
@@ -188,8 +199,7 @@ discard block |
||
| 188 | 199 | "verdict"=>$sub['verdict'] |
| 189 | 200 | ]; |
| 190 | 201 | $this->MODEL->update_submission($row['sid'], $sub); |
| 191 | - } |
|
| 192 | - catch(Exception $e) {} |
|
| 202 | + } catch(Exception $e) {} |
|
| 193 | 203 | } |
| 194 | 204 | // if ($row['oid']=='Spoj') { |
| 195 | 205 | // if (isset($spoj_v[$sj[$j][2]])) { |
@@ -424,7 +434,9 @@ discard block |
||
| 424 | 434 | |
| 425 | 435 | private function appendPOJStatus(&$results, $judger, $first = null) |
| 426 | 436 | { |
| 427 | - if ($first !== null) $first++; |
|
| 437 | + if ($first !== null) { |
|
| 438 | + $first++; |
|
| 439 | + } |
|
| 428 | 440 | $res = Requests::get("http://poj.org/status?user_id={$judger}&top={$first}"); |
| 429 | 441 | $rows = preg_match_all('/<tr align=center><td>(\d+)<\/td><td>.*?<\/td><td>.*?<\/td><td>.*?<font color=.*?>(.*?)<\/font>.*?<\/td><td>(\d*)K?<\/td><td>(\d*)(?:MS)?<\/td>/', $res->body, $matches); |
| 430 | 442 | for ($i = 0; $i < $rows; $i++) { |