Completed
Push — master ( a4261d...fc5e52 )
by John
14s
created
app/Models/Rating/RatingCalculator.php 2 patches
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -78,7 +78,7 @@
 block discarded – undo
78 78
             $mid = floor(($right + $left)/2);
79 79
             if($this->getSeed($mid) < $rank){
80 80
                 $right = $mid;
81
-            }else{
81
+            } else{
82 82
                 $left = $mid;
83 83
             }
84 84
         }
Please login to merge, or discard this patch.
Spacing   +70 added lines, -70 removed lines patch added patch discarded remove patch
@@ -17,14 +17,14 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
                     }
Please login to merge, or discard this patch.
app/Models/SubmissionModel.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -412,7 +412,7 @@  discard block
 block discarded – undo
412 412
                                             ->where(['verdict'=>'Waiting'])
413 413
                                             ->get()
414 414
                                             ->all();
415
-        foreach($ret as &$r){
415
+        foreach ($ret as &$r) {
416 416
             $r["ocode"]=DB::table("oj")->where(["oid"=>$r["oid"]])->first()["ocode"];
417 417
         }
418 418
         return $ret;
@@ -430,15 +430,15 @@  discard block
 block discarded – undo
430 430
         if (isset($sub['verdict'])) {
431 431
             $sub["color"]=$this->colorScheme[$sub['verdict']];
432 432
         }
433
-        $result = DB::table($this->tableName)->where(['sid'=>$sid])->update($sub);
434
-
435
-        $contestModel = new ContestModel();
436
-        $submission_info = DB::table($this->tableName) -> where(['sid'=>$sid]) -> get() -> first();
437
-        if ($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
-            $contestModel->updateContestRankTable($submission_info['cid'],$sub);
433
+        $result=DB::table($this->tableName)->where(['sid'=>$sid])->update($sub);
434
+
435
+        $contestModel=new ContestModel();
436
+        $submission_info=DB::table($this->tableName) -> where(['sid'=>$sid]) -> get() -> first();
437
+        if ($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
+            $contestModel->updateContestRankTable($submission_info['cid'], $sub);
442 442
         }
443 443
         return $result;
444 444
     }
@@ -509,15 +509,15 @@  discard block
 block discarded – undo
509 509
             'desc'
510 510
         );
511 511
 
512
-        if($filter["pcode"]){
512
+        if ($filter["pcode"]) {
513 513
             $paginator=$paginator->where(["pcode"=>$filter["pcode"]]);
514 514
         }
515 515
 
516
-        if($filter["result"]){
516
+        if ($filter["result"]) {
517 517
             $paginator=$paginator->where(["verdict"=>$filter["result"]]);
518 518
         }
519 519
 
520
-        if($filter["account"]){
520
+        if ($filter["account"]) {
521 521
             $paginator=$paginator->where(["name"=>$filter["account"]]);
522 522
         }
523 523
 
Please login to merge, or discard this patch.
app/Babel/Submit/Submitter.php 2 patches
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -35,7 +35,9 @@
 block discarded – undo
35 35
         ];
36 36
 
37 37
         $submitter=self::create($this->post_data["oj"], $sub, $all_data);
38
-        if(!is_null($submitter)) $submitter->submit();
38
+        if(!is_null($submitter)) {
39
+            $submitter->submit();
40
+        }
39 41
 
40 42
         // insert submission
41 43
 
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
         ];
33 33
 
34 34
         $submitter=self::create($this->post_data["oj"], $sub, $all_data);
35
-        if(!is_null($submitter)) $submitter->submit();
35
+        if (!is_null($submitter)) $submitter->submit();
36 36
 
37 37
         // insert submission
38 38
 
@@ -40,16 +40,16 @@  discard block
 block discarded – undo
40 40
         $submission->updateSubmission($this->post_data["sid"], $sub);
41 41
     }
42 42
 
