@@ -8,14 +8,14 @@ discard block |
||
| 8 | 8 | |
| 9 | 9 | class ContestModel extends Model |
| 10 | 10 | { |
| 11 | - protected $tableName = 'contest'; |
|
| 12 | - public $rule = ["Unknown","ACM","OI","Custom ACM","Custom OI"]; |
|
| 11 | + protected $tableName='contest'; |
|
| 12 | + public $rule=["Unknown", "ACM", "OI", "Custom ACM", "Custom OI"]; |
|
| 13 | 13 | |
| 14 | 14 | public function calcLength($a, $b) |
| 15 | 15 | { |
| 16 | 16 | $s=strtotime($b)-strtotime($a); |
| 17 | - $h=intval($s/3600); |
|
| 18 | - $m=round(($s-$h*3600)/60); |
|
| 17 | + $h=intval($s / 3600); |
|
| 18 | + $m=round(($s-$h * 3600) / 60); |
|
| 19 | 19 | if ($m==60) { |
| 20 | 20 | $h++; |
| 21 | 21 | $m=0; |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | |
| 35 | 35 | public function canViewContest($cid, $uid) |
| 36 | 36 | { |
| 37 | - $contest_detail = DB::table($this->tableName)->where([ |
|
| 37 | + $contest_detail=DB::table($this->tableName)->where([ |
|
| 38 | 38 | "cid"=>$cid |
| 39 | 39 | ])->first(); |
| 40 | 40 | |
@@ -45,19 +45,19 @@ discard block |
||
| 45 | 45 | if ($uid==0) { |
| 46 | 46 | return []; |
| 47 | 47 | } |
| 48 | - $group_info = DB::table("group_member")->where([ |
|
| 48 | + $group_info=DB::table("group_member")->where([ |
|
| 49 | 49 | "uid"=>$uid, |
| 50 | 50 | "gid"=>$contest_detail['gid'], |
| 51 | - ["role",">",0] |
|
| 51 | + ["role", ">", 0] |
|
| 52 | 52 | ])->first(); |
| 53 | 53 | return empty($group_info) ? [] : $contest_detail; |
| 54 | 54 | } |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | - public function detail($cid, $uid = 0) |
|
| 57 | + public function detail($cid, $uid=0) |
|
| 58 | 58 | { |
| 59 | - $contest_clearance = $this->judgeOutSideClearance($cid, $uid); |
|
| 60 | - $contest_detail = DB::table($this->tableName)->where([ |
|
| 59 | + $contest_clearance=$this->judgeOutSideClearance($cid, $uid); |
|
| 60 | + $contest_detail=DB::table($this->tableName)->where([ |
|
| 61 | 61 | "cid"=>$cid |
| 62 | 62 | ])->first(); |
| 63 | 63 | |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | |
| 90 | 90 | public function listByGroup($gid) |
| 91 | 91 | { |
| 92 | - $contest_list = DB::table($this->tableName)->where([ |
|
| 92 | + $contest_list=DB::table($this->tableName)->where([ |
|
| 93 | 93 | "gid"=>$gid |
| 94 | 94 | ])->orderBy('begin_time', 'desc')->get()->all(); |
| 95 | 95 | |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | |
| 114 | 114 | public function list() |
| 115 | 115 | { |
| 116 | - $contest_list = DB::table($this->tableName)->where([ |
|
| 116 | + $contest_list=DB::table($this->tableName)->where([ |
|
| 117 | 117 | "public"=>1, |
| 118 | 118 | "audit_status"=>1 |
| 119 | 119 | ])->orderBy('begin_time', 'desc')->get()->all(); |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | |
| 132 | 132 | public function featured() |
| 133 | 133 | { |
| 134 | - $featured = DB::table($this->tableName)->where([ |
|
| 134 | + $featured=DB::table($this->tableName)->where([ |
|
| 135 | 135 | "public"=>1, |
| 136 | 136 | "audit_status"=>1, |
| 137 | 137 | "featured"=>1 |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | |
| 149 | 149 | public function remainingTime($cid) |
| 150 | 150 | { |
| 151 | - $end_time = DB::table($this->tableName)->where([ |
|
| 151 | + $end_time=DB::table($this->tableName)->where([ |
|
| 152 | 152 | "cid"=>$cid |
| 153 | 153 | ])->select("end_time")->first()["end_time"]; |
| 154 | 154 | $end_time=strtotime($end_time); |
@@ -156,25 +156,25 @@ discard block |
||
| 156 | 156 | return $end_time-$cur_time; |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | - public function intToChr($index, $start = 65) |
|
| 159 | + public function intToChr($index, $start=65) |
|
| 160 | 160 | { |
| 161 | - $str = ''; |
|
| 162 | - if (floor($index / 26) > 0) { |
|
| 163 | - $str .= $this->intToChr(floor($index / 26)-1); |
|
| 161 | + $str=''; |
|
| 162 | + if (floor($index / 26)>0) { |
|
| 163 | + $str.=$this->intToChr(floor($index / 26)-1); |
|
| 164 | 164 | } |
| 165 | - return $str . chr($index % 26 + $start); |
|
| 165 | + return $str.chr($index % 26+$start); |
|
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | public function contestProblems($cid, $uid) |
| 169 | 169 | { |
| 170 | 170 | $submissionModel=new SubmissionModel(); |
| 171 | - $problemSet = DB::table("contest_problem")->join("problem", "contest_problem.pid", "=", "problem.pid")->where([ |
|
| 171 | + $problemSet=DB::table("contest_problem")->join("problem", "contest_problem.pid", "=", "problem.pid")->where([ |
|
| 172 | 172 | "cid"=>$cid |
| 173 | 173 | ])->orderBy('ncode', 'asc')->select("ncode", "alias", "contest_problem.pid as pid", "title")->get()->all(); |
| 174 | 174 | |
| 175 | 175 | foreach ($problemSet as &$p) { |
| 176 | - $frozen_time = strtotime(DB::table("contest")->where(["cid"=>$cid])->select("end_time")->first()["end_time"]); |
|
| 177 | - $prob_stat = DB::table("submission")->select( |
|
| 176 | + $frozen_time=strtotime(DB::table("contest")->where(["cid"=>$cid])->select("end_time")->first()["end_time"]); |
|
| 177 | + $prob_stat=DB::table("submission")->select( |
|
| 178 | 178 | DB::raw("count(sid) as submission_count"), |
| 179 | 179 | DB::raw("sum(verdict='accepted') as passed_count"), |
| 180 | 180 | DB::raw("sum(verdict='accepted')/count(sid)*100 as ac_rate") |
@@ -226,7 +226,7 @@ discard block |
||
| 226 | 226 | |
| 227 | 227 | public function getCustomInfo($cid) |
| 228 | 228 | { |
| 229 | - $basic_info = DB::table($this->tableName)->where([ |
|
| 229 | + $basic_info=DB::table($this->tableName)->where([ |
|
| 230 | 230 | "cid"=>$cid |
| 231 | 231 | ])->select("verified", "gid")->first(); |
| 232 | 232 | return $basic_info["verified"] ? DB::table("group")->where([ |
@@ -237,12 +237,12 @@ discard block |
||
| 237 | 237 | |
| 238 | 238 | public function formatTime($seconds) |
| 239 | 239 | { |
| 240 | - if ($seconds >3600) { |
|
| 241 | - $hours =intval($seconds/3600); |
|
| 242 | - $minutes = $seconds % 3600; |
|
| 243 | - $time = $hours.":".gmstrftime('%M:%S', $minutes); |
|
| 240 | + if ($seconds>3600) { |
|
| 241 | + $hours=intval($seconds / 3600); |
|
| 242 | + $minutes=$seconds % 3600; |
|
| 243 | + $time=$hours.":".gmstrftime('%M:%S', $minutes); |
|
| 244 | 244 | } else { |
| 245 | - $time = gmstrftime('%H:%M:%S', $seconds); |
|
| 245 | + $time=gmstrftime('%H:%M:%S', $seconds); |
|
| 246 | 246 | } |
| 247 | 247 | return $time; |
| 248 | 248 | } |
@@ -258,9 +258,9 @@ discard block |
||
| 258 | 258 | "color"=>"", |
| 259 | 259 | ]; |
| 260 | 260 | |
| 261 | - $frozen_time = strtotime(DB::table("contest")->where(["cid"=>$cid])->select("end_time")->first()["end_time"]); |
|
| 261 | + $frozen_time=strtotime(DB::table("contest")->where(["cid"=>$cid])->select("end_time")->first()["end_time"]); |
|
| 262 | 262 | |
| 263 | - $ac_record = DB::table("submission")->where([ |
|
| 263 | + $ac_record=DB::table("submission")->where([ |
|
| 264 | 264 | "cid"=>$cid, |
| 265 | 265 | "pid"=>$pid, |
| 266 | 266 | "uid"=>$uid, |
@@ -270,13 +270,13 @@ discard block |
||
| 270 | 270 | if (!empty($ac_record)) { |
| 271 | 271 | $ret["solved"]=1; |
| 272 | 272 | |
| 273 | - $ret["solved_time"]=$ac_record["submission_date"] - strtotime(DB::table($this->tableName)->where([ |
|
| 273 | + $ret["solved_time"]=$ac_record["submission_date"]-strtotime(DB::table($this->tableName)->where([ |
|
| 274 | 274 | "cid"=>$cid |
| 275 | 275 | ])->first()["begin_time"]); |
| 276 | 276 | |
| 277 | 277 | $ret["solved_time_parsed"]=$this->formatTime($ret["solved_time"]); |
| 278 | 278 | |
| 279 | - $ret["wrong_doings"] = DB::table("submission")->where([ |
|
| 279 | + $ret["wrong_doings"]=DB::table("submission")->where([ |
|
| 280 | 280 | "cid"=>$cid, |
| 281 | 281 | "pid"=>$pid, |
| 282 | 282 | "uid"=>$uid |
@@ -290,15 +290,15 @@ discard block |
||
| 290 | 290 | 'Output Limit Exceeded' |
| 291 | 291 | ])->where("submission_date", "<", $ac_record["submission_date"])->count(); |
| 292 | 292 | |
| 293 | - $others_first = DB::table("submission")->where([ |
|
| 293 | + $others_first=DB::table("submission")->where([ |
|
| 294 | 294 | "cid"=>$cid, |
| 295 | 295 | "pid"=>$pid, |
| 296 | 296 | "verdict"=>"Accepted" |
| 297 | 297 | ])->where("submission_date", "<", $ac_record["submission_date"])->count(); |
| 298 | 298 | |
| 299 | - $ret["color"]=$others_first?"wemd-green-text":"wemd-teal-text"; |
|
| 299 | + $ret["color"]=$others_first ? "wemd-green-text" : "wemd-teal-text"; |
|
| 300 | 300 | } else { |
| 301 | - $ret["wrong_doings"] = DB::table("submission")->where([ |
|
| 301 | + $ret["wrong_doings"]=DB::table("submission")->where([ |
|
| 302 | 302 | "cid"=>$cid, |
| 303 | 303 | "pid"=>$pid, |
| 304 | 304 | "uid"=>$uid |
@@ -327,26 +327,26 @@ discard block |
||
| 327 | 327 | |
| 328 | 328 | $ret=[]; |
| 329 | 329 | |
| 330 | - $contest_info = DB::table("contest")->where("cid", $cid)->first(); |
|
| 330 | + $contest_info=DB::table("contest")->where("cid", $cid)->first(); |
|
| 331 | 331 | |
| 332 | - $user_in_group = !empty(DB::table("group_member")->where([ |
|
| 332 | + $user_in_group=!empty(DB::table("group_member")->where([ |
|
| 333 | 333 | "uid" => $uid, |
| 334 | 334 | "gid" => $contest_info["gid"] |
| 335 | - ])->where("role",">",0)->first()); |
|
| 335 | + ])->where("role", ">", 0)->first()); |
|
| 336 | 336 | |
| 337 | 337 | if ($contest_info["registration"]) { |
| 338 | - $submissionUsers = DB::table("contest_participant")->where([ |
|
| 338 | + $submissionUsers=DB::table("contest_participant")->where([ |
|
| 339 | 339 | "cid"=>$cid, |
| 340 | 340 | "audit"=>1 |
| 341 | 341 | ])->select('uid')->get()->all(); |
| 342 | 342 | } else { |
| 343 | 343 | // Those who submitted are participants |
| 344 | - $submissionUsers = DB::table("submission")->where([ |
|
| 344 | + $submissionUsers=DB::table("submission")->where([ |
|
| 345 | 345 | "cid"=>$cid |
| 346 | 346 | ])->select('uid')->groupBy('uid')->get()->all(); |
| 347 | 347 | } |
| 348 | 348 | |
| 349 | - $problemSet = DB::table("contest_problem")->join("problem", "contest_problem.pid", "=", "problem.pid")->where([ |
|
| 349 | + $problemSet=DB::table("contest_problem")->join("problem", "contest_problem.pid", "=", "problem.pid")->where([ |
|
| 350 | 350 | "cid"=>$cid |
| 351 | 351 | ])->orderBy('ncode', 'asc')->select("ncode", "alias", "contest_problem.pid as pid", "title", "score", "tot_score")->get()->all(); |
| 352 | 352 | |
@@ -364,8 +364,8 @@ discard block |
||
| 364 | 364 | "solved_time_parsed"=>$prob_stat["solved_time_parsed"] |
| 365 | 365 | ]; |
| 366 | 366 | if ($prob_stat["solved"]) { |
| 367 | - $totPen+=$prob_stat["wrong_doings"]*20; |
|
| 368 | - $totPen+=$prob_stat["solved_time"]/60; |
|
| 367 | + $totPen+=$prob_stat["wrong_doings"] * 20; |
|
| 368 | + $totPen+=$prob_stat["solved_time"] / 60; |
|
| 369 | 369 | $totScore+=$prob_stat["solved"]; |
| 370 | 370 | } |
| 371 | 371 | } |
@@ -377,14 +377,14 @@ discard block |
||
| 377 | 377 | "nick_name" => $user_in_group ? DB::table("group_member")->where([ |
| 378 | 378 | "uid" => $s["uid"], |
| 379 | 379 | "gid" => $contest_info["gid"] |
| 380 | - ])->where("role",">",0)->first()["nick_name"] : "", |
|
| 380 | + ])->where("role", ">", 0)->first()["nick_name"] : "", |
|
| 381 | 381 | "score" => $totScore, |
| 382 | 382 | "penalty" => $totPen, |
| 383 | 383 | "problem_detail" => $prob_detail |
| 384 | 384 | ]; |
| 385 | 385 | } |
| 386 | 386 | |
| 387 | - usort($ret, function ($a, $b) { |
|
| 387 | + usort($ret, function($a, $b) { |
|
| 388 | 388 | if ($a["score"]==$b["score"]) { |
| 389 | 389 | if ($a["penalty"]==$b["penalty"]) { |
| 390 | 390 | return 0; |
@@ -424,19 +424,19 @@ discard block |
||
| 424 | 424 | return DB::table("contest")->where("cid", $cid)->where("end_time", "<", date("Y-m-d H:i:s"))->count(); |
| 425 | 425 | } |
| 426 | 426 | |
| 427 | - public function judgeClearance($cid, $uid = 0) |
|
| 427 | + public function judgeClearance($cid, $uid=0) |
|
| 428 | 428 | { |
| 429 | 429 | if ($uid==0) { |
| 430 | 430 | return 0; |
| 431 | 431 | } |
| 432 | - $contest_started = DB::table("contest")->where("cid", $cid)->where("begin_time", "<", date("Y-m-d H:i:s"))->count(); |
|
| 433 | - $contest_ended = DB::table("contest")->where("cid", $cid)->where("end_time", "<", date("Y-m-d H:i:s"))->count(); |
|
| 432 | + $contest_started=DB::table("contest")->where("cid", $cid)->where("begin_time", "<", date("Y-m-d H:i:s"))->count(); |
|
| 433 | + $contest_ended=DB::table("contest")->where("cid", $cid)->where("end_time", "<", date("Y-m-d H:i:s"))->count(); |
|
| 434 | 434 | if ($contest_started) { |
| 435 | 435 | // judge if qualified |
| 436 | 436 | // return 1 if view access, can only view |
| 437 | 437 | // return 2 if participant access, can submit code |
| 438 | 438 | // return 3 if admin access, can create announcements |
| 439 | - $contest_info = DB::table("contest")->where("cid", $cid)->first(); |
|
| 439 | + $contest_info=DB::table("contest")->where("cid", $cid)->first(); |
|
| 440 | 440 | if ($contest_info["registration"]) { |
| 441 | 441 | // check if uid in registration, temp return 3 |
| 442 | 442 | return 2; |
@@ -456,9 +456,9 @@ discard block |
||
| 456 | 456 | } |
| 457 | 457 | } |
| 458 | 458 | |
| 459 | - public function judgeOutsideClearance($cid, $uid = 0) |
|
| 459 | + public function judgeOutsideClearance($cid, $uid=0) |
|
| 460 | 460 | { |
| 461 | - $contest_info = DB::table("contest")->where("cid", $cid)->first(); |
|
| 461 | + $contest_info=DB::table("contest")->where("cid", $cid)->first(); |
|
| 462 | 462 | if (empty($contest_info)) { |
| 463 | 463 | return 0; |
| 464 | 464 | } |
@@ -482,24 +482,24 @@ discard block |
||
| 482 | 482 | |
| 483 | 483 | public function arrangeContest($gid, $config, $problems) |
| 484 | 484 | { |
| 485 | - DB::transaction(function () use ($gid, $config, $problems) { |
|
| 486 | - $cid = DB::table($this->tableName)->insertGetId([ |
|
| 485 | + DB::transaction(function() use ($gid, $config, $problems) { |
|
| 486 | + $cid=DB::table($this->tableName)->insertGetId([ |
|
| 487 | 487 | "gid"=>$gid, |
| 488 | 488 | "name"=>$config["name"], |
| 489 | - "verified"=>0, //todo |
|
| 489 | + "verified"=>0, //todo |
|
| 490 | 490 | "rated"=>0, |
| 491 | 491 | "anticheated"=>0, |
| 492 | 492 | "featured"=>0, |
| 493 | 493 | "description"=>$config["description"], |
| 494 | - "rule"=>1, //todo |
|
| 494 | + "rule"=>1, //todo |
|
| 495 | 495 | "begin_time"=>$config["begin_time"], |
| 496 | 496 | "end_time"=>$config["end_time"], |
| 497 | - "public"=>0, //todo |
|
| 498 | - "registration"=>0, //todo |
|
| 499 | - "registration_due"=>null, //todo |
|
| 500 | - "registant_type"=>0, //todo |
|
| 501 | - "froze_length"=>0, //todo |
|
| 502 | - "status_visibility"=>3, //todo |
|
| 497 | + "public"=>0, //todo |
|
| 498 | + "registration"=>0, //todo |
|
| 499 | + "registration_due"=>null, //todo |
|
| 500 | + "registant_type"=>0, //todo |
|
| 501 | + "froze_length"=>0, //todo |
|
| 502 | + "status_visibility"=>3, //todo |
|
| 503 | 503 | "create_time"=>date("Y-m-d H:i:s"), |
| 504 | 504 | "audit_status"=>1 //todo |
| 505 | 505 | ]); |
@@ -39,9 +39,9 @@ discard block |
||
| 39 | 39 | $this->post_data=$all_data; |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | - public function submitJudger($submitURL,$data) |
|
| 42 | + public function submitJudger($submitURL, $data) |
|
| 43 | 43 | { |
| 44 | - $judgeClient = new JudgeClient($data["token"], $submitURL); |
|
| 44 | + $judgeClient=new JudgeClient($data["token"], $submitURL); |
|
| 45 | 45 | return $judgeClient->judge($data["solution"], $data["language"], $data["test_case_id"], [ |
| 46 | 46 | 'output' => true, |
| 47 | 47 | 'max_cpu_time'=>$data['max_cpu_time'], |
@@ -56,10 +56,10 @@ discard block |
||
| 56 | 56 | 'coid' => 'required|integer', |
| 57 | 57 | 'solution' => 'required', |
| 58 | 58 | ])->validate(); |
| 59 | - $judgerModel = new JudgerModel(); |
|
| 60 | - $problemModel = new ProblemModel(); |
|
| 61 | - $contestModel = new ContestModel(); |
|
| 62 | - $bestServer = $judgerModel->server(1); |
|
| 59 | + $judgerModel=new JudgerModel(); |
|
| 60 | + $problemModel=new ProblemModel(); |
|
| 61 | + $contestModel=new ContestModel(); |
|
| 62 | + $bestServer=$judgerModel->server(1); |
|
| 63 | 63 | if (is_null($bestServer)) { |
| 64 | 64 | return ResponseModel::err(6001); |
| 65 | 65 | } |
@@ -68,12 +68,12 @@ discard block |
||
| 68 | 68 | $this->sub['pid']=$this->post_data["pid"]; |
| 69 | 69 | $this->sub['coid']=$this->post_data["coid"]; |
| 70 | 70 | $probBasic=$problemModel->basic($this->post_data["pid"]); |
| 71 | - $submitURL="http://" . $bestServer["host"] . ":" . $bestServer["port"]; |
|
| 72 | - $submit_data = [ |
|
| 71 | + $submitURL="http://".$bestServer["host"].":".$bestServer["port"]; |
|
| 72 | + $submit_data=[ |
|
| 73 | 73 | "solution" => $this->post_data["solution"], |
| 74 | 74 | "language" => $this->post_data["lang"], |
| 75 | 75 | "max_cpu_time" => $probBasic["time_limit"], |
| 76 | - "max_memory" => $probBasic["memory_limit"]*1024, |
|
| 76 | + "max_memory" => $probBasic["memory_limit"] * 1024, |
|
| 77 | 77 | "test_case_id" => $probBasic["pcode"], |
| 78 | 78 | "token" => $bestServer["token"] |
| 79 | 79 | ]; |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | |
| 82 | 82 | if (isset($this->post_data["contest"])) { |
| 83 | 83 | $this->sub['cid']=$this->post_data["contest"]; |
| 84 | - if($contestModel->rule($this->sub['cid'])==2) { |
|
| 84 | + if ($contestModel->rule($this->sub['cid'])==2) { |
|
| 85 | 85 | // OI Mode |
| 86 | 86 | if (!is_null($temp["err"])) { |
| 87 | 87 | $this->sub['verdict']="Compile Error"; |