| Conditions | 31 |
| Paths | 334 |
| Total Lines | 256 |
| Code Lines | 178 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 13 | public function __construct() |
||
| 14 | { |
||
| 15 | $this->MODEL=new SubmissionModel(); |
||
| 16 | $ret=[]; |
||
| 17 | |||
| 18 | $uva_v=[ |
||
|
|
|||
| 19 | 'Wrong answer'=>"Wrong Answer", |
||
| 20 | 'Accepted'=>"Accepted", |
||
| 21 | 'Runtime error'=>"Runtime Error", |
||
| 22 | 'Time limit exceeded'=>"Time Limit Exceed", |
||
| 23 | 'Presentation error'=>"Presentation Error", |
||
| 24 | 'Submission error'=>'Submission Error', |
||
| 25 | 'Compilation error'=>"Compile Error", |
||
| 26 | 'Output Limit Exceeded'=>"Output Limit Exceeded", |
||
| 27 | ]; |
||
| 28 | |||
| 29 | $codeforces_v=[ |
||
| 30 | "COMPILATION_ERROR"=>"Compile Error", |
||
| 31 | "RUNTIME_ERROR"=> "Runtime Error", |
||
| 32 | "WRONG_ANSWER"=> "Wrong Answer", |
||
| 33 | "TIME_LIMIT_EXCEEDED"=>"Time Limit Exceed" , |
||
| 34 | "OK"=>"Accepted" , |
||
| 35 | "MEMORY_LIMIT_EXCEEDED"=>"Memory Limit Exceed", |
||
| 36 | "PRESENTATION_ERROR"=>"Presentation Error"]; |
||
| 37 | |||
| 38 | $spoj_v=[ |
||
| 39 | "compilation error"=>"Compile Error", |
||
| 40 | "runtime error"=> "Runtime Error", |
||
| 41 | "wrong answer"=> "Wrong Answer", |
||
| 42 | "time limit exceeded"=>"Time Limit Exceed", |
||
| 43 | "accepted"=>"Accepted" |
||
| 44 | ]; |
||
| 45 | |||
| 46 | $contesthunter_v=[ |
||
| 47 | '正确'=>"Accepted", |
||
| 48 | '答案错误'=>"Wrong Answer", |
||
| 49 | '超出时间限制'=>"Time Limit Exceed", |
||
| 50 | '运行时错误'=>"Runtime Error", |
||
| 51 | "超出内存限制"=>"Memory Limit Exceed", |
||
| 52 | '比较器错误'=>'Submission Error', |
||
| 53 | '超出输出限制'=>"Output Limit Exceeded", |
||
| 54 | '编译错误'=>"Compile Error", |
||
| 55 | ]; |
||
| 56 | |||
| 57 | $poj_v=[ |
||
| 58 | 'Accepted'=>"Accepted", |
||
| 59 | "Presentation Error"=>"Presentation Error", |
||
| 60 | 'Time Limit Exceeded'=>"Time Limit Exceed", |
||
| 61 | "Memory Limit Exceeded"=>"Memory Limit Exceed", |
||
| 62 | 'Wrong Answer'=>"Wrong Answer", |
||
| 63 | 'Runtime Error'=>"Runtime Error", |
||
| 64 | 'Output Limit Exceeded'=>"Output Limit Exceeded", |
||
| 65 | 'Compile Error'=>"Compile Error", |
||
| 66 | ]; |
||
| 67 | |||
| 68 | $vijos_v=[ |
||
| 69 | 'Accepted'=>"Accepted", |
||
| 70 | 'Wrong Answer'=>"Wrong Answer", |
||
| 71 | 'Time Exceeded'=>"Time Limit Exceed", |
||
| 72 | "Memory Exceeded"=>"Memory Limit Exceed", |
||
| 73 | 'Runtime Error'=>"Runtime Error", |
||
| 74 | 'Compile Error'=>"Compile Error", |
||
| 75 | 'System Error'=>"Submission Error", |
||
| 76 | 'Canceled'=>"Submission Error", |
||
| 77 | 'Unknown Error'=>"Submission Error", |
||
| 78 | 'Ignored'=>"Submission Error", |
||
| 79 | ]; |
||
| 80 | |||
| 81 | $pta_v=[ |
||
| 82 | 'ACCEPTED'=>"Accepted", |
||
| 83 | 'COMPILE_ERROR'=>"Compile Error", |
||
| 84 | 'FLOAT_POINT_EXCEPTION'=>"Runtime Error", |
||
| 85 | 'INTERNAL_ERROR'=>"Submission Error", |
||
| 86 | "MEMORY_LIMIT_EXCEEDED"=>"Memory Limit Exceed", |
||
| 87 | 'MULTIPLE_ERROR'=>"Runtime Error", |
||
| 88 | 'NON_ZERO_EXIT_CODE'=>"Runtime Error", |
||
| 89 | 'NO_ANSWER'=>"Compile Error", |
||
| 90 | 'OUTPUT_LIMIT_EXCEEDED'=>"Output Limit Exceeded", |
||
| 91 | 'OVERRIDDEN'=>"Submission Error", |
||
| 92 | 'PARTIAL_ACCEPTED'=>"Partially Accepted", |
||
| 93 | "PRESENTATION_ERROR"=>"Presentation Error", |
||
| 94 | 'RUNTIME_ERROR'=>"Runtime Error", |
||
| 95 | 'SAMPLE_ERROR'=>"Wrong Answer", |
||
| 96 | 'SEGMENTATION_FAULT'=>"Runtime Error", |
||
| 97 | 'SKIPPED'=>"Submission Error", |
||
| 98 | 'TIME_LIMIT_EXCEEDED'=>"Time Limit Exceed", |
||
| 99 | 'WRONG_ANSWER'=>"Wrong Answer", |
||
| 100 | ]; |
||
| 101 | |||
| 102 | $result=$this->MODEL->get_wating_submission(); |
||
| 103 | $judger=new JudgerModel(); |
||
| 104 | $curl = new Curl(); |
||
| 105 | |||
| 106 | $cf=$this->get_last_codeforces($this->MODEL->count_wating_submission(2)); |
||
| 107 | $poj=[]; |
||
| 108 | |||
| 109 | $pojJudgerList=$judger->list(4); |
||
| 110 | $pojJudgerName=urlencode($pojJudgerList[0]["handle"]); |
||
| 111 | if ($this->MODEL->count_wating_submission(5)) $this->appendPOJStatus($poj, $pojJudgerName); |
||
| 112 | // $uva=$this->get_last_uva($this->MODEL->count_wating_submission('Uva')); |
||
| 113 | // $uval=$this->get_last_uvalive($this->MODEL->count_wating_submission('UvaLive')); |
||
| 114 | // $sj=$this->get_last_spoj($this->MODEL->count_wating_submission('Spoj')); |
||
| 115 | |||
| 116 | $i=0; |
||
| 117 | $j=0; |
||
| 118 | $k=0; |
||
| 119 | $l=0; |
||
| 120 | foreach ($result as $row) { |
||
| 121 | if ($row['oid']==2) { |
||
| 122 | if (isset($codeforces_v[$cf[$i][2]])) { |
||
| 123 | |||
| 124 | $sub['verdict'] = $codeforces_v[$cf[$i][2]]; |
||
| 125 | $sub["score"]=$sub['verdict']=="Accepted"?1:0; |
||
| 126 | $sub['time'] = $cf[$i][0]; |
||
| 127 | $sub['memory'] = $cf[$i][1]; |
||
| 128 | $sub['remote_id'] = $cf[$i][3]; |
||
| 129 | |||
| 130 | $ret[$row['sid']] = [ |
||
| 131 | "verdict"=>$sub['verdict'] |
||
| 132 | ]; |
||
| 133 | |||
| 134 | $this->MODEL->update_submission($row['sid'], $sub); |
||
| 135 | } |
||
| 136 | $i++; |
||
| 137 | } else if ($row['oid'] == 3) { |
||
| 138 | try { |
||
| 139 | $res = Requests::get('http://contest-hunter.org:83/record/'.$row['remote_id']); |
||
| 140 | preg_match('/<dt>状态<\/dt>[\s\S]*?<dd class=".*?">(.*?)<\/dd>/m', $res->body, $match); |
||
| 141 | $status = $match[1]; |
||
| 142 | if (!array_key_exists($status, $contesthunter_v)) continue; |
||
| 143 | $sub['verdict'] = $contesthunter_v[$status]; |
||
| 144 | $sub["score"]=$sub['verdict']=="Accepted"?1:0; |
||
| 145 | $sub['remote_id'] = $row['remote_id']; |
||
| 146 | if ($sub['verdict'] != "Submission Error" && $sub['verdict'] != "Compile Error") { |
||
| 147 | preg_match('/占用内存[\s\S]*?(\d+).*?KiB/m', $res->body, $match); |
||
| 148 | $sub['memory'] = $match[1]; |
||
| 149 | $maxtime = 0; |
||
| 150 | preg_match_all('/<span class="pull-right muted">(\d+) ms \/ \d+ KiB<\/span>/', $res->body, $matches); |
||
| 151 | foreach ($matches[1] as $time) { |
||
| 152 | if ($time < $maxtime) $maxtime = $time; |
||
| 153 | } |
||
| 154 | $sub['time'] = $maxtime; |
||
| 155 | } else { |
||
| 156 | $sub['memory'] = 0; |
||
| 157 | $sub['time'] = 0; |
||
| 158 | } |
||
| 159 | |||
| 160 | $ret[$row['sid']] = [ |
||
| 161 | "verdict"=>$sub['verdict'] |
||
| 162 | ]; |
||
| 163 | $this->MODEL->update_submission($row['sid'], $sub); |
||
| 164 | } |
||
| 165 | catch(Exception $e) {} |
||
| 166 | } else if ($row['oid'] == 4) { |
||
| 167 | if (!isset($poj[$row['remote_id']])) { |
||
| 168 | $this->appendPOJStatus($poj, $pojJudgerName, $row['remote_id']); |
||
| 169 | if (!isset($poj[$row['remote_id']])) continue; |
||
| 170 | } |
||
| 171 | $status = $poj[$row['remote_id']]; |
||
| 172 | $sub['verdict'] = $poj_v[$status['verdict']]; |
||
| 173 | $sub["score"]=$sub['verdict']=="Accepted"?1:0; |
||
| 174 | $sub['time'] = $status['time']; |
||
| 175 | $sub['memory'] = $status['memory']; |
||
| 176 | $sub['remote_id'] = $row['remote_id']; |
||
| 177 | |||
| 178 | $ret[$row['sid']] = [ |
||
| 179 | "verdict"=>$sub['verdict'] |
||
| 180 | ]; |
||
| 181 | $this->MODEL->update_submission($row['sid'], $sub); |
||
| 182 | } else if ($row['oid'] == 5) { |
||
| 183 | try { |
||
| 184 | $res = Requests::get('https://vijos.org/records/'.$row['remote_id']); |
||
| 185 | preg_match('/<span class="record-status--text \w*">\s*(.*?)\s*<\/span>/', $res->body, $match); |
||
| 186 | $status = $match[1]; |
||
| 187 | if (!array_key_exists($status, $vijos_v)) continue; |
||
| 188 | $sub['verdict'] = $vijos_v[$status]; |
||
| 189 | preg_match('/<dt>分数<\/dt>\s*<dd>(\d+)<\/dd>/', $res->body, $match); |
||
| 190 | $sub['score'] = $match[1]; |
||
| 191 | if ($sub['verdict'] == "Wrong Answer" && $sub['score'] != 0) $sub['verdict'] = 'Partially Accepted'; |
||
| 192 | $sub['remote_id'] = $row['remote_id']; |
||
| 193 | if ($sub['verdict'] != "Submission Error" && $sub['verdict'] != "Compile Error") { |
||
| 194 | $maxtime = 0; |
||
| 195 | preg_match_all('/<td class="col--time">(?:≥)?(\d+)ms<\/td>/', $res->body, $matches); |
||
| 196 | foreach ($matches as $match) { |
||
| 197 | if ($match[1] > $maxtime) $maxtime = $match[1]; |
||
| 198 | } |
||
| 199 | $sub['time'] = $maxtime; |
||
| 200 | preg_match('/<dt>峰值内存<\/dt>\s*<dd>(?:≥)?([\d.]+) ([KM])iB<\/dd>/', $res->body, $match); |
||
| 201 | $memory = $match[1]; |
||
| 202 | if ($match[2] == 'M') $memory *= 1024; |
||
| 203 | $sub['memory'] = intval($memory); |
||
| 204 | } else { |
||
| 205 | $sub['memory'] = 0; |
||
| 206 | $sub['time'] = 0; |
||
| 207 | } |
||
| 208 | |||
| 209 | $ret[$row['sid']] = [ |
||
| 210 | "verdict"=>$sub['verdict'] |
||
| 211 | ]; |
||
| 212 | $this->MODEL->update_submission($row['sid'], $sub); |
||
| 213 | } |
||
| 214 | catch(Exception $e) {} |
||
| 215 | } else if ($row['oid'] == 6) { |
||
| 216 | try { |
||
| 217 | $remoteId = explode('|', $row['remote_id']); |
||
| 218 | $response = $curl->grab_page("https://pintia.cn/api/problem-sets/$remoteId[0]/submissions/".$remoteId[1], 'pta'); |
||
| 219 | $data = json_decode($response, true); |
||
| 220 | if (!isset($pta_v[$data['submission']['status']])) continue; |
||
| 221 | $sub['verdict'] = $pta_v[$data['submission']['status']]; |
||
| 222 | $sub['score'] = $data['submission']['score']; |
||
| 223 | $sub['remote_id'] = $row['remote_id']; |
||
| 224 | $sub['memory'] = $data['submission']['memory'] / 1024; |
||
| 225 | $sub['time'] = $data['submission']['time'] * 1000; |
||
| 226 | |||
| 227 | $ret[$row['sid']] = [ |
||
| 228 | "verdict"=>$sub['verdict'] |
||
| 229 | ]; |
||
| 230 | $this->MODEL->update_submission($row['sid'], $sub); |
||
| 231 | } |
||
| 232 | catch(Exception $e) {} |
||
| 233 | } |
||
| 234 | // if ($row['oid']=='Spoj') { |
||
| 235 | // if (isset($spoj_v[$sj[$j][2]])) { |
||
| 236 | // $sub['verdict']=$spoj_v[$sj[$j][2]]; |
||
| 237 | // $sub['time']=$sj[$j][0]; |
||
| 238 | // $sub['memory']=$sj[$j][1]; |
||
| 239 | // $v=$sub['verdict']; |
||
| 240 | // $ret[$row['sid']]="<div style='color:{$color[$v]};'>" .$sub['Verdict']. "</div>"; |
||
| 241 | // $this->MODEL->update_submission($row['sid'], $sub); |
||
| 242 | // } |
||
| 243 | // $j++; |
||
| 244 | // } |
||
| 245 | // if ($row['oid']=='Uva') { |
||
| 246 | // if (isset($uva_v[$uva[$k][2]])) { |
||
| 247 | // $sub['verdict']=$uva_v[$uva[$k][2]]; |
||
| 248 | // $sub['time']=$uva[$k][0]; |
||
| 249 | // $sub['memory']=$uva[$k][1]; |
||
| 250 | // $v=$sub['verdict']; |
||
| 251 | // $ret[$row['sid']]="<div style='color:{$color[$v]};'>" .$sub['Verdict']. "</div>"; |
||
| 252 | // $this->MODEL->update_submission($row['sid'], $sub); |
||
| 253 | // } |
||
| 254 | // $k++; |
||
| 255 | // } |
||
| 256 | // if ($row['oid']=='UvaLive') { |
||
| 257 | // if (isset($uva_v[$uval[$l][2]])) { |
||
| 258 | // $sub['verdict']=$uva_v[$uval[$l][2]]; |
||
| 259 | // $sub['time']=$uval[$l][0]; |
||
| 260 | // $sub['memory']=$uval[$l][1]; |
||
| 261 | // $v=$sub['verdict']; |
||
| 262 | // $ret[$row['sid']]="<div style='color:{$color[$v]};'>" .$sub['Verdict']. "</div>"; |
||
| 263 | // $this->MODEL->update_submission($row['sid'], $sub); |
||
| 264 | // } |
||
| 265 | // $l++; |
||
| 266 | // } |
||
| 267 | } |
||
| 268 | $this->ret=$ret; |
||
| 269 | } |
||
| 479 |