43
-    public static function create($oj,& $sub, $all_data) {
43
+    public static function create($oj, & $sub, $all_data) {
44 44
         $submitterProvider="Submitter";
45 45
         try {
46 46
             $BabelConfig=json_decode(file_get_contents(babel_path("Extension/$oj/babel.json")), true);
47 47
             $submitterProvider=$BabelConfig["provider"]["submitter"];
48
-        } catch(ErrorException $e) {
49
-        } catch(Exception $e) {
48
+        } catch (ErrorException $e) {
49
+        } catch (Exception $e) {
50 50
         }
51
-        $className = "App\\Babel\\Extension\\$oj\\$submitterProvider";
52
-        if(class_exists($className)) {
51
+        $className="App\\Babel\\Extension\\$oj\\$submitterProvider";
52
+        if (class_exists($className)) {
53 53
             return new $className($sub, $all_data);
54 54
         } else {
55 55
             return null;
Please login to merge, or discard this patch.
app/Models/ResponseModel.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -91,7 +91,7 @@
 block discarded – undo
91 91
             '7002' => "Insufficient Clearance",
92 92
             '7003' => "No Need to Approve",
93 93
             '7004' => "Group Member Not Found",
94
-            '7005' => "Don't play just for fun",//gcode=="create"
94
+            '7005' => "Don't play just for fun", //gcode=="create"
95 95
             '7006' => "A group with the same gcode already exists",
96 96
             '7007' => "Group Problem Tag Exist",
97 97
         ];
Please login to merge, or discard this patch.
app/Models/Rating/GroupRatingCalculator.php 2 patches
Spacing   +81 added lines, -81 removed lines patch added patch discarded remove patch
@@ -14,30 +14,30 @@  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
-        $this->totParticipants = count($contestRankRaw);
29
-        $members = array_column($contestRankRaw,'uid');
30
-        $ratings_temp = DB::table('group_member')
25
+    private function getRecord() {
26
+        $contestModel=new ContestModel();
27
+        $contestRankRaw=$contestModel->contestRank($this->cid);
28
+        $this->totParticipants=count($contestRankRaw);
29
+        $members=array_column($contestRankRaw, 'uid');
30
+        $ratings_temp=DB::table('group_member')
31 31
             ->where([
32 32
                 'gid' => $this->gid,
33
-            ])->whereIn('uid',$members)
34
-            ->select('uid','ranking')
33
+            ])->whereIn('uid', $members)
34
+            ->select('uid', 'ranking')
35 35
             ->get()->all();
36
-        $ratings = [];
36
+        $ratings=[];
37 37
         foreach ($ratings_temp as $rating) {
38
-            $ratings[$rating['uid']] = $rating['ranking'];
38
+            $ratings[$rating['uid']]=$rating['ranking'];
39 39
         }
40
-        foreach($contestRankRaw as $c){
40
+        foreach ($contestRankRaw as $c) {
41 41
             $this->contestants[]=[
42 42
                 "uid"=>$c["uid"],
43 43
                 "points"=>$c["score"],
@@ -46,84 +46,84 @@  discard block
 block discarded – undo
46 46
         }
47 47
     }
48 48
 
49
-    private function reassignRank(){
49
+    private function reassignRank() {
50 50
         $this->sort("points");
51
-        $idx = 0;
52
-        $points = $this->contestants[0]["points"];
53
-        $i = 1;
54
-        while($i < $this->totParticipants){
55
-            if($this->contestants[$i]["points"] < $points){
56
-                $j = $idx;
57
-                while($j < $i){
58
-                    $this->contestants[$j]["rank"] = $i;
59
-                    $j += 1;
51
+        $idx=0;
52
+        $points=$this->contestants[0]["points"];
53
+        $i=1;
54
+        while ($i<$this->totParticipants) {
55
+            if ($this->contestants[$i]["points"]<$points) {
56
+                $j=$idx;
57
+                while ($j<$i) {
58
+                    $this->contestants[$j]["rank"]=$i;
59
+                    $j+=1;
60 60
                 }
61
-                $idx = $i;
62
-                $points = $this->contestants[$i]["points"];
61
+                $idx=$i;
62
+                $points=$this->contestants[$i]["points"];
63 63
             }
64
-            $i += 1;
64
+            $i+=1;
65 65
         }
66
-        $j = $idx;
67
-        while($j < $this->totParticipants){
68
-            $this->contestants[$j]["rank"] = $this->totParticipants;
69
-            $j += 1;
66
+        $j=$idx;
67
+        while ($j<$this->totParticipants) {
68
+            $this->contestants[$j]["rank"]=$this->totParticipants;
69
+            $j+=1;
70 70
         }
71 71
     }
72 72
 
73
-    private function getEloWinProbability($Ra, $Rb){
74
-        return 1.0 / (1 + pow(10, ($Rb-$Ra)/400.0));
73
+    private function getEloWinProbability($Ra, $Rb) {
74
+        return 1.0 / (1+pow(10, ($Rb-$Ra) / 400.0));
75 75
     }
76 76
 
77
-    private function getSeed($rating){
78
-        $result = 1.0;
79
-        foreach($this->contestants as $other){
80
-            $result += $this->getEloWinProbability($other["rating"], $rating);
77
+    private function getSeed($rating) {
78
+        $result=1.0;
79
+        foreach ($this->contestants as $other) {
80
+            $result+=$this->getEloWinProbability($other["rating"], $rating);
81 81
         }
82 82
         return $result;
83 83
     }
84 84
 
85
-    private function getRatingToRank($rank){
85
+    private function getRatingToRank($rank) {
86 86
         $left=1;
87 87
         $right=8000;
88
-        while($right - $left > 1){
89
-            $mid = floor(($right + $left)/2);
90
-            if($this->getSeed($mid) < $rank){
91
-                $right = $mid;
92
-            }else{
93
-                $left = $mid;
88
+        while ($right-$left>1) {
89
+            $mid=floor(($right+$left) / 2);
90
+            if ($this->getSeed($mid)<$rank) {
91
+                $right=$mid;
92
+            } else {
93
+                $left=$mid;
94 94
             }
95 95
         }
96 96
         return $left;
97 97
     }
98 98
 
99
-    private function sort($key){
100
-        usort($this->contestants, function ($a, $b) use ($key) {
99
+    private function sort($key) {
100
+        usort($this->contestants, function($a, $b) use ($key) {
101 101
             return $b[$key] <=> $a[$key];
102 102
         });
103 103
     }
104 104
 
105
-    public function calculate(){
106
-        if(empty($this->contestants)){
105
+    public function calculate() {
106
+        if (empty($this->contestants)) {
107 107
             return;
108 108
         }
109 109
 
110 110
         // recalc rank
111 111
         $this->reassignRank();
112 112
 
113
-        foreach($this->contestants as &$member){
114
-            $member["seed"] = 1.0;
115
-            foreach($this->contestants as $other){
116
-                if($member["uid"] != $other["uid"]){
117
-                    $member["seed"] += $this->getEloWinProbability($other["rating"], $member["rating"]);
113
+        foreach ($this->contestants as &$member) {
114
+            $member["seed"]=1.0;
115
+            foreach ($this->contestants as $other) {
116
+                if ($member["uid"]!=$other["uid"]) {
117
+                    $member["seed"]+=$this->getEloWinProbability($other["rating"], $member["rating"]);
118 118
                 }
119 119
             }
120 120
         }
121 121
         unset($member);
122 122
 
123
-        foreach($this->contestants as &$contestant){
124
-            $midRank = sqrt($contestant["rank"] * $contestant["seed"]);
125
-            $contestant["needRating"] = $this->getRatingToRank($midRank);
126
-            $contestant["delta"] = floor(($contestant["needRating"] - $contestant["rating"])/2);
123
+        foreach ($this->contestants as &$contestant) {
124
+            $midRank=sqrt($contestant["rank"] * $contestant["seed"]);
125
+            $contestant["needRating"]=$this->getRatingToRank($midRank);
126
+            $contestant["delta"]=floor(($contestant["needRating"]-$contestant["rating"]) / 2);
127 127
         }
128 128
         unset($contestant);
129 129
 
@@ -131,39 +131,39 @@  discard block
 block discarded – undo
131 131
 
132 132
         // DO some adjuct
133 133
         // Total sum should not be more than ZERO.
134
-        $sum = 0;
134
+        $sum=0;
135 135
 
136
-        foreach($this->contestants as $contestant){
137
-            $sum += $contestant["delta"];
136
+        foreach ($this->contestants as $contestant) {
137
+            $sum+=$contestant["delta"];
138 138
         }
139
-        $inc = -floor($sum / $this->totParticipants) - 1;
140
-        foreach($this->contestants as &$contestant){
141
-            $contestant["delta"] += $inc;
139
+        $inc=-floor($sum / $this->totParticipants)-1;
140
+        foreach ($this->contestants as &$contestant) {
141
+            $contestant["delta"]+=$inc;
142 142
         }
143 143
         unset($contestant);
144 144
 
145 145
         // Sum of top-4*sqrt should be adjusted to ZERO.
146 146
 
147
-        $sum = 0;
148
-        $zeroSumCount = min(intval(4*round(sqrt($this->totParticipants))), $this->totParticipants);
147
+        $sum=0;
148
+        $zeroSumCount=min(intval(4 * round(sqrt($this->totParticipants))), $this->totParticipants);
149 149
 
150
-        for($i=0;$i<$zeroSumCount;$i++){
151
-            $sum += $this->contestants[$i]["delta"];
150
+        for ($i=0; $i<$zeroSumCount; $i++) {
151
+            $sum+=$this->contestants[$i]["delta"];
152 152
         }
153 153
 
154
-        $inc = min(max(-floor($sum / $zeroSumCount), -10), 0);
154
+        $inc=min(max(-floor($sum / $zeroSumCount), -10), 0);
155 155
 
156
-        for($i=0;$i<$zeroSumCount;$i++){
157
-            $this->contestants[$i]["delta"] += $inc;
156
+        for ($i=0; $i<$zeroSumCount; $i++) {
157
+            $this->contestants[$i]["delta"]+=$inc;
158 158
         }
159 159
 
160 160
         return $this->validateDeltas();
161 161
     }
162 162
 
163
-    public function storage(){
163
+    public function storage() {
164 164
         $contestants=$this->contestants;
165
-        DB::transaction(function () use ($contestants) {
166
-            foreach($contestants as $contestant){
165
+        DB::transaction(function() use ($contestants) {
166
+            foreach ($contestants as $contestant) {
167 167
                 $newRating=$contestant["rating"]+$contestant["delta"];
168 168
                 DB::table("group_member")->where([
169 169
                     'gid' => $this->gid,
@@ -181,20 +181,20 @@  discard block
 block discarded – undo
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
                     }
Please login to merge, or discard this patch.
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -78,7 +78,7 @@
 block discarded – undo
78 78
             $mid = floor(($right + $left)/2);
79 79
             if($this->getSeed($mid) < $rank){
80 80
                 $right = $mid;
81
-            }else{
81
+            } else{
82 82
                 $left = $mid;
83 83
             }
84 84
         }
Please login to merge, or discard this patch.
app/Models/JudgerModel.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
     {
84 84
         $serverList=DB::table("judge_server")->where(["oid"=>$oid])->get()->all();
85 85
         foreach ($serverList as &$server) {
86
-            $server["status_parsed"]=is_null($server["status"])?self::$status["-1"]:self::$status[$server["status"]];
86
+            $server["status_parsed"]=is_null($server["status"]) ?self::$status["-1"] : self::$status[$server["status"]];
87 87
         }
88 88
         return $serverList;
89 89
     }
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
     {
93 93
         $serverList=DB::table("judge_server")->where(["oid"=>$oid])->get()->all();
94 94
         foreach ($serverList as $server) {
95
-            if($server["available"]==0){
95
+            if ($server["available"]==0) {
96 96
                 DB::table("judge_server")->where(["jsid"=>$server["jsid"]])->update([
97 97
                     "status"=>-2,
98 98
                     "status_update_at"=>date("Y-m-d H:i:s")
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
     {
133 133
         $curl=curl_init();
134 134
 
135
-        if($curl===false) return [];
135
+        if ($curl===false) return [];
136 136
 
137 137
         curl_setopt_array($curl, array(
138 138
             CURLOPT_PORT => $port,
Please login to merge, or discard this patch.
app/Models/CompilerModel.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -100,11 +100,11 @@
 block discarded – undo
100 100
 
101 101
     public static function add($row)
102 102
     {
103
-        if(self::checkExist([
103
+        if (self::checkExist([
104 104
             "oid"=>$row["oid"],
105 105
             "lcode"=>$row["lcode"],
106 106
             "deleted"=>0
107
-        ])){
107
+        ])) {
108 108
             throw new Exception("Duplicate Language Code");
109 109
         }
110 110
         return DB::table('compiler')->insert($row);
Please login to merge, or discard this patch.
app/Models/ContestModel.php 3 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -265,7 +265,7 @@
 block discarded – undo
265 265
                             $query=$query->where(["practice"=>$filter['practice']]);
266 266
                         }
267 267
                         $query->where('public', 1)
268
-                              ->where('audit_status', 1);
268
+                                ->where('audit_status', 1);
269 269
                     }
270 270
                 )
271 271
                 ->orWhere(
Please login to merge, or discard this patch.
Braces   +22 added lines, -23 removed lines patch added patch discarded remove patch
@@ -211,7 +211,7 @@  discard block
 block discarded – undo
211 211
                     $paginator=$paginator->where(["practice"=>$filter['practice']]);
212 212
                 }
213 213
                 $paginator = $paginator ->paginate(10);
214
-            }elseif($filter['public']=='0'){
214
+            } elseif($filter['public']=='0'){
215 215
                 $paginator=DB::table('group_member')
216 216
                 ->groupBy('contest.cid')
217 217
                 ->select('contest.*')
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
                 )
242 242
                 ->orderBy('contest.begin_time', 'desc')
243 243
                 ->paginate(10);
244
-            }else{
244
+            } else{
245 245
                 $paginator=DB::table('group_member')
246 246
                 ->groupBy('contest.cid')
247 247
                 ->select('contest.*')
@@ -786,19 +786,19 @@  discard block
 block discarded – undo
786 786
         if(time() < $end_time){
787 787
             if($clearance == 3){
788 788
                 $contestRankRaw=Cache::tags(['contest', 'rank'])->get("contestAdmin$cid");
789
-            }else{
789
+            } else{
790 790
                 $contestRankRaw=Cache::tags(['contest', 'rank'])->get($cid);
791 791
             }
792 792
             if(!isset($contestRankRaw)){
793 793
                 $contestRankRaw=$this->contestRankCache($cid);
794 794
             }
795
-        }else{
795
+        } else{
796 796
             if($clearance == 3){
797 797
                 $contestRankRaw=Cache::tags(['contest', 'rank'])->get("contestAdmin$cid");
798 798
                 if (!isset($contestRankRaw)) {
799 799
                     $contestRankRaw=$this->contestRankCache($cid);
800 800
                 }
801
-            }else{
801
+            } else{
802 802
                 $contestRankRaw=$this->getContestRankFromMySQL($cid);
803 803
                 if(!isset($contestRankRaw)){
804 804
                     $contestRankRaw=Cache::tags(['contest', 'rank'])->get($cid);
@@ -872,7 +872,7 @@  discard block
 block discarded – undo
872 872
             return DB::table("contest_clarification")->where([
873 873
                 "cid"=>$cid
874 874
             ])->orderBy('create_time', 'desc')->get()->all();
875
-        }else{
875
+        } else{
876 876
             return DB::table("contest_clarification")->where([
877 877
                 "cid"=>$cid
878 878
             ])->where(function ($query) {
@@ -1105,7 +1105,7 @@  discard block
 block discarded – undo
1105 1105
                     "records"=>[]
1106 1106
                 ];
1107 1107
             }
1108
-        }else{
1108
+        } else{
1109 1109
             if ($basicInfo["status_visibility"]==2) {
1110 1110
                 // View all
1111 1111
                 $paginator=DB::table("submission")->where([
@@ -1327,7 +1327,7 @@  discard block
 block discarded – undo
1327 1327
             if($ratingCalculator->calculate()){
1328 1328
                 $ratingCalculator->storage();
1329 1329
                 return true;
1330
-            }else{
1330
+            } else{
1331 1331
                 return false;
1332 1332
             }
1333 1333
         } else {
@@ -1424,8 +1424,7 @@  discard block
 block discarded – undo
1424 1424
                         Cache::tags(['contest', 'rank'])->put($cid, $ret);
1425 1425
                     }
1426 1426
                     Cache::tags(['contest', 'rank'])->put("contestAdmin$cid", $ret);
1427
-                }
1428
-                else{
1427
+                } else{
1429 1428
                     $ret=[];
1430 1429
                     $chache=[];
1431 1430
                     $chache['contest_info']=DB::table("contest")->where("cid", $cid)->first();
@@ -1442,7 +1441,7 @@  discard block
 block discarded – undo
1442 1441
                             "cid"=>$cid,
1443 1442
                             "audit"=>1
1444 1443
                         ])->select('uid')->get()->all();
1445
-                    }else{
1444
+                    } else{
1446 1445
                         $submissionUsers=DB::table("submission")->where([
1447 1446
                             "cid"=>$cid
1448 1447
                         ])->where(
@@ -1477,9 +1476,9 @@  discard block
 block discarded – undo
1477 1476
                     Cache::tags(['contest', 'rank'])->put("contestAdmin$cid", $retAdmin);
1478 1477
                 }
1479 1478
             }
1480
-        }catch(LockTimeoutException $e){
1479
+        } catch(LockTimeoutException $e){
1481 1480
             Log::warning("Contest Rank Lock Timed Out");
1482
-        }finally{
1481
+        } finally{
1483 1482
             optional($lock)->release();
1484 1483
         }
1485 1484
     }
@@ -1502,7 +1501,7 @@  discard block
 block discarded – undo
1502 1501
                     return 1;
1503 1502
                 }
1504 1503
             });
1505
-        }else if ($contest_info["rule"]==2){
1504
+        } else if ($contest_info["rule"]==2){
1506 1505
             usort($ret, function ($a, $b) {
1507 1506
                 if ($a["score"]==$b["score"]) {
1508 1507
                     if ($a["solved"]==$b["solved"]) {
@@ -1526,8 +1525,9 @@  discard block
 block discarded – undo
1526 1525
     {
1527 1526
         $id = count($ret);
1528 1527
         foreach($ret as $key => $r){
1529
-            if($r['uid'] == $uid)
1530
-                $id = $key;
1528
+            if($r['uid'] == $uid) {
1529
+                            $id = $key;
1530
+            }
1531 1531
         }
1532 1532
         if ($contest_info["rule"]==1) {
1533 1533
             // ACM/ICPC Mode
@@ -1535,7 +1535,7 @@  discard block
 block discarded – undo
1535 1535
                     $prob_detail = [];
1536 1536
                     $totPen = 0;
1537 1537
                     $totScore = 0;
1538
-                }else{
1538
+                } else{
1539 1539
                     $prob_detail = $ret[$id]['problem_detail'];
1540 1540
                     $totPen=$ret[$id]['penalty'];
1541 1541
                     $totScore=$ret[$id]['score'];
@@ -1575,7 +1575,7 @@  discard block
 block discarded – undo
1575 1575
                 $prob_detail = [];
1576 1576
                 $totSolved = 0;
1577 1577
                 $totScore = 0;
1578
-            }else{
1578
+            } else{
1579 1579
                 $prob_detail = $ret[$id]['problem_detail'];
1580 1580
                 $totSolved=$ret[$id]['solved'];
1581 1581
                 $totScore=$ret[$id]['score'];
@@ -1638,18 +1638,18 @@  discard block
 block discarded – undo
1638 1638
                 return false;
1639 1639
             }
1640 1640
             return true;
1641
-        }else if($status === 0){
1641
+        } else if($status === 0){
1642 1642
             if($begin_time_new !== null){
1643 1643
                 return false;
1644 1644
             }
1645 1645
             if($end_time_new !== null){
1646 1646
                 if(strtotime($end_time_new) <= time()){
1647 1647
                     return false;
1648
-                }else{
1648
+                } else{
1649 1649
                     return true;
1650 1650
                 }
1651 1651
             }
1652
-        }else{
1652
+        } else{
1653 1653
             return false;
1654 1654
         }
1655 1655
 
@@ -1670,8 +1670,7 @@  discard block
 block discarded – undo
1670 1670
             return DB::table("contest_clarification")->where('ccid','=',$ccid)->update([
1671 1671
                 "public"=>1
1672 1672
             ]);
1673
-        }
1674
-        else
1673
+        } else
1675 1674
         {
1676 1675
             return DB::table("contest_clarification")->where('ccid','=',$ccid)->update([
1677 1676
                 "public"=>0
Please login to merge, or discard this patch.
Spacing   +178 added lines, -178 removed lines patch added patch discarded remove patch
@@ -111,8 +111,8 @@  discard block
 block discarded – undo
111 111
 
112 112
     public function gcode($cid)
113 113
     {
114
-        $gid = $this->gid($cid);
115
-        return DB::table('group')->where('gid','=',$gid)->first()["gcode"];
114
+        $gid=$this->gid($cid);
115
+        return DB::table('group')->where('gid', '=', $gid)->first()["gcode"];
116 116
     }
117 117
 
118 118
     public function runningContest()
@@ -130,19 +130,19 @@  discard block
 block discarded – undo
130 130
 
131 131
     public function listForSetting($gid)
132 132
     {
133
-        $uid = Auth::user()->id;
134
-        $group_contests = DB::table('contest')
135
-            ->where('gid',$gid)
136
-            ->orderBy('begin_time','desc')
133
+        $uid=Auth::user()->id;
134
+        $group_contests=DB::table('contest')
135
+            ->where('gid', $gid)
136
+            ->orderBy('begin_time', 'desc')
137 137
             ->get()->all();
138
-        $groupModel = new GroupModel();
139
-        $group_clearance = $groupModel->judgeClearance($gid,$uid);
138
+        $groupModel=new GroupModel();
139
+        $group_clearance=$groupModel->judgeClearance($gid, $uid);
140 140
         foreach ($group_contests as &$contest) {
141
-            $contest['is_admin'] = ($contest['assign_uid'] == $uid || $group_clearance == 3);
142
-            $begin_stamps = strtotime($contest['begin_time']);
143
-            $end_stamps = strtotime($contest['end_time']);
144
-            $contest['status'] = time() >= $end_stamps ? 1
145
-                : (time() <= $begin_stamps ? -1 : 0);
141
+            $contest['is_admin']=($contest['assign_uid']==$uid || $group_clearance==3);
142
+            $begin_stamps=strtotime($contest['begin_time']);
143
+            $end_stamps=strtotime($contest['end_time']);
144
+            $contest['status']=time()>=$end_stamps ? 1
145
+                : (time()<=$begin_stamps ? -1 : 0);
146 146
             $contest["rule_parsed"]=$this->rule[$contest["rule"]];
147 147
             $contest["date_parsed"]=[
148 148
                 "date"=>date_format(date_create($contest["begin_time"]), 'j'),
@@ -159,9 +159,9 @@  discard block
 block discarded – undo
159 159
         //     "gid"=>$gid
160 160
         // ])->orderBy('begin_time', 'desc')->get()->all();
161 161
         $preQuery=DB::table($this->tableName);
162
-        $paginator=$preQuery->where('gid','=',$gid)->orderBy('begin_time', 'desc')->paginate(10);
162
+        $paginator=$preQuery->where('gid', '=', $gid)->orderBy('begin_time', 'desc')->paginate(10);
163 163
         $contest_list=$paginator->all();
164
-        if(empty($contest_list)){
164
+        if (empty($contest_list)) {
165 165
             return null;
166 166
         }
167 167
 
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
         ])->first()["rule"];
187 187
     }
188 188
 
189
-    public function list($filter,$uid)
189
+    public function list($filter, $uid)
190 190
     {
191 191
         if ($uid) {
192 192
             //$paginator=DB::select('SELECT DISTINCT contest.* FROM group_member inner join contest on group_member.gid=contest.gid left join contest_participant on contest.cid=contest_participant.cid where (public=1 and audit=1) or (group_member.uid=:uid and group_member.role>0 and (contest_participant.uid=:uidd or ISNULL(contest_participant.uid)) and (registration=0 or (registration=1 and not ISNULL(contest_participant.uid))))',["uid"=>$uid,"uidd"=>$uid])->paginate(10);
@@ -210,15 +210,15 @@  discard block
 block discarded – undo
210 210
                 if ($filter['practice']) {
211 211
                     $paginator=$paginator->where(["practice"=>$filter['practice']]);
212 212
                 }
213
-                $paginator = $paginator ->paginate(10);
214
-            }elseif($filter['public']=='0'){
213
+                $paginator=$paginator ->paginate(10);
214
+            }elseif ($filter['public']=='0') {
215 215
                 $paginator=DB::table('group_member')
216 216
                 ->groupBy('contest.cid')
217 217
                 ->select('contest.*')
218 218
                 ->join('contest', 'group_member.gid', '=', 'contest.gid')
219 219
                 ->leftJoin('contest_participant', 'contest.cid', '=', 'contest_participant.cid')
220 220
                 ->where(
221
-                    function ($query) use ($filter,$uid) {
221
+                    function($query) use ($filter, $uid) {
222 222
                         if ($filter['rule']) {
223 223
                             $query=$query->where(["rule"=>$filter['rule']]);
224 224
                         }
@@ -241,14 +241,14 @@  discard block
 block discarded – undo
241 241
                 )
242 242
                 ->orderBy('contest.begin_time', 'desc')
243 243
                 ->paginate(10);
244
-            }else{
244
+            } else {
245 245
                 $paginator=DB::table('group_member')
246 246
                 ->groupBy('contest.cid')
247 247
                 ->select('contest.*')
248 248
                 ->join('contest', 'group_member.gid', '=', 'contest.gid')
249 249
                 ->leftJoin('contest_participant', 'contest.cid', '=', 'contest_participant.cid')
250 250
                 ->where(
251
-                    function ($query) use ($filter) {
251
+                    function($query) use ($filter) {
252 252
                         if ($filter['rule']) {
253 253
                             $query=$query->where(["rule"=>$filter['rule']]);
254 254
                         }
@@ -269,7 +269,7 @@  discard block
 block discarded – undo
269 269
                     }
270 270
                 )
271 271
                 ->orWhere(
272
-                    function ($query) use ($filter,$uid) {
272
+                    function($query) use ($filter, $uid) {
273 273
                         if ($filter['rule']) {
274 274
                             $query=$query->where(["rule"=>$filter['rule']]);
275 275
                         }
@@ -315,7 +315,7 @@  discard block
 block discarded – undo
315 315
             if ($filter['practice']) {
316 316
                 $paginator=$paginator->where(["practice"=>$filter['practice']]);
317 317
             }
318
-            $paginator = $paginator ->paginate(10);
318
+            $paginator=$paginator ->paginate(10);
319 319
         }
320 320
         $contest_list=$paginator->all();
321 321
         foreach ($contest_list as &$c) {
@@ -353,14 +353,14 @@  discard block
 block discarded – undo
353 353
         }
354 354
     }
355 355
 
356
-    public function registContest($cid,$uid)
356
+    public function registContest($cid, $uid)
357 357
     {
358 358
         $registered=DB::table("contest_participant")->where([
359 359
             "cid"=>$cid,
360 360
             "uid"=>$uid
361 361
         ])->first();
362 362
 
363
-        if(empty($registered)){
363
+        if (empty($registered)) {
364 364
             DB::table("contest_participant")->insert([
365 365
                 "cid"=>$cid,
366 366
                 "uid"=>$uid,
@@ -393,9 +393,9 @@  discard block
 block discarded – undo
393 393
     public function problems($cid)
394 394
     {
395 395
         return DB::table('contest_problem')
396
-            ->join('problem','contest_problem.pid','=','problem.pid')
397
-            ->where('cid',$cid)
398
-            ->select('problem.pid as pid','pcode','number')
396
+            ->join('problem', 'contest_problem.pid', '=', 'problem.pid')
397
+            ->where('cid', $cid)
398
+            ->select('problem.pid as pid', 'pcode', 'number')
399 399
             ->get()->all();
400 400
     }
401 401
 
@@ -416,18 +416,18 @@  discard block
 block discarded – undo
416 416
         $end_time=strtotime(DB::table("contest")->where(["cid"=>$cid])->select("end_time")->first()["end_time"]);
417 417
 
418 418
         foreach ($problemSet as &$p) {
419
-            if($p['practice']){
420
-                $tags = DB::table("group_problem_tag")
421
-                ->where('gid',$p['gid'])
422
-                ->where('pid',$p['pid'])
419
+            if ($p['practice']) {
420
+                $tags=DB::table("group_problem_tag")
421
+                ->where('gid', $p['gid'])
422
+                ->where('pid', $p['pid'])
423 423
                 ->get()->all();
424
-                $tags_arr = [];
425
-                if(!empty($tags)){
424
+                $tags_arr=[];
425
+                if (!empty($tags)) {
426 426
                     foreach ($tags as $value) {
427
-                        array_push($tags_arr,$value['tag']);
427
+                        array_push($tags_arr, $value['tag']);
428 428
                     }
429 429
                 }
430
-                $p['tags'] = $tags_arr;
430
+                $p['tags']=$tags_arr;
431 431
             }
432 432
             if ($contest_rule==1) {
433 433
                 $prob_stat=DB::table("submission")->select(
@@ -688,7 +688,7 @@  discard block
 block discarded – undo
688 688
                     "problem_detail" => $prob_detail
689 689
                 ];
690 690
             }
691
-            usort($ret, function ($a, $b) {
691
+            usort($ret, function($a, $b) {
692 692
                 if ($a["score"]==$b["score"]) {
693 693
                     if ($a["penalty"]==$b["penalty"]) {
694 694
                         return 0;
@@ -735,7 +735,7 @@  discard block
 block discarded – undo
735 735
                     "problem_detail" => $prob_detail
736 736
                 ];
737 737
             }
738
-            usort($ret, function ($a, $b) {
738
+            usort($ret, function($a, $b) {
739 739
                 if ($a["score"]==$b["score"]) {
740 740
                     if ($a["solved"]==$b["solved"]) {
741 741
                         return 0;
@@ -757,7 +757,7 @@  discard block
 block discarded – undo
757 757
         return $ret;
758 758
     }
759 759
 
760
-    public function contestRank($cid, $uid = 0)
760
+    public function contestRank($cid, $uid=0)
761 761
     {
762 762
         // [ToDo] If the current user's in the organizer group show nick name
763 763
         // [ToDo] The participants determination
@@ -775,31 +775,31 @@  discard block
 block discarded – undo
775 775
             "gid" => $contest_info["gid"]
776 776
         ])->where("role", ">", 0)->first());
777 777
 
778
-        $clearance = $this -> judgeClearance($cid, $uid);
778
+        $clearance=$this -> judgeClearance($cid, $uid);
779 779
 
780 780
         /** New Version With MySQL */
781 781
         $end_time=strtotime(DB::table("contest")->where(["cid"=>$cid])->select("end_time")->first()["end_time"]);
782 782
 
783
-        if(time() < $end_time){
784
-            if($clearance == 3){
783
+        if (time()<$end_time) {
784
+            if ($clearance==3) {
785 785
                 $contestRankRaw=Cache::tags(['contest', 'rank'])->get("contestAdmin$cid");
786
-            }else{
786
+            } else {
787 787
                 $contestRankRaw=Cache::tags(['contest', 'rank'])->get($cid);
788 788
             }
789
-            if(!isset($contestRankRaw)){
789
+            if (!isset($contestRankRaw)) {
790 790
                 $contestRankRaw=$this->contestRankCache($cid);
791 791
             }
792
-        }else{
793
-            if($clearance == 3){
792
+        } else {
793
+            if ($clearance==3) {
794 794
                 $contestRankRaw=Cache::tags(['contest', 'rank'])->get("contestAdmin$cid");
795 795
                 if (!isset($contestRankRaw)) {
796 796
                     $contestRankRaw=$this->contestRankCache($cid);
797 797
                 }
798
-            }else{
798
+            } else {
799 799
                 $contestRankRaw=$this->getContestRankFromMySQL($cid);
800
-                if(!isset($contestRankRaw)){
800
+                if (!isset($contestRankRaw)) {
801 801
                     $contestRankRaw=Cache::tags(['contest', 'rank'])->get($cid);
802
-                    if(!isset($contestRankRaw)){
802
+                    if (!isset($contestRankRaw)) {
803 803
                         $contestRankRaw=$this->contestRankCache($cid);
804 804
                     }
805 805
                     $this->storeContestRankInMySQL($cid, $contestRankRaw);
@@ -817,15 +817,15 @@  discard block
 block discarded – undo
817 817
         //         $contestRankRaw=$this->contestRankCache($cid);
818 818
         //     }
819 819
         // }
820
-        if($contest_info["rule"]==1){
820
+        if ($contest_info["rule"]==1) {
821 821
             foreach ($contestRankRaw as &$cr) {
822
-                $solved = 0;
823
-                foreach($cr['problem_detail'] as $pd){
824
-                    if(!empty($pd['solved_time_parsed'])){
825
-                        $solved ++;
822
+                $solved=0;
823
+                foreach ($cr['problem_detail'] as $pd) {
824
+                    if (!empty($pd['solved_time_parsed'])) {
825
+                        $solved++;
826 826
                     }
827 827
                 }
828
-                $cr['solved'] = $solved;
828
+                $cr['solved']=$solved;
829 829
             }
830 830
         }
831 831
 
@@ -874,16 +874,16 @@  discard block
 block discarded – undo
874 874
 
875 875
     public function getClarificationList($cid)
876 876
     {
877
-        $uid = Auth::user()->id;
878
-        $clearance = $this -> judgeClearance($cid, $uid);
879
-        if($clearance == 3){
877
+        $uid=Auth::user()->id;
878
+        $clearance=$this -> judgeClearance($cid, $uid);
879
+        if ($clearance==3) {
880 880
             return DB::table("contest_clarification")->where([
881 881
                 "cid"=>$cid
882 882
             ])->orderBy('create_time', 'desc')->get()->all();
883
-        }else{
883
+        } else {
884 884
             return DB::table("contest_clarification")->where([
885 885
                 "cid"=>$cid
886
-            ])->where(function ($query) {
886
+            ])->where(function($query) {
887 887
                 $query->where([
888 888
                     "public"=>1
889 889
                 ])->orWhere([
@@ -1024,7 +1024,7 @@  discard block
 block discarded – undo
1024 1024
     public function getContestRecord($cid)
1025 1025
     {
1026 1026
         $basicInfo=$this->basic($cid);
1027
-        $userInfo=DB::table('group_member')->where('gid',$basicInfo["gid"])->where('uid',Auth::user()->id)->get()->first();
1027
+        $userInfo=DB::table('group_member')->where('gid', $basicInfo["gid"])->where('uid', Auth::user()->id)->get()->first();
1028 1028
         $problemSet_temp=DB::table("contest_problem")->join("problem", "contest_problem.pid", "=", "problem.pid")->where([
1029 1029
             "cid"=>$cid
1030 1030
         ])->orderBy('ncode', 'asc')->select("ncode", "alias", "contest_problem.pid as pid", "title", "points", "tot_score")->get()->all();
@@ -1037,7 +1037,7 @@  discard block
 block discarded – undo
1037 1037
         $end_time=strtotime(DB::table("contest")->where(["cid"=>$cid])->select("end_time")->first()["end_time"]);
1038 1038
         $contestEnd=time()>$end_time;
1039 1039
 
1040
-        if($userInfo==null || $userInfo["role"]!=3){
1040
+        if ($userInfo==null || $userInfo["role"]!=3) {
1041 1041
             if ($basicInfo["status_visibility"]==2) {
1042 1042
                 // View all
1043 1043
                 $paginator=DB::table("submission")->where([
@@ -1051,7 +1051,7 @@  discard block
 block discarded – undo
1051 1051
                     "users.id",
1052 1052
                     "=",
1053 1053
                     "submission.uid"
1054
-                )->where(function ($query) use ($frozen_time) {
1054
+                )->where(function($query) use ($frozen_time) {
1055 1055
                     $query->where(
1056 1056
                         "submission_date",
1057 1057
                         "<",
@@ -1113,7 +1113,7 @@  discard block
 block discarded – undo
1113 1113
                     "records"=>[]
1114 1114
                 ];
1115 1115
             }
1116
-        }else{
1116
+        } else {
1117 1117
             if ($basicInfo["status_visibility"]==2) {
1118 1118
                 // View all
1119 1119
                 $paginator=DB::table("submission")->where([
@@ -1225,21 +1225,21 @@  discard block
 block discarded – undo
1225 1225
         if ($uid==0) {
1226 1226
             return 0;
1227 1227
         }
1228
-        $groupModel = new GroupModel();
1228
+        $groupModel=new GroupModel();
1229 1229
         $contest_info=DB::table("contest")->where("cid", $cid)->first();
1230
-        $userInfo=DB::table('group_member')->where('gid',$contest_info["gid"])->where('uid',$uid)->get()->first();
1230
+        $userInfo=DB::table('group_member')->where('gid', $contest_info["gid"])->where('uid', $uid)->get()->first();
1231 1231
 
1232
-        if(empty($contest_info)){
1232
+        if (empty($contest_info)) {
1233 1233
             // contest not exist
1234 1234
             return 0;
1235 1235
         }
1236 1236
 
1237
-        if($uid == $contest_info['assign_uid'] || $groupModel->judgeClearance($contest_info['gid'],$uid) == 3){
1237
+        if ($uid==$contest_info['assign_uid'] || $groupModel->judgeClearance($contest_info['gid'], $uid)==3) {
1238 1238
             return 3;
1239 1239
         }
1240 1240
 
1241
-        $contest_started = strtotime($contest_info['begin_time']) < time();
1242
-        $contest_ended = strtotime($contest_info['end_time']) < time();
1241
+        $contest_started=strtotime($contest_info['begin_time'])<time();
1242
+        $contest_ended=strtotime($contest_info['end_time'])<time();
1243 1243
         if (!$contest_started) {
1244 1244
             // not started or do not exist
1245 1245
             return 0;
@@ -1330,12 +1330,12 @@  discard block
 block discarded – undo
1330 1330
     public function updateProfessionalRate($cid)
1331 1331
     {
1332 1332
         $basic=$this->basic($cid);
1333
-        if($basic["rated"]&&!$basic["is_rated"]){
1333
+        if ($basic["rated"] && !$basic["is_rated"]) {
1334 1334
             $ratingCalculator=new RatingCalculator($cid);
1335
-            if($ratingCalculator->calculate()){
1335
+            if ($ratingCalculator->calculate()) {
1336 1336
                 $ratingCalculator->storage();
1337 1337
                 return true;
1338
-            }else{
1338
+            } else {
1339 1339
                 return false;
1340 1340
             }
1341 1341
         } else {
@@ -1343,14 +1343,14 @@  discard block
 block discarded – undo
1343 1343
         }
1344 1344
     }
1345 1345
 
1346
-    public function contestUpdate($cid,$data,$problems)
1346
+    public function contestUpdate($cid, $data, $problems)
1347 1347
     {
1348
-        DB::transaction(function () use ($cid, $data, $problems) {
1348
+        DB::transaction(function() use ($cid, $data, $problems) {
1349 1349
             DB::table($this->tableName)
1350
-                ->where('cid',$cid)
1350
+                ->where('cid', $cid)
1351 1351
                 ->update($data);
1352 1352
             DB::table('contest_problem')
1353
-                ->where('cid',$cid)
1353
+                ->where('cid', $cid)
1354 1354
                 ->delete();
1355 1355
             foreach ($problems as $p) {
1356 1356
                 $pid=DB::table("problem")->where(["pcode"=>$p["pcode"]])->select("pid")->first()["pid"];
@@ -1368,7 +1368,7 @@  discard block
 block discarded – undo
1368 1368
 
1369 1369
     public function arrangeContest($gid, $config, $problems)
1370 1370
     {
1371
-        DB::transaction(function () use ($gid, $config, $problems) {
1371
+        DB::transaction(function() use ($gid, $config, $problems) {
1372 1372
             $cid=DB::table($this->tableName)->insertGetId([
1373 1373
                 "gid"=>$gid,
1374 1374
                 "name"=>$config["name"],
@@ -1382,7 +1382,7 @@  discard block
 block discarded – undo
1382 1382
                 "rule"=>1, //todo
1383 1383
                 "begin_time"=>$config["begin_time"],
1384 1384
                 "end_time"=>$config["end_time"],
1385
-                "vcid"=>isset($config["vcid"])?$config["vcid"]:null,
1385
+                "vcid"=>isset($config["vcid"]) ? $config["vcid"] : null,
1386 1386
                 "public"=>0, //todo
1387 1387
                 "registration"=>0, //todo
1388 1388
                 "registration_due"=>null, //todo
@@ -1407,33 +1407,33 @@  discard block
 block discarded – undo
1407 1407
         }, 5);
1408 1408
     }
1409 1409
 
1410
-    public function updateContestRankTable($cid,$sub)
1410
+    public function updateContestRankTable($cid, $sub)
1411 1411
     {
1412
-        $lock = Cache::lock("contestrank$cid",10);
1413
-        try{
1414
-            if($lock->get()){
1415
-                if(Cache::tags(['contest','rank'])->get($cid) != null){
1416
-                    $chache = Cache::tags(['contest','data'])->get($cid);
1417
-                    $ret = Cache::tags(['contest','rank'])->get($cid);
1418
-
1419
-                    $id = 0;
1420
-
1421
-                    foreach($chache['problemSet'] as $key => $p){
1422
-                        if ($p['pid'] == $sub['pid']){
1423
-                            $chache['problemSet'][$key]['cpid'] = $key;
1424
-                            $id = $key;
1412
+        $lock=Cache::lock("contestrank$cid", 10);
1413
+        try {
1414
+            if ($lock->get()) {
1415
+                if (Cache::tags(['contest', 'rank'])->get($cid)!=null) {
1416
+                    $chache=Cache::tags(['contest', 'data'])->get($cid);
1417
+                    $ret=Cache::tags(['contest', 'rank'])->get($cid);
1418
+
1419
+                    $id=0;
1420
+
1421
+                    foreach ($chache['problemSet'] as $key => $p) {
1422
+                        if ($p['pid']==$sub['pid']) {
1423
+                            $chache['problemSet'][$key]['cpid']=$key;
1424
+                            $id=$key;
1425 1425
                         }
1426 1426
                     }
1427 1427
 
1428
-                    $ret = $this->updateContestRankDetail($chache['contest_info'],$chache['problemSet'][$id],$cid,$sub['uid'],$ret);
1429
-                    $ret = $this->sortContestRankTable($chache['contest_info'],$cid,$ret);
1428
+                    $ret=$this->updateContestRankDetail($chache['contest_info'], $chache['problemSet'][$id], $cid, $sub['uid'], $ret);
1429
+                    $ret=$this->sortContestRankTable($chache['contest_info'], $cid, $ret);
1430 1430
 
1431
-                    if (time() < $chache['frozen_time']){
1431
+                    if (time()<$chache['frozen_time']) {
1432 1432
                         Cache::tags(['contest', 'rank'])->put($cid, $ret);
1433 1433
                     }
1434 1434
                     Cache::tags(['contest', 'rank'])->put("contestAdmin$cid", $ret);
1435 1435
                 }
1436
-                else{
1436
+                else {
1437 1437
                     $ret=[];
1438 1438
                     $chache=[];
1439 1439
                     $chache['contest_info']=DB::table("contest")->where("cid", $cid)->first();
@@ -1450,7 +1450,7 @@  discard block
 block discarded – undo
1450 1450
                             "cid"=>$cid,
1451 1451
                             "audit"=>1
1452 1452
                         ])->select('uid')->get()->all();
1453
-                    }else{
1453
+                    } else {
1454 1454
                         $submissionUsers=DB::table("submission")->where([
1455 1455
                             "cid"=>$cid
1456 1456
                         ])->where(
@@ -1463,39 +1463,39 @@  discard block
 block discarded – undo
1463 1463
                         ])->select('uid')->groupBy('uid')->get()->all();
1464 1464
                     }
1465 1465
 
1466
-                    $chacheAdmin = $chache;
1466
+                    $chacheAdmin=$chache;
1467 1467
 
1468 1468
                     foreach ($submissionUsers as $s) {
1469 1469
                         foreach ($chache['problemSet'] as $key => $p) {
1470
-                            $p['cpid'] = $key;
1471
-                            $ret = $this->updateContestRankDetail($chache['contest_info'],$p,$cid,$s['uid'],$ret);
1470
+                            $p['cpid']=$key;
1471
+                            $ret=$this->updateContestRankDetail($chache['contest_info'], $p, $cid, $s['uid'], $ret);
1472 1472
                         }
1473 1473
                     }
1474
-                    $ret = $this->sortContestRankTable($chache['contest_info'],$cid,$ret);
1474
+                    $ret=$this->sortContestRankTable($chache['contest_info'], $cid, $ret);
1475 1475
                     Cache::tags(['contest', 'rank'])->put($cid, $ret);
1476 1476
 
1477 1477
                     $retAdmin=[];
1478 1478
                     foreach ($submissionUsersAdmin as $s) {
1479 1479
                         foreach ($chacheAdmin['problemSet'] as $key => $p) {
1480
-                            $p['cpid'] = $key;
1481
-                            $retAdmin = $this->updateContestRankDetail($chacheAdmin['contest_info'],$p,$cid,$s['uid'],$retAdmin);
1480
+                            $p['cpid']=$key;
1481
+                            $retAdmin=$this->updateContestRankDetail($chacheAdmin['contest_info'], $p, $cid, $s['uid'], $retAdmin);
1482 1482
                         }
1483 1483
                     }
1484
-                    $retAdmin = $this->sortContestRankTable($chacheAdmin['contest_info'],$cid,$retAdmin);
1484
+                    $retAdmin=$this->sortContestRankTable($chacheAdmin['contest_info'], $cid, $retAdmin);
1485 1485
                     Cache::tags(['contest', 'rank'])->put("contestAdmin$cid", $retAdmin);
1486 1486
                 }
1487 1487
             }
1488
-        }catch(LockTimeoutException $e){
1488
+        } catch (LockTimeoutException $e) {
1489 1489
             Log::warning("Contest Rank Lock Timed Out");
1490
-        }finally{
1490
+        } finally {
1491 1491
             optional($lock)->release();
1492 1492
         }
1493 1493
     }
1494 1494
 
1495
-    public function sortContestRankTable($contest_info,$cid,$ret)
1495
+    public function sortContestRankTable($contest_info, $cid, $ret)
1496 1496
     {
1497
-        if ($contest_info["rule"]==1){
1498
-            usort($ret, function ($a, $b) {
1497
+        if ($contest_info["rule"]==1) {
1498
+            usort($ret, function($a, $b) {
1499 1499
                 if ($a["score"]==$b["score"]) {
1500 1500
                     if ($a["penalty"]==$b["penalty"]) {
1501 1501
                         return 0;
@@ -1510,8 +1510,8 @@  discard block
 block discarded – undo
1510 1510
                     return 1;
1511 1511
                 }
1512 1512
             });
1513
-        }else if ($contest_info["rule"]==2){
1514
-            usort($ret, function ($a, $b) {
1513
+        } else if ($contest_info["rule"]==2) {
1514
+            usort($ret, function($a, $b) {
1515 1515
                 if ($a["score"]==$b["score"]) {
1516 1516
                     if ($a["solved"]==$b["solved"]) {
1517 1517
                         return 0;
@@ -1530,21 +1530,21 @@  discard block
 block discarded – undo
1530 1530
         return $ret;
1531 1531
     }
1532 1532
 
1533
-    public function updateContestRankDetail($contest_info,$problem,$cid,$uid,$ret)
1533
+    public function updateContestRankDetail($contest_info, $problem, $cid, $uid, $ret)
1534 1534
     {
1535
-        $id = count($ret);
1536
-        foreach($ret as $key => $r){
1537
-            if($r['uid'] == $uid)
1538
-                $id = $key;
1535
+        $id=count($ret);
1536
+        foreach ($ret as $key => $r) {
1537
+            if ($r['uid']==$uid)
1538
+                $id=$key;
1539 1539
         }
1540 1540
         if ($contest_info["rule"]==1) {
1541 1541
             // ACM/ICPC Mode
1542
-                if($id == count($ret)){
1543
-                    $prob_detail = [];
1544
-                    $totPen = 0;
1545
-                    $totScore = 0;
1546
-                }else{
1547
-                    $prob_detail = $ret[$id]['problem_detail'];
1542
+                if ($id==count($ret)) {
1543
+                    $prob_detail=[];
1544
+                    $totPen=0;
1545
+                    $totScore=0;
1546
+                } else {
1547
+                    $prob_detail=$ret[$id]['problem_detail'];
1548 1548
                     $totPen=$ret[$id]['penalty'];
1549 1549
                     $totScore=$ret[$id]['score'];
1550 1550
                 };
@@ -1579,12 +1579,12 @@  discard block
 block discarded – undo
1579 1579
                 ];
1580 1580
         } elseif ($contest_info["rule"]==2) {
1581 1581
             // OI Mode
1582
-            if($id == count($ret)){
1583
-                $prob_detail = [];
1584
-                $totSolved = 0;
1585
-                $totScore = 0;
1586
-            }else{
1587
-                $prob_detail = $ret[$id]['problem_detail'];
1582
+            if ($id==count($ret)) {
1583
+                $prob_detail=[];
1584
+                $totSolved=0;
1585
+                $totScore=0;
1586
+            } else {
1587
+                $prob_detail=$ret[$id]['problem_detail'];
1588 1588
                 $totSolved=$ret[$id]['solved'];
1589 1589
                 $totScore=$ret[$id]['score'];
1590 1590
             };
@@ -1617,47 +1617,47 @@  discard block
 block discarded – undo
1617 1617
         return $ret;
1618 1618
     }
1619 1619
 
1620
-    public function assignMember($cid,$uid){
1620
+    public function assignMember($cid, $uid) {
1621 1621
         return DB::table("contest")->where(["cid"=>$cid])->update([
1622 1622
             "assign_uid"=>$uid
1623 1623
         ]);
1624 1624
     }
1625 1625
 
1626
-    public function canUpdateContestTime($cid,$time = [])
1626
+    public function canUpdateContestTime($cid, $time=[])
1627 1627
     {
1628
-        $begin_time_new = $time['begin'] ?? null;
1629
-        $end_time_new = $time['end'] ?? null;
1628
+        $begin_time_new=$time['begin'] ?? null;
1629
+        $end_time_new=$time['end'] ?? null;
1630 1630
 
1631
-        $hold_time = DB::table('contest')
1632
-            ->where('cid',$cid)
1633
-            ->select('begin_time','end_time')
1631
+        $hold_time=DB::table('contest')
1632
+            ->where('cid', $cid)
1633
+            ->select('begin_time', 'end_time')
1634 1634
             ->first();
1635
-        $begin_stamps = strtotime($hold_time['begin_time']);
1636
-        $end_stamps = strtotime($hold_time['end_time']);
1635
+        $begin_stamps=strtotime($hold_time['begin_time']);
1636
+        $end_stamps=strtotime($hold_time['end_time']);
1637 1637
         /*
1638 1638
         -1 : have not begun
1639 1639
          0 : ing
1640 1640
          1 : end
1641 1641
         */
1642
-        $status = time() >= $end_stamps ? 1
1643
-                : (time() <= $begin_stamps ? -1 : 0);
1644
-        if($status === -1){
1645
-            if(time() > $begin_time_new){
1642
+        $status=time()>=$end_stamps ? 1
1643
+                : (time()<=$begin_stamps ? -1 : 0);
1644
+        if ($status===-1) {
1645
+            if (time()>$begin_time_new) {
1646 1646
                 return false;
1647 1647
             }
1648 1648
             return true;
1649
-        }else if($status === 0){
1650
-            if($begin_time_new !== null){
1649
+        } else if ($status===0) {
1650
+            if ($begin_time_new!==null) {
1651 1651
                 return false;
1652 1652
             }
1653
-            if($end_time_new !== null){
1654
-                if(strtotime($end_time_new) <= time()){
1653
+            if ($end_time_new!==null) {
1654
+                if (strtotime($end_time_new)<=time()) {
1655 1655
                     return false;
1656
-                }else{
1656
+                } else {
1657 1657
                     return true;
1658 1658
                 }
1659 1659
             }
1660
-        }else{
1660
+        } else {
1661 1661
             return false;
1662 1662
         }
1663 1663
 
@@ -1666,22 +1666,22 @@  discard block
 block discarded – undo
1666 1666
 
1667 1667
     public function replyClarification($ccid, $content)
1668 1668
     {
1669
-        return DB::table("contest_clarification")->where('ccid','=',$ccid)->update([
1669
+        return DB::table("contest_clarification")->where('ccid', '=', $ccid)->update([
1670 1670
             "reply"=>$content
1671 1671
         ]);
1672 1672
     }
1673 1673
 
1674 1674
     public function setClarificationPublic($ccid, $public)
1675 1675
     {
1676
-        if($public)
1676
+        if ($public)
1677 1677
         {
1678
-            return DB::table("contest_clarification")->where('ccid','=',$ccid)->update([
1678
+            return DB::table("contest_clarification")->where('ccid', '=', $ccid)->update([
1679 1679
                 "public"=>1
1680 1680
             ]);
1681 1681
         }
1682 1682
         else
1683 1683
         {
1684
-            return DB::table("contest_clarification")->where('ccid','=',$ccid)->update([
1684
+            return DB::table("contest_clarification")->where('ccid', '=', $ccid)->update([
1685 1685
                 "public"=>0
1686 1686
             ]);
1687 1687
         }
@@ -1692,63 +1692,63 @@  discard block
 block discarded – undo
1692 1692
         return Cache::tags(['contest', 'account'])->get($cid);
1693 1693
     }
1694 1694
 
1695
-    public function praticeAnalysis($cid){
1696
-        $gid = DB::table('contest')
1697
-            ->where('cid',$cid)
1695
+    public function praticeAnalysis($cid) {
1696
+        $gid=DB::table('contest')
1697
+            ->where('cid', $cid)
1698 1698
             ->first()['gid'];
1699
-        $contestRank = $this->contestRank($cid,Auth::user()->id);
1700
-        $all_problems = DB::table('problem')
1701
-            ->whereIn('pid',array_column($contestRank[0]['problem_detail'],'pid'))
1702
-            ->select('pid','title')
1699
+        $contestRank=$this->contestRank($cid, Auth::user()->id);
1700
+        $all_problems=DB::table('problem')
1701
+            ->whereIn('pid', array_column($contestRank[0]['problem_detail'], 'pid'))
1702
+            ->select('pid', 'title')
1703 1703
             ->get()->all();
1704
-        $tags = DB::table('group_problem_tag')
1704
+        $tags=DB::table('group_problem_tag')
1705 1705
             ->where('gid', $gid)
1706
-            ->whereIn('pid', array_column($all_problems,'pid'))
1706
+            ->whereIn('pid', array_column($all_problems, 'pid'))
1707 1707
             ->get()->all();
1708
-        $all_tags = array_unique(array_column($tags,'tag'));
1709
-        $memberData = [];
1710
-        foreach($contestRank as $member){
1711
-            $m = [
1708
+        $all_tags=array_unique(array_column($tags, 'tag'));
1709
+        $memberData=[];
1710
+        foreach ($contestRank as $member) {
1711
+            $m=[
1712 1712
                 'uid' => $member['uid'],
1713 1713
                 'name' => $member['name'],
1714 1714
                 'nick_name' => $member['nick_name'],
1715 1715
             ];
1716
-            $completion = [];
1717
-            foreach ($all_tags as $tag){
1718
-                $completion[$tag] = [];
1716
+            $completion=[];
1717
+            foreach ($all_tags as $tag) {
1718
+                $completion[$tag]=[];
1719 1719
                 foreach ($tags as $t) {
1720
-                    if($t['tag'] == $tag){
1720
+                    if ($t['tag']==$tag) {
1721 1721
                         foreach ($member['problem_detail'] as $pd) {
1722
-                            if($pd['pid'] == $t['pid']){
1723
-                                $completion[$tag][$t['pid']] = $pd['solved_time_parsed'] == "" ? 0 : 1;
1722
+                            if ($pd['pid']==$t['pid']) {
1723
+                                $completion[$tag][$t['pid']]=$pd['solved_time_parsed']=="" ? 0 : 1;
1724 1724
                             }
1725 1725
                         }
1726 1726
                     }
1727 1727
                 }
1728 1728
             }
1729
-            $m['completion'] = $completion;
1730
-            $memberData[] = $m;
1729
+            $m['completion']=$completion;
1730
+            $memberData[]=$m;
1731 1731
         }
1732 1732
         return $memberData;
1733 1733
     }
1734 1734
 
1735 1735
     public function storeContestRankInMySQL($cid, $data)
1736 1736
     {
1737
-        $contestRankJson = json_encode($data);
1738
-        return DB::table('contest')->where('cid','=',$cid)->update([
1737
+        $contestRankJson=json_encode($data);
1738
+        return DB::table('contest')->where('cid', '=', $cid)->update([
1739 1739
             'rank' => $contestRankJson
1740 1740
         ]);
1741 1741
     }
1742 1742
 
1743 1743
     public function getContestRankFromMySQL($cid)
1744 1744
     {
1745
-        $contestRankJson = DB::table('contest')->where('cid','=',$cid)->pluck('rank')->first();
1746
-        $data = json_decode($contestRankJson, true);
1745
+        $contestRankJson=DB::table('contest')->where('cid', '=', $cid)->pluck('rank')->first();
1746
+        $data=json_decode($contestRankJson, true);
1747 1747
         return $data;
1748 1748
     }
1749 1749
 
1750 1750
     public function isVerified($cid)
1751 1751
     {
1752
-        return DB::table('contest')->where('cid','=',$cid)->pluck('verified')->first();
1752
+        return DB::table('contest')->where('cid', '=', $cid)->pluck('verified')->first();
1753 1753
     }
1754 1754
 }
Please login to merge, or discard this patch.
app/Models/RankModel.php 2 patches
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
 use Illuminate\Support\Facades\DB;
8 8
 use Illuminate\Support\Arr;
9 9
 use App\Models\Rating\RatingCalculator;
10
-use Cache,Redis;
10
+use Cache, Redis;
11 11
 
12 12
 class RankModel extends Model
13 13
 {
@@ -65,27 +65,27 @@  discard block
 block discarded – undo
65 65
 
66 66
     public static function getColor($rankTitle)
67 67
     {
68
-        if(is_null($rankTitle)) return "";
68
+        if (is_null($rankTitle)) return "";
69 69
         return self::$casualRanking[$rankTitle];
70 70
     }
71 71
 
72 72
     public static function getProfessionalColor($rankTitle)
73 73
     {
74
-        if(is_null($rankTitle)) return self::$professionalRanking["None"];
74
+        if (is_null($rankTitle)) return self::$professionalRanking["None"];
75 75
         return self::$professionalRanking[$rankTitle];
76 76
     }
77 77
 
78 78
     public function list($num)
79 79
     {
80 80
         $rankList=Cache::tags(['rank'])->get('general');
81
-        if($rankList==null) $rankList=[];
82
-        $userInfoRaw=DB::table("users")->select("id as uid","avatar","name")->limit($num)->get()->all();
81
+        if ($rankList==null) $rankList=[];
82
+        $userInfoRaw=DB::table("users")->select("id as uid", "avatar", "name")->limit($num)->get()->all();
83 83
         $userInfo=[];
84
-        foreach($userInfoRaw as $u){
84
+        foreach ($userInfoRaw as $u) {
85 85
             $userInfo[$u["uid"]]=$u;
86 86
         }
87
-        foreach($rankList as &$r){
88
-            $r["details"]=isset($userInfo[$r["uid"]])?$userInfo[$r["uid"]]:[];
87
+        foreach ($rankList as &$r) {
88
+            $r["details"]=isset($userInfo[$r["uid"]]) ? $userInfo[$r["uid"]] : [];
89 89
         }
90 90
         // var_dump($rankList); exit();
91 91
         return $rankList;
@@ -108,8 +108,8 @@  discard block
 block discarded – undo
108 108
                     $rankSolved=$rankItem["totValue"];
109 109
                 }
110 110
                 $rankTitle=$this->getRankTitle($rankValue);
111
-                Cache::tags(['rank',$rankItem["uid"]])->put("rank", $rankValue, 86400);
112
-                Cache::tags(['rank',$rankItem["uid"]])->put("title", $rankTitle, 86400);
111
+                Cache::tags(['rank', $rankItem["uid"]])->put("rank", $rankValue, 86400);
112
+                Cache::tags(['rank', $rankItem["uid"]])->put("title", $rankTitle, 86400);
113 113
                 $rankListCached[]=[
114 114
                     "uid"=>$rankItem["uid"],
115 115
                     "rank"=>$rankValue,
@@ -126,14 +126,14 @@  discard block
 block discarded – undo
126 126
 
127 127
     public function getProfessionalRanking()
128 128
     {
129
-        $professionalRankList = [];
130
-        $verifiedUsers = DB::table("users")->select("professional_rate","id as uid","avatar","name")->get()->all();
131
-        $rankIter = 0;
132
-        foreach($verifiedUsers as $user) {
133
-            $rankVal = $user['professional_rate'];
134
-            $rankTitle = self::getProfessionalTitle($rankVal);
135
-            $titleColor = self::getProfessionalColor($rankTitle);
136
-            $professionalRankList[$rankIter++] = [
129
+        $professionalRankList=[];
130
+        $verifiedUsers=DB::table("users")->select("professional_rate", "id as uid", "avatar", "name")->get()->all();
131
+        $rankIter=0;
132
+        foreach ($verifiedUsers as $user) {
133
+            $rankVal=$user['professional_rate'];
134
+            $rankTitle=self::getProfessionalTitle($rankVal);
135
+            $titleColor=self::getProfessionalColor($rankTitle);
136
+            $professionalRankList[$rankIter++]=[
137 137
                 "name"=>$user["name"],
138 138
                 "uid"=>$user["uid"],
139 139
                 "avatar"=>$user["avatar"],
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
                 $tot+=$c;
156 156
             }
157 157
             foreach ($this->casualRankingPer as &$c) {
158
-                $c=round($c*$totUsers/$tot);
158
+                $c=round($c * $totUsers / $tot);
159 159
                 $cur+=$c;
160 160
                 $c=$cur;
161 161
             }
@@ -166,16 +166,16 @@  discard block
 block discarded – undo
166 166
 
167 167
     public function getRankTitle($rankVal)
168 168
     {
169
-        foreach($this->casualRankingPer as $title=>$c){
170
-            if($rankVal<=$c) return $title;
169
+        foreach ($this->casualRankingPer as $title=>$c) {
170
+            if ($rankVal<=$c) return $title;
171 171
         }
172 172
         return Arr::last($this->casualRankingPer);
173 173
     }
174 174
 
175 175
     public static function getProfessionalTitle($rankVal)
176 176
     {
177
-        foreach(self::$professionalRankingPer as $title=>$point) {
178
-            if($rankVal >= $point) return $title;
177
+        foreach (self::$professionalRankingPer as $title=>$point) {
178
+            if ($rankVal>=$point) return $title;
179 179
         }
180 180
         return Arr::last(self::$professionalRankingPer);
181 181
     }
Please login to merge, or discard this patch.
Braces   +15 added lines, -5 removed lines patch added patch discarded remove patch
@@ -65,20 +65,26 @@  discard block
 block discarded – undo
65 65
 
66 66
     public static function getColor($rankTitle)
67 67
     {
68
-        if(is_null($rankTitle)) return "";
68
+        if(is_null($rankTitle)) {
69
+            return "";
70
+        }
69 71
         return self::$casualRanking[$rankTitle];
70 72
     }
71 73
 
72 74
     public static function getProfessionalColor($rankTitle)
73 75
     {
74
-        if(is_null($rankTitle)) return self::$professionalRanking["None"];
76
+        if(is_null($rankTitle)) {
77
+            return self::$professionalRanking["None"];
78
+        }
75 79
         return self::$professionalRanking[$rankTitle];
76 80
     }
77 81
 
78 82
     public function list($num)
79 83
     {
80 84
         $rankList=Cache::tags(['rank'])->get('general');
81
-        if($rankList==null) $rankList=[];
85
+        if($rankList==null) {
86
+            $rankList=[];
87
+        }
82 88
         $userInfoRaw=DB::table("users")->select("id as uid","avatar","name")->limit($num)->get()->all();
83 89
         $userInfo=[];
84 90
         foreach($userInfoRaw as $u){
@@ -167,7 +173,9 @@  discard block
 block discarded – undo
167 173
     public function getRankTitle($rankVal)
168 174
     {
169 175
         foreach($this->casualRankingPer as $title=>$c){
170
-            if($rankVal<=$c) return $title;
176
+            if($rankVal<=$c) {
177
+                return $title;
178
+            }
171 179
         }
172 180
         return Arr::last($this->casualRankingPer);
173 181
     }
@@ -175,7 +183,9 @@  discard block
 block discarded – undo
175 183
     public static function getProfessionalTitle($rankVal)
176 184
     {
177 185
         foreach(self::$professionalRankingPer as $title=>$point) {
178
-            if($rankVal >= $point) return $title;
186
+            if($rankVal >= $point) {
187
+                return $title;
188
+            }
179 189
         }
180 190
         return Arr::last(self::$professionalRankingPer);
181 191
     }
Please login to merge, or discard this patch.