@@ -39,8 +39,8 @@ discard block |
||
| 39 | 39 | //writing database |
| 40 | 40 | $this->transactionDB(); |
| 41 | 41 | |
| 42 | - }catch(Throwable $e){ |
|
| 43 | - if ($e->getMessage()!==""){ |
|
| 42 | + } catch (Throwable $e) { |
|
| 43 | + if ($e->getMessage()!=="") { |
|
| 44 | 44 | $this->command->line("\n <bg=red;fg=white> {$e->getMessage()} </>\n"); |
| 45 | 45 | } |
| 46 | 46 | } |
@@ -59,12 +59,12 @@ discard block |
||
| 59 | 59 | public function __construct($class) |
| 60 | 60 | { |
| 61 | 61 | $this->command=$class; |
| 62 | - $this->versionParser = new VersionConstraintParser(); |
|
| 62 | + $this->versionParser=new VersionConstraintParser(); |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | private function parseVersion() |
| 66 | 66 | { |
| 67 | - if(empty($this->babelConfig)){ |
|
| 67 | + if (empty($this->babelConfig)) { |
|
| 68 | 68 | throw new Exception('Missing babel.json Config file.'); |
| 69 | 69 | } |
| 70 | 70 | |
@@ -134,7 +134,7 @@ discard block |
||
| 134 | 134 | |
| 135 | 135 | DB::commit(); |
| 136 | 136 | |
| 137 | - }catch(Throwable $e){ |
|
| 137 | + } catch (Throwable $e) { |
|
| 138 | 138 | DB::rollback(); |
| 139 | 139 | if ($e->getMessage()!=="") { |
| 140 | 140 | $this->command->line("\n <bg=red;fg=white> {$e->getMessage()} </>\n"); |
@@ -413,7 +413,7 @@ discard block |
||
| 413 | 413 | ->where(['verdict'=>'Waiting']) |
| 414 | 414 | ->get() |
| 415 | 415 | ->all(); |
| 416 | - foreach($ret as &$r){ |
|
| 416 | + foreach ($ret as &$r) { |
|
| 417 | 417 | $r["ocode"]=DB::table("oj")->where(["oid"=>$r["oid"]])->first()["ocode"]; |
| 418 | 418 | } |
| 419 | 419 | return $ret; |
@@ -431,15 +431,15 @@ discard block |
||
| 431 | 431 | if (isset($sub['verdict'])) { |
| 432 | 432 | $sub["color"]=$this->colorScheme[$sub['verdict']]; |
| 433 | 433 | } |
| 434 | - $result = DB::table($this->tableName)->where(['sid'=>$sid])->update($sub); |
|
| 435 | - $contestModel = new ContestModel(); |
|
| 436 | - $submission_info = DB::table($this->tableName) -> where(['sid'=>$sid]) -> get() -> first(); |
|
| 437 | - if ($result==1 && $submission_info['cid'] && $contestModel->isContestRunning($submission_info['cid'])){ |
|
| 438 | - $sub['pid'] = $submission_info['pid']; |
|
| 439 | - $sub['uid'] = $submission_info['uid']; |
|
| 440 | - $sub['cid'] = $submission_info['cid']; |
|
| 441 | - $sub['sid'] = $sid; |
|
| 442 | - $contestModel->updateContestRankTable($submission_info['cid'],$sub); |
|
| 434 | + $result=DB::table($this->tableName)->where(['sid'=>$sid])->update($sub); |
|
| 435 | + $contestModel=new ContestModel(); |
|
| 436 | + $submission_info=DB::table($this->tableName) -> where(['sid'=>$sid]) -> get() -> first(); |
|
| 437 | + if ($result==1 && $submission_info['cid'] && $contestModel->isContestRunning($submission_info['cid'])) { |
|
| 438 | + $sub['pid']=$submission_info['pid']; |
|
| 439 | + $sub['uid']=$submission_info['uid']; |
|
| 440 | + $sub['cid']=$submission_info['cid']; |
|
| 441 | + $sub['sid']=$sid; |
|
| 442 | + $contestModel->updateContestRankTable($submission_info['cid'], $sub); |
|
| 443 | 443 | } |
| 444 | 444 | return $result; |
| 445 | 445 | } |
@@ -510,15 +510,15 @@ discard block |
||
| 510 | 510 | 'desc' |
| 511 | 511 | ); |
| 512 | 512 | |
| 513 | - if($filter["pcode"]){ |
|
| 513 | + if ($filter["pcode"]) { |
|
| 514 | 514 | $paginator=$paginator->where(["pcode"=>$filter["pcode"]]); |
| 515 | 515 | } |
| 516 | 516 | |
| 517 | - if($filter["result"]){ |
|
| 517 | + if ($filter["result"]) { |
|
| 518 | 518 | $paginator=$paginator->where(["verdict"=>$filter["result"]]); |
| 519 | 519 | } |
| 520 | 520 | |
| 521 | - if($filter["account"]){ |
|
| 521 | + if ($filter["account"]) { |
|
| 522 | 522 | $paginator=$paginator->where(["name"=>$filter["account"]]); |
| 523 | 523 | } |
| 524 | 524 | |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | */ |
| 22 | 22 | public function settings($gcode) |
| 23 | 23 | { |
| 24 | - return Redirect::route('group.settings.general', ['gcode' => $gcode]);; |
|
| 24 | + return Redirect::route('group.settings.general', ['gcode' => $gcode]); ; |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | /** |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | */ |
| 32 | 32 | public function settingsReturn($gcode) |
| 33 | 33 | { |
| 34 | - return Redirect::route('group.detail', ['gcode' => $gcode]);; |
|
| 34 | + return Redirect::route('group.detail', ['gcode' => $gcode]); ; |
|
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | /** |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | { |
| 44 | 44 | $groupModel=new GroupModel(); |
| 45 | 45 | $basic_info=$groupModel->details($gcode); |
| 46 | - if(empty($basic_info)) return Redirect::route('group.index'); |
|
| 46 | + if (empty($basic_info)) return Redirect::route('group.index'); |
|
| 47 | 47 | $clearance=$groupModel->judgeClearance($basic_info["gid"], Auth::user()->id); |
| 48 | 48 | $member_list=$groupModel->userList($basic_info["gid"]); |
| 49 | 49 | return view('group.settings.general', [ |
@@ -61,10 +61,10 @@ discard block |
||
| 61 | 61 | * |
| 62 | 62 | * @return Response |
| 63 | 63 | */ |
| 64 | - public function problems($gcode){ |
|
| 65 | - $groupModel = new GroupModel(); |
|
| 66 | - $group_info = $groupModel->details($gcode); |
|
| 67 | - $problems = $groupModel->problems($group_info['gid']); |
|
| 64 | + public function problems($gcode) { |
|
| 65 | + $groupModel=new GroupModel(); |
|
| 66 | + $group_info=$groupModel->details($gcode); |
|
| 67 | + $problems=$groupModel->problems($group_info['gid']); |
|
| 68 | 68 | $basic_info=$groupModel->details($gcode); |
| 69 | 69 | return view('group.settings.problems', [ |
| 70 | 70 | 'page_title'=>"Group Problems", |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | { |
| 86 | 86 | $groupModel=new GroupModel(); |
| 87 | 87 | $basic_info=$groupModel->details($gcode); |
| 88 | - if(empty($basic_info)) return Redirect::route('group.index'); |
|
| 88 | + if (empty($basic_info)) return Redirect::route('group.index'); |
|
| 89 | 89 | return view('group.settings.danger', [ |
| 90 | 90 | 'page_title'=>"Group Setting danger", |
| 91 | 91 | 'site_title'=>config("app.name"), |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | $groupModel=new GroupModel(); |
| 105 | 105 | $contestModel=new ContestModel(); |
| 106 | 106 | $basic_info=$groupModel->details($gcode); |
| 107 | - if(empty($basic_info)) return Redirect::route('group.index'); |
|
| 107 | + if (empty($basic_info)) return Redirect::route('group.index'); |
|
| 108 | 108 | $clearance=$groupModel->judgeClearance($basic_info["gid"], Auth::user()->id); |
| 109 | 109 | $member_list=$groupModel->userList($basic_info["gid"]); |
| 110 | 110 | $group_notice=$groupModel->detailNotice($gcode); |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | $groupModel=new GroupModel(); |
| 125 | 125 | $contestModel=new ContestModel(); |
| 126 | 126 | $basic_info=$groupModel->details($gcode); |
| 127 | - if(empty($basic_info)) return Redirect::route('group.index'); |
|
| 127 | + if (empty($basic_info)) return Redirect::route('group.index'); |
|
| 128 | 128 | $clearance=$groupModel->judgeClearance($basic_info["gid"], Auth::user()->id); |
| 129 | 129 | $contest_list=$contestModel->listForSetting($basic_info["gid"]); |
| 130 | 130 | $member_list=$groupModel->userList($basic_info["gid"]); |
@@ -48,11 +48,11 @@ discard block |
||
| 48 | 48 | |
| 49 | 49 | $groupModel=new GroupModel(); |
| 50 | 50 | $clearance=$groupModel->judgeClearance($all_data["gid"], Auth::user()->id); |
| 51 | - if ($clearance < 2) { |
|
| 51 | + if ($clearance<2) { |
|
| 52 | 52 | return ResponseModel::err(7002); |
| 53 | 53 | } |
| 54 | - $tags = $groupModel->problemTags($all_data['gid'],$all_data['pid']); |
|
| 55 | - if(in_array($all_data['tag'],$tags)){ |
|
| 54 | + $tags=$groupModel->problemTags($all_data['gid'], $all_data['pid']); |
|
| 55 | + if (in_array($all_data['tag'], $tags)) { |
|
| 56 | 56 | return ResponseModel::err(7007); |
| 57 | 57 | } |
| 58 | 58 | |
@@ -84,9 +84,9 @@ discard block |
||
| 84 | 84 | $request->validate([ |
| 85 | 85 | 'gid' => 'required|string', |
| 86 | 86 | ]); |
| 87 | - $gid = $request->input('gid'); |
|
| 87 | + $gid=$request->input('gid'); |
|
| 88 | 88 | $groupModel=new GroupModel(); |
| 89 | - if($groupModel->judgeClearance($gid,Auth::user()->id) < 2) { |
|
| 89 | + if ($groupModel->judgeClearance($gid, Auth::user()->id)<2) { |
|
| 90 | 90 | return ResponseModel::err(2001); |
| 91 | 91 | } |
| 92 | 92 | $groupModel->refreshElo($gid); |
@@ -178,9 +178,9 @@ discard block |
||
| 178 | 178 | |
| 179 | 179 | private function inteliAudit($uid, $content) |
| 180 | 180 | { |
| 181 | - if (strpos($content, '```')!==false){ |
|
| 181 | + if (strpos($content, '```')!==false) { |
|
| 182 | 182 | $userSolutionHistory=DB::table("problem_solution")->where(['uid'=>$uid])->orderByDesc('updated_at')->first(); |
| 183 | - if (!empty($userSolutionHistory) && $userSolutionHistory["audit"]==1){ |
|
| 183 | + if (!empty($userSolutionHistory) && $userSolutionHistory["audit"]==1) { |
|
| 184 | 184 | return 1; |
| 185 | 185 | } |
| 186 | 186 | } |
@@ -430,7 +430,7 @@ discard block |
||
| 430 | 430 | |
| 431 | 431 | if (!empty($data["sample"])) { |
| 432 | 432 | foreach ($data["sample"] as $d) { |
| 433 | - if(!isset($d['sample_note'])) $d['sample_note']=null; |
|
| 433 | + if (!isset($d['sample_note'])) $d['sample_note']=null; |
|
| 434 | 434 | DB::table("problem_sample")->insert([ |
| 435 | 435 | 'pid'=>$pid, |
| 436 | 436 | 'sample_input'=>$d['sample_input'], |
@@ -476,7 +476,7 @@ discard block |
||
| 476 | 476 | |
| 477 | 477 | if (!empty($data["sample"])) { |
| 478 | 478 | foreach ($data["sample"] as $d) { |
| 479 | - if(!isset($d['sample_note'])) $d['sample_note']=null; |
|
| 479 | + if (!isset($d['sample_note'])) $d['sample_note']=null; |
|
| 480 | 480 | DB::table("problem_sample")->insert([ |
| 481 | 481 | 'pid'=>$pid, |
| 482 | 482 | 'sample_input'=>$d['sample_input'], |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | "oid"=>$oid, |
| 60 | 60 | "available"=>1, |
| 61 | 61 | "status"=>0 |
| 62 | - ])->orderBy('usage','desc')->get()->first(); |
|
| 62 | + ])->orderBy('usage', 'desc')->get()->first(); |
|
| 63 | 63 | |
| 64 | 64 | return $serverList; |
| 65 | 65 | } |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | { |
| 69 | 69 | $serverList=DB::table("judge_server")->where(["oid"=>$oid])->get()->all(); |
| 70 | 70 | foreach ($serverList as &$server) { |
| 71 | - $server["status_parsed"]=is_null($server["status"])?self::$status["-1"]:self::$status[$server["status"]]; |
|
| 71 | + $server["status_parsed"]=is_null($server["status"]) ?self::$status["-1"] : self::$status[$server["status"]]; |
|
| 72 | 72 | } |
| 73 | 73 | return $serverList; |
| 74 | 74 | } |
@@ -63,20 +63,20 @@ discard block |
||
| 63 | 63 | } |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | -if (! function_exists('babel_path')) { |
|
| 66 | +if (!function_exists('babel_path')) { |
|
| 67 | 67 | /** |
| 68 | 68 | * Get the path to the application folder. |
| 69 | 69 | * |
| 70 | 70 | * @param string $path |
| 71 | 71 | * @return string |
| 72 | 72 | */ |
| 73 | - function babel_path($path = '') |
|
| 73 | + function babel_path($path='') |
|
| 74 | 74 | { |
| 75 | 75 | return app('path').DIRECTORY_SEPARATOR.'Babel'.($path ? DIRECTORY_SEPARATOR.$path : $path); |
| 76 | 76 | } |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | -if (! function_exists('glob_recursive')) { |
|
| 79 | +if (!function_exists('glob_recursive')) { |
|
| 80 | 80 | /** |
| 81 | 81 | * Find pathnames matching a pattern recursively. |
| 82 | 82 | * |
@@ -84,11 +84,11 @@ discard block |
||
| 84 | 84 | * @param int $flags Valid flags: GLOB_MARK |
| 85 | 85 | * @return array|false an array containing the matched files/directories, an empty array if no file matched or false on error. |
| 86 | 86 | */ |
| 87 | - function glob_recursive($pattern, $flags = 0) |
|
| 87 | + function glob_recursive($pattern, $flags=0) |
|
| 88 | 88 | { |
| 89 | - $files = glob($pattern, $flags); |
|
| 90 | - foreach (glob(dirname($pattern).'/*', GLOB_ONLYDIR|GLOB_NOSORT) as $dir) { |
|
| 91 | - $files = array_merge($files, glob_recursive($dir.'/'.basename($pattern), $flags)); |
|
| 89 | + $files=glob($pattern, $flags); |
|
| 90 | + foreach (glob(dirname($pattern).'/*', GLOB_ONLYDIR | GLOB_NOSORT) as $dir) { |
|
| 91 | + $files=array_merge($files, glob_recursive($dir.'/'.basename($pattern), $flags)); |
|
| 92 | 92 | } |
| 93 | 93 | return $files; |
| 94 | 94 | } |
@@ -122,8 +122,8 @@ discard block |
||
| 122 | 122 | function delFile($dirName) |
| 123 | 123 | { |
| 124 | 124 | if (file_exists($dirName) && $handle=opendir($dirName)) { |
| 125 | - while (false!==($item = readdir($handle))) { |
|
| 126 | - if ($item!= "." && $item != "..") { |
|
| 125 | + while (false!==($item=readdir($handle))) { |
|
| 126 | + if ($item!="." && $item!="..") { |
|
| 127 | 127 | if (file_exists($dirName.'/'.$item) && is_dir($dirName.'/'.$item)) { |
| 128 | 128 | delFile($dirName.'/'.$item); |
| 129 | 129 | } else { |
@@ -141,6 +141,6 @@ discard block |
||
| 141 | 141 | if (!function_exists('convertMarkdownToHtml')) { |
| 142 | 142 | function convertMarkdownToHtml($md) |
| 143 | 143 | { |
| 144 | - return is_string($md)?Markdown::convertToHtml($md):''; |
|
| 144 | + return is_string($md) ?Markdown::convertToHtml($md) : ''; |
|
| 145 | 145 | } |
| 146 | 146 | } |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | |
| 37 | 37 | $all_data=$request->all(); |
| 38 | 38 | |
| 39 | - if(($all_data['public'] ?? 0) && ($all_data['practice'] ?? 0)){ |
|
| 39 | + if (($all_data['public'] ?? 0) && ($all_data['practice'] ?? 0)) { |
|
| 40 | 40 | return ResponseModel::err(4007); |
| 41 | 41 | } |
| 42 | 42 | |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | return ResponseModel::err(1003); |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | - $cid = $contestModel->arrangeContest($all_data["gid"], [ |
|
| 70 | + $cid=$contestModel->arrangeContest($all_data["gid"], [ |
|
| 71 | 71 | "assign_uid"=>Auth::user()->id, |
| 72 | 72 | "name"=>$all_data["name"], |
| 73 | 73 | "description"=>$all_data["description"], |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | "public"=>$all_data["public"] ?? 0, |
| 78 | 78 | ], $problemSet); |
| 79 | 79 | |
| 80 | - return ResponseModel::success(200,'Successful!',$cid); |
|
| 80 | + return ResponseModel::success(200, 'Successful!', $cid); |
|
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | public function changeGroupName(Request $request) |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | |
| 92 | 92 | $groupModel=new GroupModel(); |
| 93 | 93 | $clearance=$groupModel->judgeClearance($all_data["gid"], Auth::user()->id); |
| 94 | - if ($clearance < 2){ |
|
| 94 | + if ($clearance<2) { |
|
| 95 | 95 | return ResponseModel::err(2001); |
| 96 | 96 | } |
| 97 | 97 | |
@@ -110,11 +110,11 @@ discard block |
||
| 110 | 110 | |
| 111 | 111 | $groupModel=new GroupModel(); |
| 112 | 112 | $clearance=$groupModel->judgeClearance($all_data["gid"], Auth::user()->id); |
| 113 | - if ($clearance < 2){ |
|
| 113 | + if ($clearance<2) { |
|
| 114 | 114 | return ResponseModel::err(2001); |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | - if ($all_data["join_policy"] < 1 || $all_data["join_policy"] > 3){ |
|
| 117 | + if ($all_data["join_policy"]<1 || $all_data["join_policy"]>3) { |
|
| 118 | 118 | return ResponseModel::err(1007); |
| 119 | 119 | } |
| 120 | 120 | |
@@ -128,7 +128,7 @@ discard block |
||
| 128 | 128 | 'gid' => 'required|integer', |
| 129 | 129 | ]); |
| 130 | 130 | |
| 131 | - $all_data = $request->all(); |
|
| 131 | + $all_data=$request->all(); |
|
| 132 | 132 | |
| 133 | 133 | if (!empty($request->file('img')) && $request->file('img')->isValid()) { |
| 134 | 134 | $extension=$request->file('img')->extension(); |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | |
| 141 | 141 | $groupModel=new GroupModel(); |
| 142 | 142 | $clearance=$groupModel->judgeClearance($all_data["gid"], Auth::user()->id); |
| 143 | - if ($clearance < 2){ |
|
| 143 | + if ($clearance<2) { |
|
| 144 | 144 | return ResponseModel::err(2001); |
| 145 | 145 | } |
| 146 | 146 | |
@@ -178,18 +178,18 @@ discard block |
||
| 178 | 178 | $clearance=$groupModel->judgeClearance($all_data["gid"], Auth::user()->id); |
| 179 | 179 | $target_clearance=$groupModel->judgeClearance($all_data["gid"], $all_data['uid']); |
| 180 | 180 | |
| 181 | - if($target_clearance == -3){ |
|
| 181 | + if ($target_clearance==-3) { |
|
| 182 | 182 | return ResponseModel::err(7004); |
| 183 | 183 | } |
| 184 | 184 | |
| 185 | - if($target_clearance >= $clearance || $clearance < 2 || $all_data['permission'] >= $clearance){ |
|
| 185 | + if ($target_clearance>=$clearance || $clearance<2 || $all_data['permission']>=$clearance) { |
|
| 186 | 186 | return ResponseModel::err(2001); |
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | $groupModel->changeClearance($all_data['uid'], $all_data["gid"], $all_data['permission']); |
| 190 | 190 | |
| 191 | - $result_info = $groupModel->userProfile($all_data['uid'],$all_data["gid"]); |
|
| 192 | - return ResponseModel::success(200,null,$result_info); |
|
| 191 | + $result_info=$groupModel->userProfile($all_data['uid'], $all_data["gid"]); |
|
| 192 | + return ResponseModel::success(200, null, $result_info); |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | public function approveMember(Request $request) |
@@ -205,7 +205,7 @@ discard block |
||
| 205 | 205 | $clearance=$groupModel->judgeClearance($all_data["gid"], Auth::user()->id); |
| 206 | 206 | $targetClearance=$groupModel->judgeClearance($all_data["gid"], $all_data["uid"]); |
| 207 | 207 | if ($clearance>1) { |
| 208 | - if($targetClearance!=0) { |
|
| 208 | + if ($targetClearance!=0) { |
|
| 209 | 209 | return ResponseModel::err(7003); |
| 210 | 210 | } |
| 211 | 211 | $groupModel->changeClearance($all_data["uid"], $all_data["gid"], 1); |
@@ -226,7 +226,7 @@ discard block |
||
| 226 | 226 | $groupModel=new GroupModel(); |
| 227 | 227 | $clearance=$groupModel->judgeClearance($all_data["gid"], Auth::user()->id); |
| 228 | 228 | $targetClearance=$groupModel->judgeClearance($all_data["gid"], $all_data["uid"]); |
| 229 | - if ($clearance <= 1 || $clearance <= $targetClearance){ |
|
| 229 | + if ($clearance<=1 || $clearance<=$targetClearance) { |
|
| 230 | 230 | return ResponseModel::err(7002); |
| 231 | 231 | } |
| 232 | 232 | |
@@ -246,11 +246,11 @@ discard block |
||
| 246 | 246 | |
| 247 | 247 | $groupModel=new GroupModel(); |
| 248 | 248 | $is_user=$groupModel->isUser($all_data["email"]); |
| 249 | - if(!$is_user) return ResponseModel::err(2006); |
|
| 249 | + if (!$is_user) return ResponseModel::err(2006); |
|
| 250 | 250 | $clearance=$groupModel->judgeClearance($all_data["gid"], Auth::user()->id); |
| 251 | - if($clearance<2) return ResponseModel::err(7002); |
|
| 251 | + if ($clearance<2) return ResponseModel::err(7002); |
|
| 252 | 252 | $targetClearance=$groupModel->judgeEmailClearance($all_data["gid"], $all_data["email"]); |
| 253 | - if($targetClearance!=-3) return ResponseModel::err(7003); |
|
| 253 | + if ($targetClearance!=-3) return ResponseModel::err(7003); |
|
| 254 | 254 | $groupModel->inviteMember($all_data["gid"], $all_data["email"]); |
| 255 | 255 | return ResponseModel::success(200); |
| 256 | 256 | } |
@@ -287,7 +287,7 @@ discard block |
||
| 287 | 287 | |
| 288 | 288 | $groupModel=new GroupModel(); |
| 289 | 289 | $clearance=$groupModel->judgeClearance($all_data["gid"], Auth::user()->id); |
| 290 | - if ($clearance < 2){ |
|
| 290 | + if ($clearance<2) { |
|
| 291 | 291 | return ResponseModel::err(2001); |
| 292 | 292 | } |
| 293 | 293 | $groupModel->createNotice($all_data["gid"], Auth::user()->id, $all_data["title"], $all_data["content"]); |
@@ -14,36 +14,36 @@ discard block |
||
| 14 | 14 | public $totParticipants=0; |
| 15 | 15 | public $INITIAL_RATING=1500; |
| 16 | 16 | |
| 17 | - public function __construct($cid){ |
|
| 18 | - $contestModel = new ContestModel(); |
|
| 19 | - $this->cid = $cid; |
|
| 20 | - $this->gid = $contestModel->gid($cid); |
|
| 17 | + public function __construct($cid) { |
|
| 18 | + $contestModel=new ContestModel(); |
|
| 19 | + $this->cid=$cid; |
|
| 20 | + $this->gid=$contestModel->gid($cid); |
|
| 21 | 21 | // get rank |
| 22 | 22 | $this->getRecord(); |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | - private function getRecord(){ |
|
| 26 | - $contestModel = new ContestModel(); |
|
| 27 | - $contestRankRaw = $contestModel->contestRank($this->cid); |
|
| 28 | - foreach($contestRankRaw as $key => $contestRank){ |
|
| 29 | - if(isset($contestRank['remote']) && $contestRank['remote']){ |
|
| 25 | + private function getRecord() { |
|
| 26 | + $contestModel=new ContestModel(); |
|
| 27 | + $contestRankRaw=$contestModel->contestRank($this->cid); |
|
| 28 | + foreach ($contestRankRaw as $key => $contestRank) { |
|
| 29 | + if (isset($contestRank['remote']) && $contestRank['remote']) { |
|
| 30 | 30 | unset($contestRankRaw[$key]); |
| 31 | 31 | } |
| 32 | 32 | } |
| 33 | - $contestRankRaw = array_values($contestRankRaw); |
|
| 34 | - $members = array_column($contestRankRaw,'uid'); |
|
| 35 | - $ratings_temp = DB::table('group_member') |
|
| 33 | + $contestRankRaw=array_values($contestRankRaw); |
|
| 34 | + $members=array_column($contestRankRaw, 'uid'); |
|
| 35 | + $ratings_temp=DB::table('group_member') |
|
| 36 | 36 | ->where([ |
| 37 | 37 | 'gid' => $this->gid, |
| 38 | - ])->whereIn('uid',$members) |
|
| 39 | - ->select('uid','ranking') |
|
| 38 | + ])->whereIn('uid', $members) |
|
| 39 | + ->select('uid', 'ranking') |
|
| 40 | 40 | ->get()->all(); |
| 41 | - $ratings = []; |
|
| 41 | + $ratings=[]; |
|
| 42 | 42 | foreach ($ratings_temp as $rating) { |
| 43 | - $ratings[$rating['uid']] = $rating['ranking']; |
|
| 43 | + $ratings[$rating['uid']]=$rating['ranking']; |
|
| 44 | 44 | } |
| 45 | - foreach($contestRankRaw as $c){ |
|
| 46 | - if(!isset($ratings[$c['uid']])){ |
|
| 45 | + foreach ($contestRankRaw as $c) { |
|
| 46 | + if (!isset($ratings[$c['uid']])) { |
|
| 47 | 47 | continue; |
| 48 | 48 | } |
| 49 | 49 | $this->contestants[]=[ |
@@ -52,87 +52,87 @@ discard block |
||
| 52 | 52 | "rating"=>$ratings[$c['uid']], |
| 53 | 53 | ]; |
| 54 | 54 | } |
| 55 | - $this->totParticipants = count($this->contestants); |
|
| 55 | + $this->totParticipants=count($this->contestants); |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | - private function reassignRank(){ |
|
| 58 | + private function reassignRank() { |
|
| 59 | 59 | $this->sort("points"); |
| 60 | - $idx = 0; |
|
| 61 | - $points = $this->contestants[0]["points"]; |
|
| 62 | - $i = 1; |
|
| 63 | - while($i < $this->totParticipants){ |
|
| 64 | - if($this->contestants[$i]["points"] < $points){ |
|
| 65 | - $j = $idx; |
|
| 66 | - while($j < $i){ |
|
| 67 | - $this->contestants[$j]["rank"] = $i; |
|
| 68 | - $j += 1; |
|
| 60 | + $idx=0; |
|
| 61 | + $points=$this->contestants[0]["points"]; |
|
| 62 | + $i=1; |
|
| 63 | + while ($i<$this->totParticipants) { |
|
| 64 | + if ($this->contestants[$i]["points"]<$points) { |
|
| 65 | + $j=$idx; |
|
| 66 | + while ($j<$i) { |
|
| 67 | + $this->contestants[$j]["rank"]=$i; |
|
| 68 | + $j+=1; |
|
| 69 | 69 | } |
| 70 | - $idx = $i; |
|
| 71 | - $points = $this->contestants[$i]["points"]; |
|
| 70 | + $idx=$i; |
|
| 71 | + $points=$this->contestants[$i]["points"]; |
|
| 72 | 72 | } |
| 73 | - $i += 1; |
|
| 73 | + $i+=1; |
|
| 74 | 74 | } |
| 75 | - $j = $idx; |
|
| 76 | - while($j < $this->totParticipants){ |
|
| 77 | - $this->contestants[$j]["rank"] = $this->totParticipants; |
|
| 78 | - $j += 1; |
|
| 75 | + $j=$idx; |
|
| 76 | + while ($j<$this->totParticipants) { |
|
| 77 | + $this->contestants[$j]["rank"]=$this->totParticipants; |
|
| 78 | + $j+=1; |
|
| 79 | 79 | } |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | - private function getEloWinProbability($Ra, $Rb){ |
|
| 83 | - return 1.0 / (1 + pow(10, ($Rb-$Ra)/400.0)); |
|
| 82 | + private function getEloWinProbability($Ra, $Rb) { |
|
| 83 | + return 1.0 / (1+pow(10, ($Rb-$Ra) / 400.0)); |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | - private function getSeed($rating){ |
|
| 87 | - $result = 1.0; |
|
| 88 | - foreach($this->contestants as $other){ |
|
| 89 | - $result += $this->getEloWinProbability($other["rating"], $rating); |
|
| 86 | + private function getSeed($rating) { |
|
| 87 | + $result=1.0; |
|
| 88 | + foreach ($this->contestants as $other) { |
|
| 89 | + $result+=$this->getEloWinProbability($other["rating"], $rating); |
|
| 90 | 90 | } |
| 91 | 91 | return $result; |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | - private function getRatingToRank($rank){ |
|
| 94 | + private function getRatingToRank($rank) { |
|
| 95 | 95 | $left=1; |
| 96 | 96 | $right=8000; |
| 97 | - while($right - $left > 1){ |
|
| 98 | - $mid = floor(($right + $left)/2); |
|
| 99 | - if($this->getSeed($mid) < $rank){ |
|
| 100 | - $right = $mid; |
|
| 101 | - }else{ |
|
| 102 | - $left = $mid; |
|
| 97 | + while ($right-$left>1) { |
|
| 98 | + $mid=floor(($right+$left) / 2); |
|
| 99 | + if ($this->getSeed($mid)<$rank) { |
|
| 100 | + $right=$mid; |
|
| 101 | + } else { |
|
| 102 | + $left=$mid; |
|
| 103 | 103 | } |
| 104 | 104 | } |
| 105 | 105 | return $left; |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | - private function sort($key){ |
|
| 109 | - usort($this->contestants, function ($a, $b) use ($key) { |
|
| 108 | + private function sort($key) { |
|
| 109 | + usort($this->contestants, function($a, $b) use ($key) { |
|
| 110 | 110 | return $b[$key] <=> $a[$key]; |
| 111 | 111 | }); |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | - public function calculate(){ |
|
| 115 | - if(empty($this->contestants)){ |
|
| 114 | + public function calculate() { |
|
| 115 | + if (empty($this->contestants)) { |
|
| 116 | 116 | return; |
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | // recalc rank |
| 120 | 120 | $this->reassignRank(); |
| 121 | 121 | |
| 122 | - foreach($this->contestants as &$member){ |
|
| 123 | - $member["seed"] = 1.0; |
|
| 124 | - foreach($this->contestants as $other){ |
|
| 125 | - if($member["uid"] != $other["uid"]){ |
|
| 126 | - $member["seed"] += $this->getEloWinProbability($other["rating"], $member["rating"]); |
|
| 122 | + foreach ($this->contestants as &$member) { |
|
| 123 | + $member["seed"]=1.0; |
|
| 124 | + foreach ($this->contestants as $other) { |
|
| 125 | + if ($member["uid"]!=$other["uid"]) { |
|
| 126 | + $member["seed"]+=$this->getEloWinProbability($other["rating"], $member["rating"]); |
|
| 127 | 127 | } |
| 128 | 128 | } |
| 129 | 129 | } |
| 130 | 130 | unset($member); |
| 131 | 131 | |
| 132 | - foreach($this->contestants as &$contestant){ |
|
| 133 | - $midRank = sqrt($contestant["rank"] * $contestant["seed"]); |
|
| 134 | - $contestant["needRating"] = $this->getRatingToRank($midRank); |
|
| 135 | - $contestant["delta"] = floor(($contestant["needRating"] - $contestant["rating"])/2); |
|
| 132 | + foreach ($this->contestants as &$contestant) { |
|
| 133 | + $midRank=sqrt($contestant["rank"] * $contestant["seed"]); |
|
| 134 | + $contestant["needRating"]=$this->getRatingToRank($midRank); |
|
| 135 | + $contestant["delta"]=floor(($contestant["needRating"]-$contestant["rating"]) / 2); |
|
| 136 | 136 | } |
| 137 | 137 | unset($contestant); |
| 138 | 138 | |
@@ -140,39 +140,39 @@ discard block |
||
| 140 | 140 | |
| 141 | 141 | // DO some adjuct |
| 142 | 142 | // Total sum should not be more than ZERO. |
| 143 | - $sum = 0; |
|
| 143 | + $sum=0; |
|
| 144 | 144 | |
| 145 | - foreach($this->contestants as $contestant){ |
|
| 146 | - $sum += $contestant["delta"]; |
|
| 145 | + foreach ($this->contestants as $contestant) { |
|
| 146 | + $sum+=$contestant["delta"]; |
|
| 147 | 147 | } |
| 148 | - $inc = -floor($sum / $this->totParticipants) - 1; |
|
| 149 | - foreach($this->contestants as &$contestant){ |
|
| 150 | - $contestant["delta"] += $inc; |
|
| 148 | + $inc=-floor($sum / $this->totParticipants)-1; |
|
| 149 | + foreach ($this->contestants as &$contestant) { |
|
| 150 | + $contestant["delta"]+=$inc; |
|
| 151 | 151 | } |
| 152 | 152 | unset($contestant); |
| 153 | 153 | |
| 154 | 154 | // Sum of top-4*sqrt should be adjusted to ZERO. |
| 155 | 155 | |
| 156 | - $sum = 0; |
|
| 157 | - $zeroSumCount = min(intval(4*round(sqrt($this->totParticipants))), $this->totParticipants); |
|
| 156 | + $sum=0; |
|
| 157 | + $zeroSumCount=min(intval(4 * round(sqrt($this->totParticipants))), $this->totParticipants); |
|
| 158 | 158 | |
| 159 | - for($i=0;$i<$zeroSumCount;$i++){ |
|
| 160 | - $sum += $this->contestants[$i]["delta"]; |
|
| 159 | + for ($i=0; $i<$zeroSumCount; $i++) { |
|
| 160 | + $sum+=$this->contestants[$i]["delta"]; |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | - $inc = min(max(-floor($sum / $zeroSumCount), -10), 0); |
|
| 163 | + $inc=min(max(-floor($sum / $zeroSumCount), -10), 0); |
|
| 164 | 164 | |
| 165 | - for($i=0;$i<$zeroSumCount;$i++){ |
|
| 166 | - $this->contestants[$i]["delta"] += $inc; |
|
| 165 | + for ($i=0; $i<$zeroSumCount; $i++) { |
|
| 166 | + $this->contestants[$i]["delta"]+=$inc; |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | return $this->validateDeltas(); |
| 170 | 170 | } |
| 171 | 171 | |
| 172 | - public function storage(){ |
|
| 172 | + public function storage() { |
|
| 173 | 173 | $contestants=$this->contestants; |
| 174 | - DB::transaction(function () use ($contestants) { |
|
| 175 | - foreach($contestants as $contestant){ |
|
| 174 | + DB::transaction(function() use ($contestants) { |
|
| 175 | + foreach ($contestants as $contestant) { |
|
| 176 | 176 | $newRating=$contestant["rating"]+$contestant["delta"]; |
| 177 | 177 | DB::table("group_member")->where([ |
| 178 | 178 | 'gid' => $this->gid, |
@@ -190,20 +190,20 @@ discard block |
||
| 190 | 190 | }, 5); |
| 191 | 191 | } |
| 192 | 192 | |
| 193 | - private function validateDeltas(){ |
|
| 193 | + private function validateDeltas() { |
|
| 194 | 194 | $this->sort("points"); |
| 195 | 195 | |
| 196 | - for($i=0;$i<$this->totParticipants;$i++){ |
|
| 197 | - for($j=$i+1;$j<$this->totParticipants;$j++){ |
|
| 198 | - if($this->contestants[$i]["rating"] > $this->contestants[$j]["rating"]){ |
|
| 199 | - if($this->contestants[$i]["rating"] + $this->contestants[$i]["delta"] < $this->contestants[$j]["rating"] + $this->contestants[$j]["delta"]){ |
|
| 196 | + for ($i=0; $i<$this->totParticipants; $i++) { |
|
| 197 | + for ($j=$i+1; $j<$this->totParticipants; $j++) { |
|
| 198 | + if ($this->contestants[$i]["rating"]>$this->contestants[$j]["rating"]) { |
|
| 199 | + if ($this->contestants[$i]["rating"]+$this->contestants[$i]["delta"]<$this->contestants[$j]["rating"]+$this->contestants[$j]["delta"]) { |
|
| 200 | 200 | Log::warning("First rating invariant failed: {$this->contestants[$i]["uid"]} vs. {$this->contestants[$j]["uid"]}."); |
| 201 | 201 | return false; |
| 202 | 202 | } |
| 203 | 203 | } |
| 204 | 204 | |
| 205 | - if($this->contestants[$i]["rating"] < $this->contestants[$j]["rating"]){ |
|
| 206 | - if($this->contestants[$i]["delta"] < $this->contestants[$j]["delta"]){ |
|
| 205 | + if ($this->contestants[$i]["rating"]<$this->contestants[$j]["rating"]) { |
|
| 206 | + if ($this->contestants[$i]["delta"]<$this->contestants[$j]["delta"]) { |
|
| 207 | 207 | Log::warning("Second rating invariant failed: {$this->contestants[$i]["uid"]} vs. {$this->contestants[$j]["uid"]}."); |
| 208 | 208 | return false; |
| 209 | 209 | } |