@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | $groupModel=new GroupModel(); |
| 44 | 44 | $contestModel=new ContestModel(); |
| 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 | $my_profile=$groupModel->userProfile(Auth::user()->id, $basic_info["gid"]); |
| 48 | 48 | $clearance=$groupModel->judgeClearance($basic_info["gid"], Auth::user()->id); |
| 49 | 49 | $member_list=$groupModel->userList($basic_info["gid"]); |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | */ |
| 89 | 89 | public function settings($gcode) |
| 90 | 90 | { |
| 91 | - return Redirect::route('group.settings.general', ['gcode' => $gcode]);; |
|
| 91 | + return Redirect::route('group.settings.general', ['gcode' => $gcode]); ; |
|
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | /** |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | */ |
| 99 | 99 | public function settingsReturn($gcode) |
| 100 | 100 | { |
| 101 | - return Redirect::route('group.detail', ['gcode' => $gcode]);; |
|
| 101 | + return Redirect::route('group.detail', ['gcode' => $gcode]); ; |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | /** |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | { |
| 111 | 111 | $groupModel=new GroupModel(); |
| 112 | 112 | $basic_info=$groupModel->details($gcode); |
| 113 | - if(empty($basic_info)) return Redirect::route('group.index'); |
|
| 113 | + if (empty($basic_info)) return Redirect::route('group.index'); |
|
| 114 | 114 | $clearance=$groupModel->judgeClearance($basic_info["gid"], Auth::user()->id); |
| 115 | 115 | $member_list=$groupModel->userList($basic_info["gid"]); |
| 116 | 116 | return view('group.settings.general', [ |
@@ -128,10 +128,10 @@ discard block |
||
| 128 | 128 | * |
| 129 | 129 | * @return Response |
| 130 | 130 | */ |
| 131 | - public function problems($gcode){ |
|
| 132 | - $groupModel = new GroupModel(); |
|
| 133 | - $group_info = $groupModel->details($gcode); |
|
| 134 | - $problems = $groupModel->problems($group_info['gid']); |
|
| 131 | + public function problems($gcode) { |
|
| 132 | + $groupModel=new GroupModel(); |
|
| 133 | + $group_info=$groupModel->details($gcode); |
|
| 134 | + $problems=$groupModel->problems($group_info['gid']); |
|
| 135 | 135 | $basic_info=$groupModel->details($gcode); |
| 136 | 136 | return view('group.settings.problems', [ |
| 137 | 137 | 'page_title'=>"Group Problems", |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | { |
| 153 | 153 | $groupModel=new GroupModel(); |
| 154 | 154 | $basic_info=$groupModel->details($gcode); |
| 155 | - if(empty($basic_info)) return Redirect::route('group.index'); |
|
| 155 | + if (empty($basic_info)) return Redirect::route('group.index'); |
|
| 156 | 156 | return view('group.settings.danger', [ |
| 157 | 157 | 'page_title'=>"Group Setting danger", |
| 158 | 158 | 'site_title'=>config("app.name"), |
@@ -166,9 +166,9 @@ discard block |
||
| 166 | 166 | * |
| 167 | 167 | * @return Response |
| 168 | 168 | */ |
| 169 | - public function analysis($gcode){ |
|
| 170 | - $groupModel = new GroupModel(); |
|
| 171 | - $group_info = $groupModel->details($gcode); |
|
| 169 | + public function analysis($gcode) { |
|
| 170 | + $groupModel=new GroupModel(); |
|
| 171 | + $group_info=$groupModel->details($gcode); |
|
| 172 | 172 | return view('group.settings.analysis', [ |
| 173 | 173 | 'page_title'=>"Group Analysis", |
| 174 | 174 | 'site_title'=>"NOJ", |
@@ -188,7 +188,7 @@ discard block |
||
| 188 | 188 | $groupModel=new GroupModel(); |
| 189 | 189 | $contestModel=new ContestModel(); |
| 190 | 190 | $basic_info=$groupModel->details($gcode); |
| 191 | - if(empty($basic_info)) return Redirect::route('group.index'); |
|
| 191 | + if (empty($basic_info)) return Redirect::route('group.index'); |
|
| 192 | 192 | $clearance=$groupModel->judgeClearance($basic_info["gid"], Auth::user()->id); |
| 193 | 193 | $member_list=$groupModel->userList($basic_info["gid"]); |
| 194 | 194 | $group_notice=$groupModel->detailNotice($gcode); |
@@ -208,7 +208,7 @@ discard block |
||
| 208 | 208 | $groupModel=new GroupModel(); |
| 209 | 209 | $contestModel=new ContestModel(); |
| 210 | 210 | $basic_info=$groupModel->details($gcode); |
| 211 | - if(empty($basic_info)) return Redirect::route('group.index'); |
|
| 211 | + if (empty($basic_info)) return Redirect::route('group.index'); |
|
| 212 | 212 | $clearance=$groupModel->judgeClearance($basic_info["gid"], Auth::user()->id); |
| 213 | 213 | $contest_list=$contestModel->listForSetting($basic_info["gid"]); |
| 214 | 214 | $member_list=$groupModel->userList($basic_info["gid"]); |
@@ -223,13 +223,13 @@ discard block |
||
| 223 | 223 | ]); |
| 224 | 224 | } |
| 225 | 225 | |
| 226 | - public function analysisDownload($gcode,Request $request){ |
|
| 227 | - $all_data = $request->all(); |
|
| 228 | - $groupModel = new GroupModel(); |
|
| 229 | - $group_info = $groupModel->details($gcode); |
|
| 230 | - $mode = $all_data['mode'] ?? 'contest'; |
|
| 231 | - if($mode == 'contest'){ |
|
| 232 | - $data = $groupModel->groupMemberPracticeContestStat($group_info['gid']); |
|
| 226 | + public function analysisDownload($gcode, Request $request) { |
|
| 227 | + $all_data=$request->all(); |
|
| 228 | + $groupModel=new GroupModel(); |
|
| 229 | + $group_info=$groupModel->details($gcode); |
|
| 230 | + $mode=$all_data['mode'] ?? 'contest'; |
|
| 231 | + if ($mode=='contest') { |
|
| 232 | + $data=$groupModel->groupMemberPracticeContestStat($group_info['gid']); |
|
| 233 | 233 | return Excel::download( |
| 234 | 234 | new GroupAnalysisExport( |
| 235 | 235 | [ |
@@ -242,10 +242,10 @@ discard block |
||
| 242 | 242 | 'percent' => $all_data['percent'] ?? false, |
| 243 | 243 | ] |
| 244 | 244 | ), |
| 245 | - $gcode . '_Group_Contest_Analysis.xlsx' |
|
| 245 | + $gcode.'_Group_Contest_Analysis.xlsx' |
|
| 246 | 246 | ); |
| 247 | - }else{ |
|
| 248 | - $data = $groupModel->groupMemberPracticeTagStat($group_info['gid']); |
|
| 247 | + } else { |
|
| 248 | + $data=$groupModel->groupMemberPracticeTagStat($group_info['gid']); |
|
| 249 | 249 | return Excel::download( |
| 250 | 250 | new GroupAnalysisExport( |
| 251 | 251 | [ |
@@ -258,7 +258,7 @@ discard block |
||
| 258 | 258 | 'percent' => $all_data['percent'] ?? false, |
| 259 | 259 | ] |
| 260 | 260 | ), |
| 261 | - $gcode . '_Group_Tag_Analysis.xlsx' |
|
| 261 | + $gcode.'_Group_Tag_Analysis.xlsx' |
|
| 262 | 262 | ); |
| 263 | 263 | } |
| 264 | 264 | } |
@@ -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 | |
@@ -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 | - $this->totParticipants = count($contestRankRaw); |
|
| 35 | - $members = array_column($contestRankRaw,'uid'); |
|
| 36 | - $ratings_temp = DB::table('group_member') |
|
| 33 | + $contestRankRaw=array_values($contestRankRaw); |
|
| 34 | + $this->totParticipants=count($contestRankRaw); |
|
| 35 | + $members=array_column($contestRankRaw, 'uid'); |
|
| 36 | + $ratings_temp=DB::table('group_member') |
|
| 37 | 37 | ->where([ |
| 38 | 38 | 'gid' => $this->gid, |
| 39 | - ])->whereIn('uid',$members) |
|
| 40 | - ->select('uid','ranking') |
|
| 39 | + ])->whereIn('uid', $members) |
|
| 40 | + ->select('uid', 'ranking') |
|
| 41 | 41 | ->get()->all(); |
| 42 | - $ratings = []; |
|
| 42 | + $ratings=[]; |
|
| 43 | 43 | foreach ($ratings_temp as $rating) { |
| 44 | - $ratings[$rating['uid']] = $rating['ranking']; |
|
| 44 | + $ratings[$rating['uid']]=$rating['ranking']; |
|
| 45 | 45 | } |
| 46 | - foreach($contestRankRaw as $c){ |
|
| 46 | + foreach ($contestRankRaw as $c) { |
|
| 47 | 47 | $this->contestants[]=[ |
| 48 | 48 | "uid"=>$c["uid"], |
| 49 | 49 | "points"=>$c["score"], |
@@ -52,84 +52,84 @@ discard block |
||
| 52 | 52 | } |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | - private function reassignRank(){ |
|
| 55 | + private function reassignRank() { |
|
| 56 | 56 | $this->sort("points"); |
| 57 | - $idx = 0; |
|
| 58 | - $points = $this->contestants[0]["points"]; |
|
| 59 | - $i = 1; |
|
| 60 | - while($i < $this->totParticipants){ |
|
| 61 | - if($this->contestants[$i]["points"] < $points){ |
|
| 62 | - $j = $idx; |
|
| 63 | - while($j < $i){ |
|
| 64 | - $this->contestants[$j]["rank"] = $i; |
|
| 65 | - $j += 1; |
|
| 57 | + $idx=0; |
|
| 58 | + $points=$this->contestants[0]["points"]; |
|
| 59 | + $i=1; |
|
| 60 | + while ($i<$this->totParticipants) { |
|
| 61 | + if ($this->contestants[$i]["points"]<$points) { |
|
| 62 | + $j=$idx; |
|
| 63 | + while ($j<$i) { |
|
| 64 | + $this->contestants[$j]["rank"]=$i; |
|
| 65 | + $j+=1; |
|
| 66 | 66 | } |
| 67 | - $idx = $i; |
|
| 68 | - $points = $this->contestants[$i]["points"]; |
|
| 67 | + $idx=$i; |
|
| 68 | + $points=$this->contestants[$i]["points"]; |
|
| 69 | 69 | } |
| 70 | - $i += 1; |
|
| 70 | + $i+=1; |
|
| 71 | 71 | } |
| 72 | - $j = $idx; |
|
| 73 | - while($j < $this->totParticipants){ |
|
| 74 | - $this->contestants[$j]["rank"] = $this->totParticipants; |
|
| 75 | - $j += 1; |
|
| 72 | + $j=$idx; |
|
| 73 | + while ($j<$this->totParticipants) { |
|
| 74 | + $this->contestants[$j]["rank"]=$this->totParticipants; |
|
| 75 | + $j+=1; |
|
| 76 | 76 | } |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | - private function getEloWinProbability($Ra, $Rb){ |
|
| 80 | - return 1.0 / (1 + pow(10, ($Rb-$Ra)/400.0)); |
|
| 79 | + private function getEloWinProbability($Ra, $Rb) { |
|
| 80 | + return 1.0 / (1+pow(10, ($Rb-$Ra) / 400.0)); |
|
| 81 | 81 | } |
| 82 | 82 | |
| 83 | - private function getSeed($rating){ |
|
| 84 | - $result = 1.0; |
|
| 85 | - foreach($this->contestants as $other){ |
|
| 86 | - $result += $this->getEloWinProbability($other["rating"], $rating); |
|
| 83 | + private function getSeed($rating) { |
|
| 84 | + $result=1.0; |
|
| 85 | + foreach ($this->contestants as $other) { |
|
| 86 | + $result+=$this->getEloWinProbability($other["rating"], $rating); |
|
| 87 | 87 | } |
| 88 | 88 | return $result; |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | - private function getRatingToRank($rank){ |
|
| 91 | + private function getRatingToRank($rank) { |
|
| 92 | 92 | $left=1; |
| 93 | 93 | $right=8000; |
| 94 | - while($right - $left > 1){ |
|
| 95 | - $mid = floor(($right + $left)/2); |
|
| 96 | - if($this->getSeed($mid) < $rank){ |
|
| 97 | - $right = $mid; |
|
| 98 | - }else{ |
|
| 99 | - $left = $mid; |
|
| 94 | + while ($right-$left>1) { |
|
| 95 | + $mid=floor(($right+$left) / 2); |
|
| 96 | + if ($this->getSeed($mid)<$rank) { |
|
| 97 | + $right=$mid; |
|
| 98 | + } else { |
|
| 99 | + $left=$mid; |
|
| 100 | 100 | } |
| 101 | 101 | } |
| 102 | 102 | return $left; |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | - private function sort($key){ |
|
| 106 | - usort($this->contestants, function ($a, $b) use ($key) { |
|
| 105 | + private function sort($key) { |
|
| 106 | + usort($this->contestants, function($a, $b) use ($key) { |
|
| 107 | 107 | return $b[$key] <=> $a[$key]; |
| 108 | 108 | }); |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | - public function calculate(){ |
|
| 112 | - if(empty($this->contestants)){ |
|
| 111 | + public function calculate() { |
|
| 112 | + if (empty($this->contestants)) { |
|
| 113 | 113 | return; |
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | // recalc rank |
| 117 | 117 | $this->reassignRank(); |
| 118 | 118 | |
| 119 | - foreach($this->contestants as &$member){ |
|
| 120 | - $member["seed"] = 1.0; |
|
| 121 | - foreach($this->contestants as $other){ |
|
| 122 | - if($member["uid"] != $other["uid"]){ |
|
| 123 | - $member["seed"] += $this->getEloWinProbability($other["rating"], $member["rating"]); |
|
| 119 | + foreach ($this->contestants as &$member) { |
|
| 120 | + $member["seed"]=1.0; |
|
| 121 | + foreach ($this->contestants as $other) { |
|
| 122 | + if ($member["uid"]!=$other["uid"]) { |
|
| 123 | + $member["seed"]+=$this->getEloWinProbability($other["rating"], $member["rating"]); |
|
| 124 | 124 | } |
| 125 | 125 | } |
| 126 | 126 | } |
| 127 | 127 | unset($member); |
| 128 | 128 | |
| 129 | - foreach($this->contestants as &$contestant){ |
|
| 130 | - $midRank = sqrt($contestant["rank"] * $contestant["seed"]); |
|
| 131 | - $contestant["needRating"] = $this->getRatingToRank($midRank); |
|
| 132 | - $contestant["delta"] = floor(($contestant["needRating"] - $contestant["rating"])/2); |
|
| 129 | + foreach ($this->contestants as &$contestant) { |
|
| 130 | + $midRank=sqrt($contestant["rank"] * $contestant["seed"]); |
|
| 131 | + $contestant["needRating"]=$this->getRatingToRank($midRank); |
|
| 132 | + $contestant["delta"]=floor(($contestant["needRating"]-$contestant["rating"]) / 2); |
|
| 133 | 133 | } |
| 134 | 134 | unset($contestant); |
| 135 | 135 | |
@@ -137,39 +137,39 @@ discard block |
||
| 137 | 137 | |
| 138 | 138 | // DO some adjuct |
| 139 | 139 | // Total sum should not be more than ZERO. |
| 140 | - $sum = 0; |
|
| 140 | + $sum=0; |
|
| 141 | 141 | |
| 142 | - foreach($this->contestants as $contestant){ |
|
| 143 | - $sum += $contestant["delta"]; |
|
| 142 | + foreach ($this->contestants as $contestant) { |
|
| 143 | + $sum+=$contestant["delta"]; |
|
| 144 | 144 | } |
| 145 | - $inc = -floor($sum / $this->totParticipants) - 1; |
|
| 146 | - foreach($this->contestants as &$contestant){ |
|
| 147 | - $contestant["delta"] += $inc; |
|
| 145 | + $inc=-floor($sum / $this->totParticipants)-1; |
|
| 146 | + foreach ($this->contestants as &$contestant) { |
|
| 147 | + $contestant["delta"]+=$inc; |
|
| 148 | 148 | } |
| 149 | 149 | unset($contestant); |
| 150 | 150 | |
| 151 | 151 | // Sum of top-4*sqrt should be adjusted to ZERO. |
| 152 | 152 | |
| 153 | - $sum = 0; |
|
| 154 | - $zeroSumCount = min(intval(4*round(sqrt($this->totParticipants))), $this->totParticipants); |
|
| 153 | + $sum=0; |
|
| 154 | + $zeroSumCount=min(intval(4 * round(sqrt($this->totParticipants))), $this->totParticipants); |
|
| 155 | 155 | |
| 156 | - for($i=0;$i<$zeroSumCount;$i++){ |
|
| 157 | - $sum += $this->contestants[$i]["delta"]; |
|
| 156 | + for ($i=0; $i<$zeroSumCount; $i++) { |
|
| 157 | + $sum+=$this->contestants[$i]["delta"]; |
|
| 158 | 158 | } |
| 159 | 159 | |
| 160 | - $inc = min(max(-floor($sum / $zeroSumCount), -10), 0); |
|
| 160 | + $inc=min(max(-floor($sum / $zeroSumCount), -10), 0); |
|
| 161 | 161 | |
| 162 | - for($i=0;$i<$zeroSumCount;$i++){ |
|
| 163 | - $this->contestants[$i]["delta"] += $inc; |
|
| 162 | + for ($i=0; $i<$zeroSumCount; $i++) { |
|
| 163 | + $this->contestants[$i]["delta"]+=$inc; |
|
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | return $this->validateDeltas(); |
| 167 | 167 | } |
| 168 | 168 | |
| 169 | - public function storage(){ |
|
| 169 | + public function storage() { |
|
| 170 | 170 | $contestants=$this->contestants; |
| 171 | - DB::transaction(function () use ($contestants) { |
|
| 172 | - foreach($contestants as $contestant){ |
|
| 171 | + DB::transaction(function() use ($contestants) { |
|
| 172 | + foreach ($contestants as $contestant) { |
|
| 173 | 173 | $newRating=$contestant["rating"]+$contestant["delta"]; |
| 174 | 174 | DB::table("group_member")->where([ |
| 175 | 175 | 'gid' => $this->gid, |
@@ -187,20 +187,20 @@ discard block |
||
| 187 | 187 | }, 5); |
| 188 | 188 | } |
| 189 | 189 | |
| 190 | - private function validateDeltas(){ |
|
| 190 | + private function validateDeltas() { |
|
| 191 | 191 | $this->sort("points"); |
| 192 | 192 | |
| 193 | - for($i=0;$i<$this->totParticipants;$i++){ |
|
| 194 | - for($j=$i+1;$j<$this->totParticipants;$j++){ |
|
| 195 | - if($this->contestants[$i]["rating"] > $this->contestants[$j]["rating"]){ |
|
| 196 | - if($this->contestants[$i]["rating"] + $this->contestants[$i]["delta"] < $this->contestants[$j]["rating"] + $this->contestants[$j]["delta"]){ |
|
| 193 | + for ($i=0; $i<$this->totParticipants; $i++) { |
|
| 194 | + for ($j=$i+1; $j<$this->totParticipants; $j++) { |
|
| 195 | + if ($this->contestants[$i]["rating"]>$this->contestants[$j]["rating"]) { |
|
| 196 | + if ($this->contestants[$i]["rating"]+$this->contestants[$i]["delta"]<$this->contestants[$j]["rating"]+$this->contestants[$j]["delta"]) { |
|
| 197 | 197 | Log::warning("First rating invariant failed: {$this->contestants[$i]["uid"]} vs. {$this->contestants[$j]["uid"]}."); |
| 198 | 198 | return false; |
| 199 | 199 | } |
| 200 | 200 | } |
| 201 | 201 | |
| 202 | - if($this->contestants[$i]["rating"] < $this->contestants[$j]["rating"]){ |
|
| 203 | - if($this->contestants[$i]["delta"] < $this->contestants[$j]["delta"]){ |
|
| 202 | + if ($this->contestants[$i]["rating"]<$this->contestants[$j]["rating"]) { |
|
| 203 | + if ($this->contestants[$i]["delta"]<$this->contestants[$j]["delta"]) { |
|
| 204 | 204 | Log::warning("Second rating invariant failed: {$this->contestants[$i]["uid"]} vs. {$this->contestants[$j]["uid"]}."); |
| 205 | 205 | return false; |
| 206 | 206 | } |
@@ -17,14 +17,14 @@ discard block |
||
| 17 | 17 | public $totParticipants=0; |
| 18 | 18 | public $INITIAL_RATING=1500; |
| 19 | 19 | |
| 20 | - public function __construct($cid){ |
|
| 20 | + public function __construct($cid) { |
|
| 21 | 21 | $this->cid=$cid; |
| 22 | 22 | |
| 23 | 23 | // get rank |
| 24 | 24 | $this->getRecord(); |
| 25 | 25 | } |
| 26 | 26 | |
| 27 | - private function getRecord(){ |
|
| 27 | + private function getRecord() { |
|
| 28 | 28 | $contestRankRaw=Cache::tags(['contest', 'rank'])->get($this->cid); |
| 29 | 29 | |
| 30 | 30 | if ($contestRankRaw==null) { |
@@ -32,8 +32,8 @@ discard block |
||
| 32 | 32 | $contestRankRaw=$contestModel->contestRankCache($this->cid); |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | - $this->totParticipants = count($contestRankRaw); |
|
| 36 | - foreach($contestRankRaw as $c){ |
|
| 35 | + $this->totParticipants=count($contestRankRaw); |
|
| 36 | + foreach ($contestRankRaw as $c) { |
|
| 37 | 37 | $this->contestants[]=[ |
| 38 | 38 | "uid"=>$c["uid"], |
| 39 | 39 | "points"=>$c["score"], |
@@ -42,84 +42,84 @@ discard block |
||
| 42 | 42 | } |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | - private function reassignRank(){ |
|
| 45 | + private function reassignRank() { |
|
| 46 | 46 | $this->sort("points"); |
| 47 | - $idx = 0; |
|
| 48 | - $points = $this->contestants[0]["points"]; |
|
| 49 | - $i = 1; |
|
| 50 | - while($i < $this->totParticipants){ |
|
| 51 | - if($this->contestants[$i]["points"] < $points){ |
|
| 52 | - $j = $idx; |
|
| 53 | - while($j < $i){ |
|
| 54 | - $this->contestants[$j]["rank"] = $i; |
|
| 55 | - $j += 1; |
|
| 47 | + $idx=0; |
|
| 48 | + $points=$this->contestants[0]["points"]; |
|
| 49 | + $i=1; |
|
| 50 | + while ($i<$this->totParticipants) { |
|
| 51 | + if ($this->contestants[$i]["points"]<$points) { |
|
| 52 | + $j=$idx; |
|
| 53 | + while ($j<$i) { |
|
| 54 | + $this->contestants[$j]["rank"]=$i; |
|
| 55 | + $j+=1; |
|
| 56 | 56 | } |
| 57 | - $idx = $i; |
|
| 58 | - $points = $this->contestants[$i]["points"]; |
|
| 57 | + $idx=$i; |
|
| 58 | + $points=$this->contestants[$i]["points"]; |
|
| 59 | 59 | } |
| 60 | - $i += 1; |
|
| 60 | + $i+=1; |
|
| 61 | 61 | } |
| 62 | - $j = $idx; |
|
| 63 | - while($j < $this->totParticipants){ |
|
| 64 | - $this->contestants[$j]["rank"] = $this->totParticipants; |
|
| 65 | - $j += 1; |
|
| 62 | + $j=$idx; |
|
| 63 | + while ($j<$this->totParticipants) { |
|
| 64 | + $this->contestants[$j]["rank"]=$this->totParticipants; |
|
| 65 | + $j+=1; |
|
| 66 | 66 | } |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | - private function getEloWinProbability($Ra, $Rb){ |
|
| 70 | - return 1.0 / (1 + pow(10, ($Rb-$Ra)/400.0)); |
|
| 69 | + private function getEloWinProbability($Ra, $Rb) { |
|
| 70 | + return 1.0 / (1+pow(10, ($Rb-$Ra) / 400.0)); |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | - private function getSeed($rating){ |
|
| 74 | - $result = 1.0; |
|
| 75 | - foreach($this->contestants as $other){ |
|
| 76 | - $result += $this->getEloWinProbability($other["rating"], $rating); |
|
| 73 | + private function getSeed($rating) { |
|
| 74 | + $result=1.0; |
|
| 75 | + foreach ($this->contestants as $other) { |
|
| 76 | + $result+=$this->getEloWinProbability($other["rating"], $rating); |
|
| 77 | 77 | } |
| 78 | 78 | return $result; |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | - private function getRatingToRank($rank){ |
|
| 81 | + private function getRatingToRank($rank) { |
|
| 82 | 82 | $left=1; |
| 83 | 83 | $right=8000; |
| 84 | - while($right - $left > 1){ |
|
| 85 | - $mid = floor(($right + $left)/2); |
|
| 86 | - if($this->getSeed($mid) < $rank){ |
|
| 87 | - $right = $mid; |
|
| 88 | - }else{ |
|
| 89 | - $left = $mid; |
|
| 84 | + while ($right-$left>1) { |
|
| 85 | + $mid=floor(($right+$left) / 2); |
|
| 86 | + if ($this->getSeed($mid)<$rank) { |
|
| 87 | + $right=$mid; |
|
| 88 | + } else { |
|
| 89 | + $left=$mid; |
|
| 90 | 90 | } |
| 91 | 91 | } |
| 92 | 92 | return $left; |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | - private function sort($key){ |
|
| 96 | - usort($this->contestants, function ($a, $b) use ($key) { |
|
| 95 | + private function sort($key) { |
|
| 96 | + usort($this->contestants, function($a, $b) use ($key) { |
|
| 97 | 97 | return $b[$key] <=> $a[$key]; |
| 98 | 98 | }); |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | - public function calculate(){ |
|
| 102 | - if(empty($this->contestants)){ |
|
| 101 | + public function calculate() { |
|
| 102 | + if (empty($this->contestants)) { |
|
| 103 | 103 | return; |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | // recalc rank |
| 107 | 107 | $this->reassignRank(); |
| 108 | 108 | |
| 109 | - foreach($this->contestants as &$member){ |
|
| 110 | - $member["seed"] = 1.0; |
|
| 111 | - foreach($this->contestants as $other){ |
|
| 112 | - if($member["uid"] != $other["uid"]){ |
|
| 113 | - $member["seed"] += $this->getEloWinProbability($other["rating"], $member["rating"]); |
|
| 109 | + foreach ($this->contestants as &$member) { |
|
| 110 | + $member["seed"]=1.0; |
|
| 111 | + foreach ($this->contestants as $other) { |
|
| 112 | + if ($member["uid"]!=$other["uid"]) { |
|
| 113 | + $member["seed"]+=$this->getEloWinProbability($other["rating"], $member["rating"]); |
|
| 114 | 114 | } |
| 115 | 115 | } |
| 116 | 116 | } |
| 117 | 117 | unset($member); |
| 118 | 118 | |
| 119 | - foreach($this->contestants as &$contestant){ |
|
| 120 | - $midRank = sqrt($contestant["rank"] * $contestant["seed"]); |
|
| 121 | - $contestant["needRating"] = $this->getRatingToRank($midRank); |
|
| 122 | - $contestant["delta"] = floor(($contestant["needRating"] - $contestant["rating"])/2); |
|
| 119 | + foreach ($this->contestants as &$contestant) { |
|
| 120 | + $midRank=sqrt($contestant["rank"] * $contestant["seed"]); |
|
| 121 | + $contestant["needRating"]=$this->getRatingToRank($midRank); |
|
| 122 | + $contestant["delta"]=floor(($contestant["needRating"]-$contestant["rating"]) / 2); |
|
| 123 | 123 | } |
| 124 | 124 | unset($contestant); |
| 125 | 125 | |
@@ -127,39 +127,39 @@ discard block |
||
| 127 | 127 | |
| 128 | 128 | // DO some adjuct |
| 129 | 129 | // Total sum should not be more than ZERO. |
| 130 | - $sum = 0; |
|
| 130 | + $sum=0; |
|
| 131 | 131 | |
| 132 | - foreach($this->contestants as $contestant){ |
|
| 133 | - $sum += $contestant["delta"]; |
|
| 132 | + foreach ($this->contestants as $contestant) { |
|
| 133 | + $sum+=$contestant["delta"]; |
|
| 134 | 134 | } |
| 135 | - $inc = -floor($sum / $this->totParticipants) - 1; |
|
| 136 | - foreach($this->contestants as &$contestant){ |
|
| 137 | - $contestant["delta"] += $inc; |
|
| 135 | + $inc=-floor($sum / $this->totParticipants)-1; |
|
| 136 | + foreach ($this->contestants as &$contestant) { |
|
| 137 | + $contestant["delta"]+=$inc; |
|
| 138 | 138 | } |
| 139 | 139 | unset($contestant); |
| 140 | 140 | |
| 141 | 141 | // Sum of top-4*sqrt should be adjusted to ZERO. |
| 142 | 142 | |
| 143 | - $sum = 0; |
|
| 144 | - $zeroSumCount = min(intval(4*round(sqrt($this->totParticipants))), $this->totParticipants); |
|
| 143 | + $sum=0; |
|
| 144 | + $zeroSumCount=min(intval(4 * round(sqrt($this->totParticipants))), $this->totParticipants); |
|
| 145 | 145 | |
| 146 | - for($i=0;$i<$zeroSumCount;$i++){ |
|
| 147 | - $sum += $this->contestants[$i]["delta"]; |
|
| 146 | + for ($i=0; $i<$zeroSumCount; $i++) { |
|
| 147 | + $sum+=$this->contestants[$i]["delta"]; |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | - $inc = min(max(-floor($sum / $zeroSumCount), -10), 0); |
|
| 150 | + $inc=min(max(-floor($sum / $zeroSumCount), -10), 0); |
|
| 151 | 151 | |
| 152 | - for($i=0;$i<$zeroSumCount;$i++){ |
|
| 153 | - $this->contestants[$i]["delta"] += $inc; |
|
| 152 | + for ($i=0; $i<$zeroSumCount; $i++) { |
|
| 153 | + $this->contestants[$i]["delta"]+=$inc; |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | return $this->validateDeltas(); |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | - public function storage(){ |
|
| 159 | + public function storage() { |
|
| 160 | 160 | $contestants=$this->contestants; |
| 161 | - DB::transaction(function () use ($contestants) { |
|
| 162 | - foreach($contestants as $contestant){ |
|
| 161 | + DB::transaction(function() use ($contestants) { |
|
| 162 | + foreach ($contestants as $contestant) { |
|
| 163 | 163 | $newRating=$contestant["rating"]+$contestant["delta"]; |
| 164 | 164 | DB::table("users")->where([ |
| 165 | 165 | "id"=>$contestant["uid"] |
@@ -181,20 +181,20 @@ discard block |
||
| 181 | 181 | }, 5); |
| 182 | 182 | } |
| 183 | 183 | |
| 184 | - private function validateDeltas(){ |
|
| 184 | + private function validateDeltas() { |
|
| 185 | 185 | $this->sort("points"); |
| 186 | 186 | |
| 187 | - for($i=0;$i<$this->totParticipants;$i++){ |
|
| 188 | - for($j=$i+1;$j<$this->totParticipants;$j++){ |
|
| 189 | - if($this->contestants[$i]["rating"] > $this->contestants[$j]["rating"]){ |
|
| 190 | - if($this->contestants[$i]["rating"] + $this->contestants[$i]["delta"] < $this->contestants[$j]["rating"] + $this->contestants[$j]["delta"]){ |
|
| 187 | + for ($i=0; $i<$this->totParticipants; $i++) { |
|
| 188 | + for ($j=$i+1; $j<$this->totParticipants; $j++) { |
|
| 189 | + if ($this->contestants[$i]["rating"]>$this->contestants[$j]["rating"]) { |
|
| 190 | + if ($this->contestants[$i]["rating"]+$this->contestants[$i]["delta"]<$this->contestants[$j]["rating"]+$this->contestants[$j]["delta"]) { |
|
| 191 | 191 | Log::warning("First rating invariant failed: {$this->contestants[$i]["uid"]} vs. {$this->contestants[$j]["uid"]}."); |
| 192 | 192 | return false; |
| 193 | 193 | } |
| 194 | 194 | } |
| 195 | 195 | |
| 196 | - if($this->contestants[$i]["rating"] < $this->contestants[$j]["rating"]){ |
|
| 197 | - if($this->contestants[$i]["delta"] < $this->contestants[$j]["delta"]){ |
|
| 196 | + if ($this->contestants[$i]["rating"]<$this->contestants[$j]["rating"]) { |
|
| 197 | + if ($this->contestants[$i]["delta"]<$this->contestants[$j]["delta"]) { |
|
| 198 | 198 | Log::warning("Second rating invariant failed: {$this->contestants[$i]["uid"]} vs. {$this->contestants[$j]["uid"]}."); |
| 199 | 199 | return false; |
| 200 | 200 | } |
@@ -58,10 +58,10 @@ discard block |
||
| 58 | 58 | foreach ($trending_groups as &$t) { |
| 59 | 59 | $t["members"]=$this->countGroupMembers($t["gid"]); |
| 60 | 60 | } |
| 61 | - usort($trending_groups, function ($a, $b) { |
|
| 61 | + usort($trending_groups, function($a, $b) { |
|
| 62 | 62 | return $b["members"]<=>$a["members"]; |
| 63 | 63 | }); |
| 64 | - Cache::tags(['group'])->put('trending', array_slice($trending_groups,0,12), 3600*24); |
|
| 64 | + Cache::tags(['group'])->put('trending', array_slice($trending_groups, 0, 12), 3600 * 24); |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | public function userGroups($uid) |
@@ -101,13 +101,13 @@ discard block |
||
| 101 | 101 | |
| 102 | 102 | public function changeGroupName($gid, $GroupName) |
| 103 | 103 | { |
| 104 | - return DB::table("group")->where('gid',$gid)->update([ |
|
| 104 | + return DB::table("group")->where('gid', $gid)->update([ |
|
| 105 | 105 | "name"=>$GroupName |
| 106 | 106 | ]); |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | - public function changeJoinPolicy($gid, $JoinPolicy){ |
|
| 110 | - return DB::table("group")->where('gid',$gid)->update([ |
|
| 109 | + public function changeJoinPolicy($gid, $JoinPolicy) { |
|
| 110 | + return DB::table("group")->where('gid', $gid)->update([ |
|
| 111 | 111 | "join_policy"=>$JoinPolicy |
| 112 | 112 | ]); |
| 113 | 113 | } |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | public function details($gcode) |
| 116 | 116 | { |
| 117 | 117 | $basic_info=DB::table($this->tableName)->where(["gcode"=>$gcode])->first(); |
| 118 | - if(empty($basic_info)) return []; |
|
| 118 | + if (empty($basic_info)) return []; |
|
| 119 | 119 | $basic_info["members"]=$this->countGroupMembers($basic_info["gid"]); |
| 120 | 120 | $basic_info["tags"]=$this->getGroupTags($basic_info["gid"]); |
| 121 | 121 | $basic_info["create_time_foramt"]=date_format(date_create($basic_info["create_time"]), 'M jS, Y'); |
@@ -132,10 +132,10 @@ discard block |
||
| 132 | 132 | public function userProfile($uid, $gid) |
| 133 | 133 | { |
| 134 | 134 | $info=DB::table("group_member") |
| 135 | - ->join('users','users.id','=','group_member.uid') |
|
| 135 | + ->join('users', 'users.id', '=', 'group_member.uid') |
|
| 136 | 136 | ->where(["gid"=>$gid, "uid"=>$uid]) |
| 137 | 137 | ->where("role", ">", 0) |
| 138 | - ->select('avatar','describes','email','gid','uid','name','nick_name','professional_rate','role','sub_group') |
|
| 138 | + ->select('avatar', 'describes', 'email', 'gid', 'uid', 'name', 'nick_name', 'professional_rate', 'role', 'sub_group') |
|
| 139 | 139 | ->first(); |
| 140 | 140 | if (!empty($info)) { |
| 141 | 141 | $info["role_parsed"]=$this->role[$info["role"]]; |
@@ -163,7 +163,7 @@ discard block |
||
| 163 | 163 | foreach ($user_list as &$u) { |
| 164 | 164 | $u["role_parsed"]=$this->role[$u["role"]]; |
| 165 | 165 | $u["role_color"]=$this->role_color[$u["role"]]; |
| 166 | - if(is_null($u["sub_group"])) $u["sub_group"]="None"; |
|
| 166 | + if (is_null($u["sub_group"])) $u["sub_group"]="None"; |
|
| 167 | 167 | } |
| 168 | 168 | return $user_list; |
| 169 | 169 | } |
@@ -224,16 +224,16 @@ discard block |
||
| 224 | 224 | ])->where("role", ">", 0)->count(); |
| 225 | 225 | } |
| 226 | 226 | |
| 227 | - public function problemTags($gid,$pid = -1) |
|
| 227 | + public function problemTags($gid, $pid=-1) |
|
| 228 | 228 | { |
| 229 | - if($pid == -1){ |
|
| 230 | - $tags = DB::table('group_problem_tag') |
|
| 229 | + if ($pid==-1) { |
|
| 230 | + $tags=DB::table('group_problem_tag') |
|
| 231 | 231 | ->select('tag') |
| 232 | - ->where('gid',$gid) |
|
| 232 | + ->where('gid', $gid) |
|
| 233 | 233 | ->distinct() |
| 234 | 234 | ->get()->all(); |
| 235 | - }else{ |
|
| 236 | - $tags = DB::table('group_problem_tag') |
|
| 235 | + } else { |
|
| 236 | + $tags=DB::table('group_problem_tag') |
|
| 237 | 237 | ->select('tag') |
| 238 | 238 | ->where('gid', $gid) |
| 239 | 239 | ->where('pid', $pid) |
@@ -241,10 +241,10 @@ discard block |
||
| 241 | 241 | ->get()->all(); |
| 242 | 242 | } |
| 243 | 243 | |
| 244 | - $tags_arr = []; |
|
| 245 | - if(!empty($tags)){ |
|
| 244 | + $tags_arr=[]; |
|
| 245 | + if (!empty($tags)) { |
|
| 246 | 246 | foreach ($tags as $value) { |
| 247 | - array_push($tags_arr,$value['tag']); |
|
| 247 | + array_push($tags_arr, $value['tag']); |
|
| 248 | 248 | } |
| 249 | 249 | } |
| 250 | 250 | return $tags_arr; |
@@ -252,28 +252,28 @@ discard block |
||
| 252 | 252 | |
| 253 | 253 | public function problems($gid) |
| 254 | 254 | { |
| 255 | - $contestModel = new ContestModel(); |
|
| 256 | - $problems = DB::table('contest_problem') |
|
| 257 | - ->join('contest','contest_problem.cid', '=', 'contest.cid') |
|
| 258 | - ->join('problem','contest_problem.pid', '=', 'problem.pid' ) |
|
| 255 | + $contestModel=new ContestModel(); |
|
| 256 | + $problems=DB::table('contest_problem') |
|
| 257 | + ->join('contest', 'contest_problem.cid', '=', 'contest.cid') |
|
| 258 | + ->join('problem', 'contest_problem.pid', '=', 'problem.pid') |
|
| 259 | 259 | ->select('contest_problem.cid as cid', 'problem.pid as pid', 'pcode', 'title') |
| 260 | - ->where('contest.gid',$gid) |
|
| 261 | - ->where('contest.practice',1) |
|
| 262 | - ->orderBy('contest.create_time','desc') |
|
| 260 | + ->where('contest.gid', $gid) |
|
| 261 | + ->where('contest.practice', 1) |
|
| 262 | + ->orderBy('contest.create_time', 'desc') |
|
| 263 | 263 | ->distinct() |
| 264 | 264 | ->get()->all(); |
| 265 | - $user_id = Auth::user()->id; |
|
| 266 | - foreach($problems as $key => $value){ |
|
| 267 | - if($contestModel->judgeClearance($value['cid'],$user_id) != 3){ |
|
| 265 | + $user_id=Auth::user()->id; |
|
| 266 | + foreach ($problems as $key => $value) { |
|
| 267 | + if ($contestModel->judgeClearance($value['cid'], $user_id)!=3) { |
|
| 268 | 268 | unset($problems[$key]); |
| 269 | - }else{ |
|
| 270 | - $problems[$key]['tags'] = $this->problemTags($gid,$value['pid']); |
|
| 269 | + } else { |
|
| 270 | + $problems[$key]['tags']=$this->problemTags($gid, $value['pid']); |
|
| 271 | 271 | } |
| 272 | 272 | } |
| 273 | 273 | return $problems; |
| 274 | 274 | } |
| 275 | 275 | |
| 276 | - public function problemAddTag($gid,$pid,$tag) |
|
| 276 | + public function problemAddTag($gid, $pid, $tag) |
|
| 277 | 277 | { |
| 278 | 278 | return DB::table("group_problem_tag")->insert([ |
| 279 | 279 | "gid"=>$gid, |
@@ -282,7 +282,7 @@ discard block |
||
| 282 | 282 | ]); |
| 283 | 283 | } |
| 284 | 284 | |
| 285 | - public function problemRemoveTag($gid,$pid,$tag) |
|
| 285 | + public function problemRemoveTag($gid, $pid, $tag) |
|
| 286 | 286 | { |
| 287 | 287 | return DB::table("group_problem_tag")->where([ |
| 288 | 288 | "gid"=>$gid, |
@@ -327,7 +327,7 @@ discard block |
||
| 327 | 327 | public function judgeEmailClearance($gid, $email) |
| 328 | 328 | { |
| 329 | 329 | $user=DB::table("users")->where(["email"=>$email])->first(); |
| 330 | - if(empty($user)) return -4; |
|
| 330 | + if (empty($user)) return -4; |
|
| 331 | 331 | $ret=DB::table("group_member")->where([ |
| 332 | 332 | "gid"=>$gid, |
| 333 | 333 | "uid"=>$user["id"], |
@@ -408,20 +408,20 @@ discard block |
||
| 408 | 408 | |
| 409 | 409 | public function groupMemberPracticeContestStat($gid) |
| 410 | 410 | { |
| 411 | - $contestModel = new ContestModel(); |
|
| 411 | + $contestModel=new ContestModel(); |
|
| 412 | 412 | |
| 413 | - $allPracticeContest = DB::table('contest') |
|
| 413 | + $allPracticeContest=DB::table('contest') |
|
| 414 | 414 | ->where([ |
| 415 | 415 | 'gid' => $gid, |
| 416 | 416 | 'practice' => 1, |
| 417 | 417 | ]) |
| 418 | - ->select('cid','name') |
|
| 418 | + ->select('cid', 'name') |
|
| 419 | 419 | ->get()->all(); |
| 420 | - $user_list = $this->userList($gid); |
|
| 420 | + $user_list=$this->userList($gid); |
|
| 421 | 421 | |
| 422 | - $memberData = []; |
|
| 422 | + $memberData=[]; |
|
| 423 | 423 | foreach ($user_list as $u) { |
| 424 | - $memberData[$u['uid']] = [ |
|
| 424 | + $memberData[$u['uid']]=[ |
|
| 425 | 425 | 'name' => $u['name'], |
| 426 | 426 | 'nick_name' => $u['nick_name'], |
| 427 | 427 | 'elo' => $u['ranking'], |
@@ -432,24 +432,24 @@ discard block |
||
| 432 | 432 | ]; |
| 433 | 433 | } |
| 434 | 434 | foreach ($allPracticeContest as $c) { |
| 435 | - $contestRankRaw = $contestModel->contestRank($c['cid']); |
|
| 436 | - foreach($contestRankRaw as $key => $contestRank){ |
|
| 437 | - if(isset($contestRank['remote']) && $contestRank['remote']){ |
|
| 435 | + $contestRankRaw=$contestModel->contestRank($c['cid']); |
|
| 436 | + foreach ($contestRankRaw as $key => $contestRank) { |
|
| 437 | + if (isset($contestRank['remote']) && $contestRank['remote']) { |
|
| 438 | 438 | unset($contestRankRaw[$key]); |
| 439 | 439 | } |
| 440 | 440 | } |
| 441 | - $contestRank = array_values($contestRankRaw); |
|
| 442 | - $problemsCount = DB::table('contest_problem') |
|
| 443 | - ->where('cid',$c['cid']) |
|
| 441 | + $contestRank=array_values($contestRankRaw); |
|
| 442 | + $problemsCount=DB::table('contest_problem') |
|
| 443 | + ->where('cid', $c['cid']) |
|
| 444 | 444 | ->count(); |
| 445 | - $rank = 0; |
|
| 445 | + $rank=0; |
|
| 446 | 446 | foreach ($contestRank as $cr) { |
| 447 | 447 | $rank++; |
| 448 | - if(in_array($cr['uid'],array_keys($memberData))) { |
|
| 449 | - $memberData[$cr['uid']]['solved_all'] += $cr['solved']; |
|
| 450 | - $memberData[$cr['uid']]['problem_all'] += $problemsCount; |
|
| 451 | - $memberData[$cr['uid']]['penalty'] += $cr['penalty']; |
|
| 452 | - $memberData[$cr['uid']]['contest_detial'][$c['cid']] = [ |
|
| 448 | + if (in_array($cr['uid'], array_keys($memberData))) { |
|
| 449 | + $memberData[$cr['uid']]['solved_all']+=$cr['solved']; |
|
| 450 | + $memberData[$cr['uid']]['problem_all']+=$problemsCount; |
|
| 451 | + $memberData[$cr['uid']]['penalty']+=$cr['penalty']; |
|
| 452 | + $memberData[$cr['uid']]['contest_detial'][$c['cid']]=[ |
|
| 453 | 453 | 'rank' => $rank, |
| 454 | 454 | 'solved' => $cr['solved'], |
| 455 | 455 | 'problems' => $problemsCount, |
@@ -458,22 +458,22 @@ discard block |
||
| 458 | 458 | } |
| 459 | 459 | } |
| 460 | 460 | } |
| 461 | - $new_memberData = []; |
|
| 461 | + $new_memberData=[]; |
|
| 462 | 462 | foreach ($memberData as $uid => $data) { |
| 463 | - $contest_count = 0; |
|
| 464 | - $rank_sum = 0; |
|
| 463 | + $contest_count=0; |
|
| 464 | + $rank_sum=0; |
|
| 465 | 465 | foreach ($data['contest_detial'] as $cid => $c) { |
| 466 | - $rank_sum += $c['rank']; |
|
| 467 | - $contest_count += 1; |
|
| 466 | + $rank_sum+=$c['rank']; |
|
| 467 | + $contest_count+=1; |
|
| 468 | 468 | } |
| 469 | - $temp = $data; |
|
| 470 | - $temp['uid'] = $uid; |
|
| 471 | - if($contest_count != 0){ |
|
| 472 | - $temp['rank_ave'] = $rank_sum/$contest_count; |
|
| 469 | + $temp=$data; |
|
| 470 | + $temp['uid']=$uid; |
|
| 471 | + if ($contest_count!=0) { |
|
| 472 | + $temp['rank_ave']=$rank_sum / $contest_count; |
|
| 473 | 473 | } |
| 474 | - array_push($new_memberData,$temp); |
|
| 474 | + array_push($new_memberData, $temp); |
|
| 475 | 475 | } |
| 476 | - $ret = [ |
|
| 476 | + $ret=[ |
|
| 477 | 477 | 'contest_list' => $allPracticeContest, |
| 478 | 478 | 'member_data' => $new_memberData |
| 479 | 479 | ]; |
@@ -482,58 +482,58 @@ discard block |
||
| 482 | 482 | |
| 483 | 483 | public function groupMemberPracticeTagStat($gid) |
| 484 | 484 | { |
| 485 | - $tags = $this->problemTags($gid); |
|
| 486 | - $tag_problems = []; |
|
| 485 | + $tags=$this->problemTags($gid); |
|
| 486 | + $tag_problems=[]; |
|
| 487 | 487 | |
| 488 | - $user_list = $this->userList($gid); |
|
| 488 | + $user_list=$this->userList($gid); |
|
| 489 | 489 | foreach ($tags as $tag) { |
| 490 | - $tag_problems[$tag] = DB::table('problem') |
|
| 491 | - ->join('group_problem_tag','problem.pid','=','group_problem_tag.pid') |
|
| 490 | + $tag_problems[$tag]=DB::table('problem') |
|
| 491 | + ->join('group_problem_tag', 'problem.pid', '=', 'group_problem_tag.pid') |
|
| 492 | 492 | ->where([ |
| 493 | 493 | 'group_problem_tag.gid' => $gid, |
| 494 | 494 | 'tag' => $tag |
| 495 | 495 | ]) |
| 496 | - ->select('group_problem_tag.pid as pid','pcode','title') |
|
| 496 | + ->select('group_problem_tag.pid as pid', 'pcode', 'title') |
|
| 497 | 497 | ->get()->all(); |
| 498 | 498 | } |
| 499 | - $all_problems = []; |
|
| 499 | + $all_problems=[]; |
|
| 500 | 500 | foreach ($tag_problems as &$tag_problem_set) { |
| 501 | 501 | foreach ($tag_problem_set as $problem) { |
| 502 | - $all_problems[$problem['pid']] = $problem; |
|
| 502 | + $all_problems[$problem['pid']]=$problem; |
|
| 503 | 503 | } |
| 504 | - $tag_problem_set = array_column($tag_problem_set,'pid'); |
|
| 504 | + $tag_problem_set=array_column($tag_problem_set, 'pid'); |
|
| 505 | 505 | } |
| 506 | - $submission_data = DB::table('submission') |
|
| 507 | - ->whereIn('pid',array_keys($all_problems)) |
|
| 508 | - ->whereIn('uid',array_column($user_list,'uid')) |
|
| 509 | - ->where('verdict','Accepted') |
|
| 510 | - ->select('pid','uid') |
|
| 506 | + $submission_data=DB::table('submission') |
|
| 507 | + ->whereIn('pid', array_keys($all_problems)) |
|
| 508 | + ->whereIn('uid', array_column($user_list, 'uid')) |
|
| 509 | + ->where('verdict', 'Accepted') |
|
| 510 | + ->select('pid', 'uid') |
|
| 511 | 511 | ->get()->all(); |
| 512 | 512 | |
| 513 | - $memberData = []; |
|
| 513 | + $memberData=[]; |
|
| 514 | 514 | foreach ($user_list as $member) { |
| 515 | - $completion = []; |
|
| 516 | - foreach($tag_problems as $tag => $problems) { |
|
| 517 | - $completion[$tag] = []; |
|
| 515 | + $completion=[]; |
|
| 516 | + foreach ($tag_problems as $tag => $problems) { |
|
| 517 | + $completion[$tag]=[]; |
|
| 518 | 518 | foreach ($problems as $problem) { |
| 519 | - $is_accepted = 0; |
|
| 519 | + $is_accepted=0; |
|
| 520 | 520 | foreach ($submission_data as $sd) { |
| 521 | - if($sd['pid'] == $problem && $sd['uid'] == $member['uid']){ |
|
| 522 | - $is_accepted = 1; |
|
| 521 | + if ($sd['pid']==$problem && $sd['uid']==$member['uid']) { |
|
| 522 | + $is_accepted=1; |
|
| 523 | 523 | break; |
| 524 | 524 | } |
| 525 | 525 | } |
| 526 | - $completion[$tag][$problem] = $is_accepted; |
|
| 526 | + $completion[$tag][$problem]=$is_accepted; |
|
| 527 | 527 | } |
| 528 | 528 | } |
| 529 | - array_push($memberData,[ |
|
| 529 | + array_push($memberData, [ |
|
| 530 | 530 | 'uid' => $member['uid'], |
| 531 | 531 | 'name' => $member['name'], |
| 532 | 532 | 'nick_name' => $member['nick_name'], |
| 533 | 533 | 'completion' => $completion, |
| 534 | 534 | ]); |
| 535 | 535 | } |
| 536 | - $ret = [ |
|
| 536 | + $ret=[ |
|
| 537 | 537 | 'all_problems' => $all_problems, |
| 538 | 538 | 'tag_problems' => $tag_problems, |
| 539 | 539 | 'member_data' => $memberData |
@@ -544,29 +544,29 @@ discard block |
||
| 544 | 544 | public function refreshElo($gid) |
| 545 | 545 | { |
| 546 | 546 | DB::table('group_rated_change_log') |
| 547 | - ->where('gid',$gid) |
|
| 547 | + ->where('gid', $gid) |
|
| 548 | 548 | ->delete(); |
| 549 | 549 | DB::table('group_member') |
| 550 | - ->where('gid',$gid) |
|
| 550 | + ->where('gid', $gid) |
|
| 551 | 551 | ->update([ |
| 552 | 552 | 'ranking' => 1500 |
| 553 | 553 | ]); |
| 554 | - $contests = DB::table('contest') |
|
| 554 | + $contests=DB::table('contest') |
|
| 555 | 555 | ->where([ |
| 556 | 556 | 'gid' => $gid, |
| 557 | 557 | 'practice' => 1 |
| 558 | 558 | ]) |
| 559 | - ->where('end_time','<',date("Y-m-d H:i:s")) |
|
| 559 | + ->where('end_time', '<', date("Y-m-d H:i:s")) |
|
| 560 | 560 | ->select('cid') |
| 561 | 561 | ->orderBy('end_time') |
| 562 | 562 | ->get()->all(); |
| 563 | 563 | |
| 564 | - if(empty($contests)) { |
|
| 564 | + if (empty($contests)) { |
|
| 565 | 565 | return true; |
| 566 | 566 | } |
| 567 | 567 | |
| 568 | 568 | foreach ($contests as $contest) { |
| 569 | - $calc = new GroupRatingCalculator($contest['cid']); |
|
| 569 | + $calc=new GroupRatingCalculator($contest['cid']); |
|
| 570 | 570 | $calc->calculate(); |
| 571 | 571 | $calc->storage(); |
| 572 | 572 | } |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | |
| 12 | 12 | class AccountModel extends Model |
| 13 | 13 | { |
| 14 | - private $user_extra = [ |
|
| 14 | + private $user_extra=[ |
|
| 15 | 15 | 0 => 'gender', |
| 16 | 16 | 1 => 'contact', |
| 17 | 17 | 2 => 'school', |
@@ -26,11 +26,11 @@ discard block |
||
| 26 | 26 | 1004 => 'github_token', |
| 27 | 27 | ]; |
| 28 | 28 | |
| 29 | - private $socialite_support = [ |
|
| 29 | + private $socialite_support=[ |
|
| 30 | 30 | //use the form "platform_id" for unique authentication |
| 31 | 31 | //such as github_id |
| 32 | 32 | 'github' => [ |
| 33 | - 'email','nickname','homepage','token' |
|
| 33 | + 'email', 'nickname', 'homepage', 'token' |
|
| 34 | 34 | ], |
| 35 | 35 | ]; |
| 36 | 36 | |
@@ -48,8 +48,8 @@ discard block |
||
| 48 | 48 | public function feed($uid=null) |
| 49 | 49 | { |
| 50 | 50 | $ret=[]; |
| 51 | - $solution=DB::table("problem_solution")->join("problem","problem.pid","=","problem_solution.pid")->where(["uid"=>$uid,"audit"=>1])->select("problem.pid as pid","pcode","title","problem_solution.created_at as created_at")->orderBy("problem_solution.created_at","DESC")->get()->all(); |
|
| 52 | - foreach($solution as &$s){ |
|
| 51 | + $solution=DB::table("problem_solution")->join("problem", "problem.pid", "=", "problem_solution.pid")->where(["uid"=>$uid, "audit"=>1])->select("problem.pid as pid", "pcode", "title", "problem_solution.created_at as created_at")->orderBy("problem_solution.created_at", "DESC")->get()->all(); |
|
| 52 | + foreach ($solution as &$s) { |
|
| 53 | 53 | $s["type"]="event"; |
| 54 | 54 | $s["color"]="wemd-orange"; |
| 55 | 55 | $s["icon"]="comment-check-outline"; |
@@ -120,14 +120,14 @@ discard block |
||
| 120 | 120 | ])->join("problem", "problem.pid", "=", "submission.pid")->select('pcode')->distinct()->get()->all(); |
| 121 | 121 | $ret["solvedCount"]=count($ret["solved"]); |
| 122 | 122 | // Casual |
| 123 | - $ret["rank"]=Cache::tags(['rank',$ret["id"]])->get("rank", "N/A"); |
|
| 124 | - $ret["rankTitle"]=Cache::tags(['rank',$ret["id"]])->get("title"); |
|
| 123 | + $ret["rank"]=Cache::tags(['rank', $ret["id"]])->get("rank", "N/A"); |
|
| 124 | + $ret["rankTitle"]=Cache::tags(['rank', $ret["id"]])->get("title"); |
|
| 125 | 125 | $ret["rankTitleColor"]=RankModel::getColor($ret["rankTitle"]); |
| 126 | 126 | // Professional |
| 127 | 127 | $ret["professionalTitle"]=RankModel::getProfessionalTitle($ret["professional_rate"]); |
| 128 | 128 | $ret["professionalTitleColor"]=RankModel::getProfessionalColor($ret["professionalTitle"]); |
| 129 | 129 | // Administration Group |
| 130 | - $ret["admin"]=$uid==1?1:0; |
|
| 130 | + $ret["admin"]=$uid==1 ? 1 : 0; |
|
| 131 | 131 | if (Cache::tags(['bing', 'pic'])->get(date("Y-m-d"))==null) { |
| 132 | 132 | $bing=new BingPhoto([ |
| 133 | 133 | 'locale' => 'zh-CN', |
@@ -146,26 +146,26 @@ discard block |
||
| 146 | 146 | * @param string|array $need An array is returned when an array is passed in,Only one value is returned when a string is passed in. |
| 147 | 147 | * @return string|array $result |
| 148 | 148 | */ |
| 149 | - public function getExtra($uid,$need, $secret_level = 0){ |
|
| 150 | - $ret = DB::table('users_extra')->where('uid',$uid)->orderBy('key')->get()->all(); |
|
| 151 | - $result = []; |
|
| 152 | - if(!empty($ret)){ |
|
| 153 | - if(is_string($need)){ |
|
| 149 | + public function getExtra($uid, $need, $secret_level=0) { |
|
| 150 | + $ret=DB::table('users_extra')->where('uid', $uid)->orderBy('key')->get()->all(); |
|
| 151 | + $result=[]; |
|
| 152 | + if (!empty($ret)) { |
|
| 153 | + if (is_string($need)) { |
|
| 154 | 154 | foreach ($ret as $value) { |
| 155 | - if(empty($value['secret_level']) || $value['secret_level'] <= $secret_level){ |
|
| 156 | - $key_name = $this->user_extra[$value['key']] ?? 'unknown'; |
|
| 157 | - if($key_name == $need){ |
|
| 155 | + if (empty($value['secret_level']) || $value['secret_level']<=$secret_level) { |
|
| 156 | + $key_name=$this->user_extra[$value['key']] ?? 'unknown'; |
|
| 157 | + if ($key_name==$need) { |
|
| 158 | 158 | return $value['value']; |
| 159 | 159 | } |
| 160 | 160 | } |
| 161 | 161 | } |
| 162 | 162 | return null; |
| 163 | - }else{ |
|
| 163 | + } else { |
|
| 164 | 164 | foreach ($ret as $value) { |
| 165 | - if(empty($value['secret_level']) || $value['secret_level'] <= $secret_level){ |
|
| 166 | - $key_name = $this->user_extra[$value['key']] ?? 'unknown'; |
|
| 167 | - if(in_array($key_name,$need)){ |
|
| 168 | - $result[$key_name] = $value['value']; |
|
| 165 | + if (empty($value['secret_level']) || $value['secret_level']<=$secret_level) { |
|
| 166 | + $key_name=$this->user_extra[$value['key']] ?? 'unknown'; |
|
| 167 | + if (in_array($key_name, $need)) { |
|
| 168 | + $result[$key_name]=$value['value']; |
|
| 169 | 169 | } |
| 170 | 170 | } |
| 171 | 171 | } |
@@ -182,26 +182,26 @@ discard block |
||
| 182 | 182 | * @param string|null $value the extra info will be delete when value is null |
| 183 | 183 | * @return mixed $result |
| 184 | 184 | */ |
| 185 | - public function setExtra($uid,$key_name,$value = null,$secret_level = -1){ |
|
| 186 | - $key = array_search($key_name,$this->user_extra); |
|
| 187 | - if($key === false){ |
|
| 185 | + public function setExtra($uid, $key_name, $value=null, $secret_level=-1) { |
|
| 186 | + $key=array_search($key_name, $this->user_extra); |
|
| 187 | + if ($key===false) { |
|
| 188 | 188 | return false; |
| 189 | 189 | } |
| 190 | - $ret = DB::table('users_extra')->where('uid',$uid)->where('key',$key)->first(); |
|
| 191 | - if(!empty($ret)){ |
|
| 190 | + $ret=DB::table('users_extra')->where('uid', $uid)->where('key', $key)->first(); |
|
| 191 | + if (!empty($ret)) { |
|
| 192 | 192 | unset($ret['id']); |
| 193 | - if(!is_null($value)){ |
|
| 194 | - $ret['value'] = $value; |
|
| 195 | - }else{ |
|
| 196 | - DB::table('users_extra')->where('uid',$uid)->where('key',$key)->delete(); |
|
| 193 | + if (!is_null($value)) { |
|
| 194 | + $ret['value']=$value; |
|
| 195 | + } else { |
|
| 196 | + DB::table('users_extra')->where('uid', $uid)->where('key', $key)->delete(); |
|
| 197 | 197 | return true; |
| 198 | 198 | } |
| 199 | - if($secret_level != -1){ |
|
| 200 | - $ret['secret_level'] = $secret_level; |
|
| 199 | + if ($secret_level!=-1) { |
|
| 200 | + $ret['secret_level']=$secret_level; |
|
| 201 | 201 | } |
| 202 | - return DB::table('users_extra')->where('uid',$uid)->where('key',$key)->update($ret); |
|
| 203 | - }else{ |
|
| 204 | - if($value === null){ |
|
| 202 | + return DB::table('users_extra')->where('uid', $uid)->where('key', $key)->update($ret); |
|
| 203 | + } else { |
|
| 204 | + if ($value===null) { |
|
| 205 | 205 | return true; |
| 206 | 206 | } |
| 207 | 207 | return DB::table('users_extra')->insertGetId( |
@@ -209,7 +209,7 @@ discard block |
||
| 209 | 209 | 'uid' => $uid, |
| 210 | 210 | 'key' => $key, |
| 211 | 211 | 'value' => $value, |
| 212 | - 'secret_level' => $secret_level == -1 ? 0 : $secret_level, |
|
| 212 | + 'secret_level' => $secret_level==-1 ? 0 : $secret_level, |
|
| 213 | 213 | ] |
| 214 | 214 | ); |
| 215 | 215 | } |
@@ -221,33 +221,33 @@ discard block |
||
| 221 | 221 | * @param string $value the value |
| 222 | 222 | * @return string $result |
| 223 | 223 | */ |
| 224 | - public function findExtra($key,$value) |
|
| 224 | + public function findExtra($key, $value) |
|
| 225 | 225 | { |
| 226 | - $key = array_search($key,$this->user_extra); |
|
| 227 | - if($key){ |
|
| 228 | - return DB::table('users_extra')->where('key',$key)->where('value',$value)->first(); |
|
| 229 | - }else{ |
|
| 226 | + $key=array_search($key, $this->user_extra); |
|
| 227 | + if ($key) { |
|
| 228 | + return DB::table('users_extra')->where('key', $key)->where('value', $value)->first(); |
|
| 229 | + } else { |
|
| 230 | 230 | return null; |
| 231 | 231 | } |
| 232 | 232 | } |
| 233 | 233 | |
| 234 | - public function getSocialiteInfo($uid,$secret_level = -1) |
|
| 234 | + public function getSocialiteInfo($uid, $secret_level=-1) |
|
| 235 | 235 | { |
| 236 | - $socialites = []; |
|
| 236 | + $socialites=[]; |
|
| 237 | 237 | foreach ($this->socialite_support as $key => $value) { |
| 238 | - $id_keyname = $key.'_id'; |
|
| 239 | - $id = $this->getExtra($uid,$id_keyname); |
|
| 240 | - if(!empty($id)){ |
|
| 241 | - $info = [ |
|
| 238 | + $id_keyname=$key.'_id'; |
|
| 239 | + $id=$this->getExtra($uid, $id_keyname); |
|
| 240 | + if (!empty($id)) { |
|
| 241 | + $info=[ |
|
| 242 | 242 | 'id' => $id, |
| 243 | 243 | ]; |
| 244 | 244 | foreach ($value as $info_name) { |
| 245 | - $info_temp = $this->getExtra($uid,$key.'_'.$info_name); |
|
| 246 | - if($info_temp !== null){ |
|
| 247 | - $info[$info_name] = $info_temp; |
|
| 245 | + $info_temp=$this->getExtra($uid, $key.'_'.$info_name); |
|
| 246 | + if ($info_temp!==null) { |
|
| 247 | + $info[$info_name]=$info_temp; |
|
| 248 | 248 | } |
| 249 | 249 | } |
| 250 | - $socialites[$key] = $info; |
|
| 250 | + $socialites[$key]=$info; |
|
| 251 | 251 | } |
| 252 | 252 | } |
| 253 | 253 | |
@@ -23,34 +23,34 @@ |
||
| 23 | 23 | if (!$request->has('search_key')) { |
| 24 | 24 | return ResponseModel::err(1003); |
| 25 | 25 | } |
| 26 | - $key = $request->input('search_key'); |
|
| 27 | - $all_result = []; |
|
| 28 | - $search_from = [ |
|
| 26 | + $key=$request->input('search_key'); |
|
| 27 | + $all_result=[]; |
|
| 28 | + $search_from=[ |
|
| 29 | 29 | 'users' => \App\Models\Search\UserSearchModel::class, |
| 30 | 30 | 'problems' => \App\Models\Search\ProblemSearchModel::class, |
| 31 | 31 | 'contests' => \App\Models\Search\ContestSearchModel::class, |
| 32 | 32 | 'groups' => \App\Models\Search\GroupSearchModel::class, |
| 33 | 33 | ]; |
| 34 | 34 | foreach ($search_from as $name => $model_class) { |
| 35 | - if(class_exists($model_class)){ |
|
| 36 | - $model = new $model_class(); |
|
| 37 | - if(!method_exists($model,'search')){ |
|
| 38 | - $all_result[$name] = [ |
|
| 35 | + if (class_exists($model_class)) { |
|
| 36 | + $model=new $model_class(); |
|
| 37 | + if (!method_exists($model, 'search')) { |
|
| 38 | + $all_result[$name]=[ |
|
| 39 | 39 | 'code' => -1, |
| 40 | 40 | 'msg' => 'cannot find search method in '.$model_class |
| 41 | 41 | ]; |
| 42 | 42 | continue; |
| 43 | 43 | } |
| 44 | - $result = $model->search($key); |
|
| 45 | - $all_result[$name] = $result; |
|
| 46 | - }else{ |
|
| 47 | - $all_result[$name] = [ |
|
| 44 | + $result=$model->search($key); |
|
| 45 | + $all_result[$name]=$result; |
|
| 46 | + } else { |
|
| 47 | + $all_result[$name]=[ |
|
| 48 | 48 | 'code' => -1, |
| 49 | 49 | 'msg' => 'cannot find class named '.$model_class |
| 50 | - ];; |
|
| 50 | + ]; ; |
|
| 51 | 51 | continue; |
| 52 | 52 | } |
| 53 | 53 | } |
| 54 | - return ResponseModel::success(200,'Successful',$all_result); |
|
| 54 | + return ResponseModel::success(200, 'Successful', $all_result); |
|
| 55 | 55 | } |
| 56 | 56 | } |
@@ -91,7 +91,7 @@ |
||
| 91 | 91 | { |
| 92 | 92 | $serverList=DB::table("judge_server")->where(["oid"=>$oid])->get()->all(); |
| 93 | 93 | foreach ($serverList as &$server) { |
| 94 | - $server["status_parsed"]=is_null($server["status"])?self::$status["-1"]:self::$status[$server["status"]]; |
|
| 94 | + $server["status_parsed"]=is_null($server["status"]) ?self::$status["-1"] : self::$status[$server["status"]]; |
|
| 95 | 95 | } |
| 96 | 96 | return $serverList; |
| 97 | 97 | } |
@@ -110,8 +110,8 @@ discard block |
||
| 110 | 110 | if (empty($basic)) { |
| 111 | 111 | return ResponseModel::err(3001); |
| 112 | 112 | } |
| 113 | - $ret=$problemModel->addSolution($pid,Auth::user()->id,$content); |
|
| 114 | - return $ret?ResponseModel::success(200):ResponseModel::err(3003); |
|
| 113 | + $ret=$problemModel->addSolution($pid, Auth::user()->id, $content); |
|
| 114 | + return $ret ?ResponseModel::success(200) : ResponseModel::err(3003); |
|
| 115 | 115 | } |
| 116 | 116 | /** |
| 117 | 117 | * The Ajax Problem Solution Discussion Update. |
@@ -126,8 +126,8 @@ discard block |
||
| 126 | 126 | $problemModel=new ProblemModel(); |
| 127 | 127 | $psoid=$all_data["psoid"]; |
| 128 | 128 | $content=$all_data["content"]; |
| 129 | - $ret=$problemModel->updateSolution($psoid,Auth::user()->id,$content); |
|
| 130 | - return $ret?ResponseModel::success(200):ResponseModel::err(3004); |
|
| 129 | + $ret=$problemModel->updateSolution($psoid, Auth::user()->id, $content); |
|
| 130 | + return $ret ?ResponseModel::success(200) : ResponseModel::err(3004); |
|
| 131 | 131 | } |
| 132 | 132 | /** |
| 133 | 133 | * The Ajax Problem Solution Discussion Delete. |
@@ -141,8 +141,8 @@ discard block |
||
| 141 | 141 | $all_data=$request->all(); |
| 142 | 142 | $problemModel=new ProblemModel(); |
| 143 | 143 | $psoid=$all_data["psoid"]; |
| 144 | - $ret=$problemModel->removeSolution($psoid,Auth::user()->id); |
|
| 145 | - return $ret?ResponseModel::success(200):ResponseModel::err(3004); |
|
| 144 | + $ret=$problemModel->removeSolution($psoid, Auth::user()->id); |
|
| 145 | + return $ret ?ResponseModel::success(200) : ResponseModel::err(3004); |
|
| 146 | 146 | } |
| 147 | 147 | /** |
| 148 | 148 | * The Ajax Problem Solution Discussion Vote. |
@@ -157,8 +157,8 @@ discard block |
||
| 157 | 157 | $problemModel=new ProblemModel(); |
| 158 | 158 | $psoid=$all_data["psoid"]; |
| 159 | 159 | $type=$all_data["type"]; |
| 160 | - $ret=$problemModel->voteSolution($psoid,Auth::user()->id,$type); |
|
| 161 | - return $ret["ret"]?ResponseModel::success(200,null,["votes"=>$ret["votes"],"select"=>$ret["select"]]):ResponseModel::err(3004); |
|
| 160 | + $ret=$problemModel->voteSolution($psoid, Auth::user()->id, $type); |
|
| 161 | + return $ret["ret"] ?ResponseModel::success(200, null, ["votes"=>$ret["votes"], "select"=>$ret["select"]]) : ResponseModel::err(3004); |
|
| 162 | 162 | } |
| 163 | 163 | /** |
| 164 | 164 | * The Ajax Problem Solution Submit. |
@@ -251,15 +251,15 @@ discard block |
||
| 251 | 251 | |
| 252 | 252 | $submissionData=$submissionModel->basic($all_data["sid"]); |
| 253 | 253 | |
| 254 | - if($submissionData["uid"]!=Auth::user()->id){ |
|
| 254 | + if ($submissionData["uid"]!=Auth::user()->id) { |
|
| 255 | 255 | return ResponseModel::err(2001); |
| 256 | 256 | } |
| 257 | 257 | |
| 258 | - if($submissionData["verdict"]!="Submission Error"){ |
|
| 258 | + if ($submissionData["verdict"]!="Submission Error") { |
|
| 259 | 259 | return ResponseModel::err(6003); |
| 260 | 260 | } |
| 261 | 261 | |
| 262 | - $submissionModel->updateSubmission($all_data["sid"],[ |
|
| 262 | + $submissionModel->updateSubmission($all_data["sid"], [ |
|
| 263 | 263 | "verdict"=>"Pending", |
| 264 | 264 | "time"=>0, |
| 265 | 265 | "memory"=>0 |