Passed
Push — master ( 46d43a...ae46ae )
by John
09:19 queued 04:28
created
app/Http/Controllers/Contest/BoardController.php 2 patches
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -106,8 +106,8 @@  discard block
 block discarded – undo
106 106
             ];
107 107
         }
108 108
 
109
-        $editor_left_width = $accountModel->getExtra(Auth::user()->id, 'editor_left_width');
110
-        if(empty($editor_left_width)) $editor_left_width='40';
109
+        $editor_left_width=$accountModel->getExtra(Auth::user()->id, 'editor_left_width');
110
+        if (empty($editor_left_width)) $editor_left_width='40';
111 111
 
112 112
         return view('contest.board.editor', [
113 113
             'page_title'=>"Problem Detail",
@@ -151,14 +151,14 @@  discard block
 block discarded – undo
151 151
 
152 152
         // To determine the ranking
153 153
         foreach ($contestRank as $i => &$r) {
154
-            if($i != 0) {
155
-                if($r['score'] == $contestRank[$i-1]['score'] && $r['penalty'] == $contestRank[$i-1]['penalty']){
156
-                    $r['rank'] = $contestRank[$i-1]['rank'];
157
-                }else{
158
-                    $r['rank'] = $i + 1;
154
+            if ($i!=0) {
155
+                if ($r['score']==$contestRank[$i-1]['score'] && $r['penalty']==$contestRank[$i-1]['penalty']) {
156
+                    $r['rank']=$contestRank[$i-1]['rank'];
157
+                } else {
158
+                    $r['rank']=$i+1;
159 159
                 }
160
-            }else{
161
-                $r['rank'] = 1;
160
+            } else {
161
+                $r['rank']=1;
162 162
             }
163 163
         }
164 164
         $rankFrozen=$contestModel->isFrozen($cid);
@@ -278,7 +278,7 @@  discard block
 block discarded – undo
278 278
         ]);
279 279
     }
280 280
 
281
-    public function analysis($cid){
281
+    public function analysis($cid) {
282 282
         $contestModel=new ContestModel();
283 283
         $clearance=$contestModel->judgeClearance($cid, Auth::user()->id);
284 284
         if (!$clearance) {
Please login to merge, or discard this patch.
Braces   +5 added lines, -3 removed lines patch added patch discarded remove patch
@@ -107,7 +107,9 @@  discard block
 block discarded – undo
107 107
         }
108 108
 
109 109
         $editor_left_width = $accountModel->getExtra(Auth::user()->id, 'editor_left_width');
110
-        if(empty($editor_left_width)) $editor_left_width='40';
110
+        if(empty($editor_left_width)) {
111
+            $editor_left_width='40';
112
+        }
111 113
 
112 114
         return view('contest.board.editor', [
113 115
             'page_title'=>"Problem Detail",
@@ -154,10 +156,10 @@  discard block
 block discarded – undo
154 156
             if($i != 0) {
155 157
                 if($r['score'] == $contestRank[$i-1]['score'] && $r['penalty'] == $contestRank[$i-1]['penalty']){
156 158
                     $r['rank'] = $contestRank[$i-1]['rank'];
157
-                }else{
159
+                } else{
158 160
                     $r['rank'] = $i + 1;
159 161
                 }
160
-            }else{
162
+            } else{
161 163
                 $r['rank'] = 1;
162 164
             }
163 165
         }
Please login to merge, or discard this patch.
app/Http/Controllers/Ajax/GroupManageController.php 1 patch
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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"]);
Please login to merge, or discard this patch.
app/Models/GroupModel.php 2 patches
Spacing   +102 added lines, -102 removed lines patch added patch discarded remove patch
@@ -58,10 +58,10 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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"],
@@ -418,20 +418,20 @@  discard block
 block discarded – undo
418 418
 
419 419
     public function groupMemberPracticeContestStat($gid)
420 420
     {
421
-        $contestModel = new ContestModel();
421
+        $contestModel=new ContestModel();
422 422
 
423
-        $allPracticeContest = DB::table('contest')
423
+        $allPracticeContest=DB::table('contest')
424 424
             ->where([
425 425
                 'gid' => $gid,
426 426
                 'practice' => 1,
427 427
             ])
428
-            ->select('cid','name')
428
+            ->select('cid', 'name')
429 429
             ->get()->all();
430
-        $user_list = $this->userList($gid);
430
+        $user_list=$this->userList($gid);
431 431
 
432
-        $memberData = [];
432
+        $memberData=[];
433 433
         foreach ($user_list as $u) {
434
-            $memberData[$u['uid']] = [
434
+            $memberData[$u['uid']]=[
435 435
                 'name' => $u['name'],
436 436
                 'nick_name' => $u['nick_name'],
437 437
                 'elo' => $u['ranking'],
@@ -442,60 +442,60 @@  discard block
 block discarded – undo
442 442
             ];
443 443
         }
444 444
         foreach ($allPracticeContest as $c) {
445
-            $contestRankRaw = $contestModel->contestRank($c['cid']);
446
-            foreach($contestRankRaw as $key => $contestRank){
447
-                if(isset($contestRank['remote']) && $contestRank['remote']){
445
+            $contestRankRaw=$contestModel->contestRank($c['cid']);
446
+            foreach ($contestRankRaw as $key => $contestRank) {
447
+                if (isset($contestRank['remote']) && $contestRank['remote']) {
448 448
                     unset($contestRankRaw[$key]);
449 449
                 }
450 450
             }
451
-            $contestRank = array_values($contestRankRaw);
452
-            $problemsCount = DB::table('contest_problem')
453
-                ->where('cid',$c['cid'])
451
+            $contestRank=array_values($contestRankRaw);
452
+            $problemsCount=DB::table('contest_problem')
453
+                ->where('cid', $c['cid'])
454 454
                 ->count();
455
-            $index = 1;
456
-            $last_cr = [];
457
-            $last_rank = 1;
455
+            $index=1;
456
+            $last_cr=[];
457
+            $last_rank=1;
458 458
             foreach ($contestRank as $cr) {
459
-                $last_rank = $index;
460
-                if(!empty($last_cr)){
461
-                    if($cr['solved'] == $last_cr['solved'] && $cr['penalty'] == $last_cr['penalty'] ){
462
-                        $rank = $last_rank;
463
-                    }else{
464
-                        $rank = $index;
465
-                        $last_rank = $rank;
459
+                $last_rank=$index;
460
+                if (!empty($last_cr)) {
461
+                    if ($cr['solved']==$last_cr['solved'] && $cr['penalty']==$last_cr['penalty']) {
462
+                        $rank=$last_rank;
463
+                    } else {
464
+                        $rank=$index;
465
+                        $last_rank=$rank;
466 466
                     }
467 467
                 }
468
-                if(in_array($cr['uid'],array_keys($memberData))) {
469
-                    $memberData[$cr['uid']]['solved_all'] += $cr['solved'];
470
-                    $memberData[$cr['uid']]['problem_all'] += $problemsCount;
471
-                    $memberData[$cr['uid']]['penalty'] += $cr['penalty'];
472
-                    $memberData[$cr['uid']]['contest_detial'][$c['cid']] = [
468
+                if (in_array($cr['uid'], array_keys($memberData))) {
469
+                    $memberData[$cr['uid']]['solved_all']+=$cr['solved'];
470
+                    $memberData[$cr['uid']]['problem_all']+=$problemsCount;
471
+                    $memberData[$cr['uid']]['penalty']+=$cr['penalty'];
472
+                    $memberData[$cr['uid']]['contest_detial'][$c['cid']]=[
473 473
                         'rank' => $rank ?? 1,
474 474
                         'solved' => $cr['solved'],
475 475
                         'problems' => $problemsCount,
476 476
                         'penalty' => $cr['penalty']
477 477
                     ];
478 478
                 }
479
-                $last_cr = $cr;
479
+                $last_cr=$cr;
480 480
                 $index++;
481 481
             }
482 482
         }
483
-        $new_memberData = [];
483
+        $new_memberData=[];
484 484
         foreach ($memberData as $uid => $data) {
485
-            $contest_count = 0;
486
-            $rank_sum = 0;
485
+            $contest_count=0;
486
+            $rank_sum=0;
487 487
             foreach ($data['contest_detial'] as $cid => $c) {
488
-                $rank_sum += $c['rank'];
489
-                $contest_count += 1;
488
+                $rank_sum+=$c['rank'];
489
+                $contest_count+=1;
490 490
             }
491
-            $temp = $data;
492
-            $temp['uid'] = $uid;
493
-            if($contest_count != 0){
494
-                $temp['rank_ave'] = $rank_sum/$contest_count;
491
+            $temp=$data;
492
+            $temp['uid']=$uid;
493
+            if ($contest_count!=0) {
494
+                $temp['rank_ave']=$rank_sum / $contest_count;
495 495
             }
496
-            array_push($new_memberData,$temp);
496
+            array_push($new_memberData, $temp);
497 497
         }
498
-        $ret = [
498
+        $ret=[
499 499
             'contest_list' => $allPracticeContest,
500 500
             'member_data' => $new_memberData
501 501
         ];
@@ -504,58 +504,58 @@  discard block
 block discarded – undo
504 504
 
505 505
     public function groupMemberPracticeTagStat($gid)
506 506
     {
507
-        $tags = $this->problemTags($gid);
508
-        $tag_problems = [];
507
+        $tags=$this->problemTags($gid);
508
+        $tag_problems=[];
509 509
 
510
-        $user_list = $this->userList($gid);
510
+        $user_list=$this->userList($gid);
511 511
         foreach ($tags as $tag) {
512
-            $tag_problems[$tag] = DB::table('problem')
513
-                ->join('group_problem_tag','problem.pid','=','group_problem_tag.pid')
512
+            $tag_problems[$tag]=DB::table('problem')
513
+                ->join('group_problem_tag', 'problem.pid', '=', 'group_problem_tag.pid')
514 514
                 ->where([
515 515
                     'group_problem_tag.gid' => $gid,
516 516
                     'tag' => $tag
517 517
                 ])
518
-                ->select('group_problem_tag.pid as pid','pcode','title')
518
+                ->select('group_problem_tag.pid as pid', 'pcode', 'title')
519 519
                 ->get()->all();
520 520
         }
521
-        $all_problems = [];
521
+        $all_problems=[];
522 522
         foreach ($tag_problems as &$tag_problem_set) {
523 523
             foreach ($tag_problem_set as $problem) {
524
-                $all_problems[$problem['pid']] = $problem;
524
+                $all_problems[$problem['pid']]=$problem;
525 525
             }
526
-            $tag_problem_set = array_column($tag_problem_set,'pid');
526
+            $tag_problem_set=array_column($tag_problem_set, 'pid');
527 527
         }
528
-        $submission_data =  DB::table('submission')
529
-            ->whereIn('pid',array_keys($all_problems))
530
-            ->whereIn('uid',array_column($user_list,'uid'))
531
-            ->where('verdict','Accepted')
532
-            ->select('pid','uid')
528
+        $submission_data=DB::table('submission')
529
+            ->whereIn('pid', array_keys($all_problems))
530
+            ->whereIn('uid', array_column($user_list, 'uid'))
531
+            ->where('verdict', 'Accepted')
532
+            ->select('pid', 'uid')
533 533
             ->get()->all();
534 534
 
535
-        $memberData = [];
535
+        $memberData=[];
536 536
         foreach ($user_list as $member) {
537
-            $completion = [];
538
-            foreach($tag_problems as $tag => $problems) {
539
-                $completion[$tag] = [];
537
+            $completion=[];
538
+            foreach ($tag_problems as $tag => $problems) {
539
+                $completion[$tag]=[];
540 540
                 foreach ($problems as $problem) {
541
-                    $is_accepted = 0;
541
+                    $is_accepted=0;
542 542
                     foreach ($submission_data as $sd) {
543
-                        if($sd['pid'] == $problem && $sd['uid'] == $member['uid']){
544
-                            $is_accepted = 1;
543
+                        if ($sd['pid']==$problem && $sd['uid']==$member['uid']) {
544
+                            $is_accepted=1;
545 545
                             break;
546 546
                         }
547 547
                     }
548
-                    $completion[$tag][$problem] = $is_accepted;
548
+                    $completion[$tag][$problem]=$is_accepted;
549 549
                 }
550 550
             }
551
-            array_push($memberData,[
551
+            array_push($memberData, [
552 552
                 'uid' => $member['uid'],
553 553
                 'name' => $member['name'],
554 554
                 'nick_name' => $member['nick_name'],
555 555
                 'completion' => $completion,
556 556
             ]);
557 557
         }
558
-        $ret = [
558
+        $ret=[
559 559
             'all_problems' => $all_problems,
560 560
             'tag_problems' => $tag_problems,
561 561
             'member_data' => $memberData
@@ -566,29 +566,29 @@  discard block
 block discarded – undo
566 566
     public function refreshElo($gid)
567 567
     {
568 568
         DB::table('group_rated_change_log')
569
-            ->where('gid',$gid)
569
+            ->where('gid', $gid)
570 570
             ->delete();
571 571
         DB::table('group_member')
572
-            ->where('gid',$gid)
572
+            ->where('gid', $gid)
573 573
             ->update([
574 574
                 'ranking' => 1500
575 575
             ]);
576
-        $contests = DB::table('contest')
576
+        $contests=DB::table('contest')
577 577
             ->where([
578 578
                 'gid' => $gid,
579 579
                 'practice' => 1
580 580
             ])
581
-            ->where('end_time','<',date("Y-m-d H:i:s"))
581
+            ->where('end_time', '<', date("Y-m-d H:i:s"))
582 582
             ->select('cid')
583 583
             ->orderBy('end_time')
584 584
             ->get()->all();
585 585
 
586
-        if(empty($contests)) {
586
+        if (empty($contests)) {
587 587
             return true;
588 588
         }
589 589
 
590 590
         foreach ($contests as $contest) {
591
-            $calc = new GroupRatingCalculator($contest['cid']);
591
+            $calc=new GroupRatingCalculator($contest['cid']);
592 592
             $calc->calculate();
593 593
             $calc->storage();
594 594
         }
Please login to merge, or discard this patch.
Braces   +12 added lines, -6 removed lines patch added patch discarded remove patch
@@ -115,7 +115,9 @@  discard block
 block discarded – undo
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)) {
119
+            return [];
120
+        }
119 121
         $basic_info["members"]=$this->countGroupMembers($basic_info["gid"]);
120 122
         $basic_info["tags"]=$this->getGroupTags($basic_info["gid"]);
121 123
         $basic_info["create_time_foramt"]=date_format(date_create($basic_info["create_time"]), 'M jS, Y');
@@ -163,7 +165,9 @@  discard block
 block discarded – undo
163 165
         foreach ($user_list as &$u) {
164 166
             $u["role_parsed"]=$this->role[$u["role"]];
165 167
             $u["role_color"]=$this->role_color[$u["role"]];
166
-            if(is_null($u["sub_group"])) $u["sub_group"]="None";
168
+            if(is_null($u["sub_group"])) {
169
+                $u["sub_group"]="None";
170
+            }
167 171
         }
168 172
         return $user_list;
169 173
     }
@@ -232,7 +236,7 @@  discard block
 block discarded – undo
232 236
             ->where('gid',$gid)
233 237
             ->distinct()
234 238
             ->get()->all();
235
-        }else{
239
+        } else{
236 240
             $tags =  DB::table('group_problem_tag')
237 241
             ->select('tag')
238 242
             ->where('gid', $gid)
@@ -266,7 +270,7 @@  discard block
 block discarded – undo
266 270
         foreach($problems as $key => $value){
267 271
             if($contestModel->judgeClearance($value['cid'],$user_id) != 3){
268 272
                 unset($problems[$key]);
269
-            }else{
273
+            } else{
270 274
                 $problems[$key]['tags'] = $this->problemTags($gid,$value['pid']);
271 275
             }
272 276
         }
@@ -327,7 +331,9 @@  discard block
 block discarded – undo
327 331
     public function judgeEmailClearance($gid, $email)
328 332
     {
329 333
         $user=DB::table("users")->where(["email"=>$email])->first();
330
-        if(empty($user)) return -4;
334
+        if(empty($user)) {
335
+            return -4;
336
+        }
331 337
         $ret=DB::table("group_member")->where([
332 338
             "gid"=>$gid,
333 339
             "uid"=>$user["id"],
@@ -460,7 +466,7 @@  discard block
 block discarded – undo
460 466
                 if(!empty($last_cr)){
461 467
                     if($cr['solved'] == $last_cr['solved'] && $cr['penalty'] == $last_cr['penalty'] ){
462 468
                         $rank = $last_rank;
463
-                    }else{
469
+                    } else{
464 470
                         $rank = $index;
465 471
                         $last_rank = $rank;
466 472
                     }
Please login to merge, or discard this patch.
app/Models/Rating/GroupRatingCalculator.php 1 patch
Spacing   +85 added lines, -85 removed lines patch added patch discarded remove patch
@@ -14,37 +14,37 @@  discard block
 block discarded – undo
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){
47
-            if(!isset($ratings[$c['uid']])){
46
+        foreach ($contestRankRaw as $c) {
47
+            if (!isset($ratings[$c['uid']])) {
48 48
                 continue;
49 49
             }
50 50
             $this->contestants[]=[
@@ -55,84 +55,84 @@  discard block
 block discarded – undo
55 55
         }
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
 block discarded – undo
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
 block discarded – undo
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
                     }
Please login to merge, or discard this patch.