| Conditions | 25 |
| Paths | 104 |
| Total Lines | 216 |
| Code Lines | 142 |
| 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 | $result=$this->MODEL->get_wating_submission(); |
||
| 82 | $judger=new JudgerModel(); |
||
| 83 | |||
| 84 | $cf=$this->get_last_codeforces($this->MODEL->count_wating_submission(2)); |
||
| 85 | $poj=[]; |
||
| 86 | |||
| 87 | $pojJudgerList=$judger->list(4); |
||
| 88 | $pojJudgerName=urlencode($pojJudgerList[0]["handle"]); |
||
| 89 | $this->appendPOJStatus($poj, $pojJudgerName); |
||
| 90 | // $uva=$this->get_last_uva($this->MODEL->count_wating_submission('Uva')); |
||
| 91 | // $uval=$this->get_last_uvalive($this->MODEL->count_wating_submission('UvaLive')); |
||
| 92 | // $sj=$this->get_last_spoj($this->MODEL->count_wating_submission('Spoj')); |
||
| 93 | |||
| 94 | $i=0; |
||
| 95 | $j=0; |
||
| 96 | $k=0; |
||
| 97 | $l=0; |
||
| 98 | |||
| 99 | foreach ($result as $row) { |
||
| 100 | if ($row['oid']==2) { |
||
| 101 | if (isset($codeforces_v[$cf[$i][2]])) { |
||
| 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]; |
||
| 108 | |||
| 109 | $ret[$row['sid']] = [ |
||
| 110 | "verdict"=>$sub['verdict'] |
||
| 111 | ]; |
||
| 112 | |||
| 113 | $this->MODEL->update_submission($row['sid'], $sub); |
||
| 114 | } |
||
| 115 | $i++; |
||
| 116 | } else if ($row['oid'] == 3) { |
||
| 117 | try { |
||
| 118 | $res = Requests::get('http://contest-hunter.org:83/record/'.$row['remote_id']); |
||
| 119 | preg_match('/<dt>状态<\/dt>[\s\S]*?<dd class=".*?">(.*?)<\/dd>/m', $res->body, $match); |
||
| 120 | $status = $match[1]; |
||
| 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") { |
||
| 126 | preg_match('/占用内存[\s\S]*?(\d+).*?KiB/m', $res->body, $match); |
||
| 127 | $sub['memory'] = $match[1]; |
||
| 128 | $maxtime = 0; |
||
| 129 | preg_match_all('/<span class="pull-right muted">(\d+) ms \/ \d+ KiB<\/span>/', $res->body, $matches); |
||
| 130 | foreach ($matches[1] as $time) { |
||
| 131 | if ($time < $maxtime) $maxtime = $time; |
||
| 132 | } |
||
| 133 | $sub['time'] = $maxtime; |
||
| 134 | } else { |
||
| 135 | $sub['memory'] = 0; |
||
| 136 | $sub['time'] = 0; |
||
| 137 | } |
||
| 138 | |||
| 139 | $ret[$row['sid']] = [ |
||
| 140 | "verdict"=>$sub['verdict'] |
||
| 141 | ]; |
||
| 142 | $this->MODEL->update_submission($row['sid'], $sub); |
||
| 143 | } |
||
| 144 | catch(Exception $e) {} |
||
| 145 | } else if ($row['oid'] == 4) { |
||
| 146 | if (!isset($poj[$row['remote_id']])) { |
||
| 147 | $this->appendPOJStatus($poj, $pojJudgerName, $row['remote_id']); |
||
| 148 | if (!isset($poj[$row['remote_id']])) continue; |
||
| 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']] = [ |
||
| 158 | "verdict"=>$sub['verdict'] |
||
| 159 | ]; |
||
| 160 | $this->MODEL->update_submission($row['sid'], $sub); |
||
| 161 | } else if ($row['oid'] == 5) { |
||
| 162 | try { |
||
| 163 | $res = Requests::get('https://vijos.org/records/'.$row['remote_id']); |
||
| 164 | preg_match('/<span class="record-status--text \w*">\s*(.*?)\s*<\/span>/', $res->body, $match); |
||
| 165 | $status = $match[1]; |
||
| 166 | if (!array_key_exists($status, $vijos_v)) continue; |
||
| 167 | $sub['verdict'] = $vijos_v[$status]; |
||
| 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; |
||
| 173 | preg_match_all('/<td class="col--time">(?:≥)?(\d+)ms<\/td>/', $res->body, $matches); |
||
| 174 | foreach ($matches as $match) { |
||
| 175 | if ($match[1] > $maxtime) $maxtime = $match[1]; |
||
| 176 | } |
||
| 177 | $sub['time'] = $maxtime; |
||
| 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); |
||
| 182 | } else { |
||
| 183 | $sub['memory'] = 0; |
||
| 184 | $sub['time'] = 0; |
||
| 185 | } |
||
| 186 | |||
| 187 | $ret[$row['sid']] = [ |
||
| 188 | "verdict"=>$sub['verdict'] |
||
| 189 | ]; |
||
| 190 | $this->MODEL->update_submission($row['sid'], $sub); |
||
| 191 | } |
||
| 192 | catch(Exception $e) {} |
||
| 193 | } |
||
| 194 | // if ($row['oid']=='Spoj') { |
||
| 195 | // if (isset($spoj_v[$sj[$j][2]])) { |
||
| 196 | // $sub['verdict']=$spoj_v[$sj[$j][2]]; |
||
| 197 | // $sub['time']=$sj[$j][0]; |
||
| 198 | // $sub['memory']=$sj[$j][1]; |
||
| 199 | // $v=$sub['verdict']; |
||
| 200 | // $ret[$row['sid']]="<div style='color:{$color[$v]};'>" .$sub['Verdict']. "</div>"; |
||
| 201 | // $this->MODEL->update_submission($row['sid'], $sub); |
||
| 202 | // } |
||
| 203 | // $j++; |
||
| 204 | // } |
||
| 205 | // if ($row['oid']=='Uva') { |
||
| 206 | // if (isset($uva_v[$uva[$k][2]])) { |
||
| 207 | // $sub['verdict']=$uva_v[$uva[$k][2]]; |
||
| 208 | // $sub['time']=$uva[$k][0]; |
||
| 209 | // $sub['memory']=$uva[$k][1]; |
||
| 210 | // $v=$sub['verdict']; |
||
| 211 | // $ret[$row['sid']]="<div style='color:{$color[$v]};'>" .$sub['Verdict']. "</div>"; |
||
| 212 | // $this->MODEL->update_submission($row['sid'], $sub); |
||
| 213 | // } |
||
| 214 | // $k++; |
||
| 215 | // } |
||
| 216 | // if ($row['oid']=='UvaLive') { |
||
| 217 | // if (isset($uva_v[$uval[$l][2]])) { |
||
| 218 | // $sub['verdict']=$uva_v[$uval[$l][2]]; |
||
| 219 | // $sub['time']=$uval[$l][0]; |
||
| 220 | // $sub['memory']=$uval[$l][1]; |
||
| 221 | // $v=$sub['verdict']; |
||
| 222 | // $ret[$row['sid']]="<div style='color:{$color[$v]};'>" .$sub['Verdict']. "</div>"; |
||
| 223 | // $this->MODEL->update_submission($row['sid'], $sub); |
||
| 224 | // } |
||
| 225 | // $l++; |
||
| 226 | // } |
||
| 227 | } |
||
| 228 | $this->ret=$ret; |
||
| 229 | } |
||
| 439 |