Passed
Push — master ( 61a757...a989ff )
by
unknown
04:38 queued 10s
created
app/Models/Rating/RatingCalculator.php 1 patch
Spacing   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -17,24 +17,24 @@  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) {
31 31
             $contestModel=new ContestModel();
32
-            $contestRankRaw=Chache::tags('contest','rank')->get($this->cid);
32
+            $contestRankRaw=Chache::tags('contest', 'rank')->get($this->cid);
33 33
             //$contestModel->contestRankCache($this->cid);//TODO:use realtimeContestRankCache
34 34
         }
35 35
 
36
-        $this->totParticipants = count($contestRankRaw);
37
-        foreach($contestRankRaw as $c){
36
+        $this->totParticipants=count($contestRankRaw);
37
+        foreach ($contestRankRaw as $c) {
38 38
             $this->contestants[]=[
39 39
                 "uid"=>$c["uid"],
40 40
                 "points"=>$c["score"],
@@ -43,84 +43,84 @@  discard block
 block discarded – undo
43 43
         }
44 44
     }
45 45
 
46
-    private function reassignRank(){
46
+    private function reassignRank() {
47 47
         $this->sort("points");
48
-        $idx = 0;
49
-        $points = $this->contestants[0]["points"];
50
-        $i = 1;
51
-        while($i < $this->totParticipants){
52
-            if($this->contestants[$i]["points"] < $points){
53
-                $j = $idx;
54
-                while($j < $i){
55
-                    $this->contestants[$j]["rank"] = $i;
56
-                    $j += 1;
48
+        $idx=0;
49
+        $points=$this->contestants[0]["points"];
50
+        $i=1;
51
+        while ($i<$this->totParticipants) {
52
+            if ($this->contestants[$i]["points"]<$points) {
53
+                $j=$idx;
54
+                while ($j<$i) {
55
+                    $this->contestants[$j]["rank"]=$i;
56
+                    $j+=1;
57 57
                 }
58
-                $idx = $i;
59
-                $points = $this->contestants[$i]["points"];
58
+                $idx=$i;
59
+                $points=$this->contestants[$i]["points"];
60 60
             }
61
-            $i += 1;
61
+            $i+=1;
62 62
         }
63
-        $j = $idx;
64
-        while($j < $this->totParticipants){
65
-            $this->contestants[$j]["rank"] = $this->totParticipants;
66
-            $j += 1;
63
+        $j=$idx;
64
+        while ($j<$this->totParticipants) {
65
+            $this->contestants[$j]["rank"]=$this->totParticipants;
66
+            $j+=1;
67 67
         }
68 68
     }
69 69
 
70
-    private function getEloWinProbability($Ra, $Rb){
71
-        return 1.0 / (1 + pow(10, ($Rb-$Ra)/400.0));
70
+    private function getEloWinProbability($Ra, $Rb) {
71
+        return 1.0 / (1+pow(10, ($Rb-$Ra) / 400.0));
72 72
     }
73 73
 
74
-    private function getSeed($rating){
75
-        $result = 1.0;
76
-        foreach($this->contestants as $other){
77
-            $result += $this->getEloWinProbability($other["rating"], $rating);
74
+    private function getSeed($rating) {
75
+        $result=1.0;
76
+        foreach ($this->contestants as $other) {
77
+            $result+=$this->getEloWinProbability($other["rating"], $rating);
78 78
         }
79 79
         return $result;
80 80
     }
81 81
 
82
-    private function getRatingToRank($rank){
82
+    private function getRatingToRank($rank) {
83 83
         $left=1;
84 84
         $right=8000;
85
-        while($right - $left > 1){
86
-            $mid = floor(($right + $left)/2);
87
-            if($this->getSeed($mid) < $rank){
88
-                $right = $mid;
89
-            }else{
90
-                $left = $mid;
85
+        while ($right-$left>1) {
86
+            $mid=floor(($right+$left) / 2);
87
+            if ($this->getSeed($mid)<$rank) {
88
+                $right=$mid;
89
+            } else {
90
+                $left=$mid;
91 91
             }
92 92
         }
93 93
         return $left;
94 94
     }
95 95
 
96
-    private function sort($key){
97
-        usort($this->contestants, function ($a, $b) use ($key) {
96
+    private function sort($key) {
97
+        usort($this->contestants, function($a, $b) use ($key) {
98 98
             return $b[$key] <=> $a[$key];
99 99
         });
100 100
     }
101 101
 
102
-    public function calculate(){
103
-        if(empty($this->contestants)){
102
+    public function calculate() {
103
+        if (empty($this->contestants)) {
104 104
             return;
105 105
         }
106 106
 
107 107
         // recalc rank
108 108
         $this->reassignRank();
109 109
 
110
-        foreach($this->contestants as &$member){
111
-            $member["seed"] = 1.0;
112
-            foreach($this->contestants as $other){
113
-                if($member["uid"] != $other["uid"]){
114
-                    $member["seed"] += $this->getEloWinProbability($other["rating"], $member["rating"]);
110
+        foreach ($this->contestants as &$member) {
111
+            $member["seed"]=1.0;
112
+            foreach ($this->contestants as $other) {
113
+                if ($member["uid"]!=$other["uid"]) {
114
+                    $member["seed"]+=$this->getEloWinProbability($other["rating"], $member["rating"]);
115 115
                 }
116 116
             }
117 117
         }
118 118
         unset($member);
119 119
 
120
-        foreach($this->contestants as &$contestant){
121
-            $midRank = sqrt($contestant["rank"] * $contestant["seed"]);
122
-            $contestant["needRating"] = $this->getRatingToRank($midRank);
123
-            $contestant["delta"] = floor(($contestant["needRating"] - $contestant["rating"])/2);
120
+        foreach ($this->contestants as &$contestant) {
121
+            $midRank=sqrt($contestant["rank"] * $contestant["seed"]);
122
+            $contestant["needRating"]=$this->getRatingToRank($midRank);
123
+            $contestant["delta"]=floor(($contestant["needRating"]-$contestant["rating"]) / 2);
124 124
         }
125 125
         unset($contestant);
126 126
 
@@ -128,39 +128,39 @@  discard block
 block discarded – undo
128 128
 
129 129
         // DO some adjuct
130 130
         // Total sum should not be more than ZERO.
131
-        $sum = 0;
131
+        $sum=0;
132 132
 
133
-        foreach($this->contestants as $contestant){
134
-            $sum += $contestant["delta"];
133
+        foreach ($this->contestants as $contestant) {
134
+            $sum+=$contestant["delta"];
135 135
         }
136
-        $inc = -floor($sum / $this->totParticipants) - 1;
137
-        foreach($this->contestants as &$contestant){
138
-            $contestant["delta"] += $inc;
136
+        $inc=-floor($sum / $this->totParticipants)-1;
137
+        foreach ($this->contestants as &$contestant) {
138
+            $contestant["delta"]+=$inc;
139 139
         }
140 140
         unset($contestant);
141 141
 
142 142
         // Sum of top-4*sqrt should be adjusted to ZERO.
143 143
 
144
-        $sum = 0;
145
-        $zeroSumCount = min(intval(4*round(sqrt($this->totParticipants))), $this->totParticipants);
144
+        $sum=0;
145
+        $zeroSumCount=min(intval(4 * round(sqrt($this->totParticipants))), $this->totParticipants);
146 146
 
147
-        for($i=0;$i<$zeroSumCount;$i++){
148
-            $sum += $this->contestants[$i]["delta"];
147
+        for ($i=0; $i<$zeroSumCount; $i++) {
148
+            $sum+=$this->contestants[$i]["delta"];
149 149
         }
150 150
 
151
-        $inc = min(max(-floor($sum / $zeroSumCount), -10), 0);
151
+        $inc=min(max(-floor($sum / $zeroSumCount), -10), 0);
152 152
 
153
-        for($i=0;$i<$zeroSumCount;$i++){
154
-            $this->contestants[$i]["delta"] += $inc;
153
+        for ($i=0; $i<$zeroSumCount; $i++) {
154
+            $this->contestants[$i]["delta"]+=$inc;
155 155
         }
156 156
 
157 157
         return $this->validateDeltas();
158 158
     }
159 159
 
160
-    public function storage(){
160
+    public function storage() {
161 161
         $contestants=$this->contestants;
162
-        DB::transaction(function () use ($contestants) {
163
-            foreach($contestants as $contestant){
162
+        DB::transaction(function() use ($contestants) {
163
+            foreach ($contestants as $contestant) {
164 164
                 $newRating=$contestant["rating"]+$contestant["delta"];
165 165
                 DB::table("users")->where([
166 166
                     "id"=>$contestant["uid"]
@@ -182,20 +182,20 @@  discard block
 block discarded – undo
182 182
         }, 5);
183 183
     }
184 184
 
185
-    private function validateDeltas(){
185
+    private function validateDeltas() {
186 186
         $this->sort("points");
187 187
 
188
-        for($i=0;$i<$this->totParticipants;$i++){
189
-            for($j=$i+1;$j<$this->totParticipants;$j++){
190
-                if($this->contestants[$i]["rating"] > $this->contestants[$j]["rating"]){
191
-                    if($this->contestants[$i]["rating"] + $this->contestants[$i]["delta"] < $this->contestants[$j]["rating"] + $this->contestants[$j]["delta"]){
188
+        for ($i=0; $i<$this->totParticipants; $i++) {
189
+            for ($j=$i+1; $j<$this->totParticipants; $j++) {
190
+                if ($this->contestants[$i]["rating"]>$this->contestants[$j]["rating"]) {
191
+                    if ($this->contestants[$i]["rating"]+$this->contestants[$i]["delta"]<$this->contestants[$j]["rating"]+$this->contestants[$j]["delta"]) {
192 192
                         Log::warning("First rating invariant failed: {$this->contestants[i]["uid"]} vs. {$this->contestants[j]["uid"]}.");
193 193
                         return false;
194 194
                     }
195 195
                 }
196 196
 
197
-                if($this->contestants[$i]["rating"] < $this->contestants[$j]["rating"]){
198
-                    if($this->contestants[$i]["delta"] < $this->contestants[$j]["delta"]){
197
+                if ($this->contestants[$i]["rating"]<$this->contestants[$j]["rating"]) {
198
+                    if ($this->contestants[$i]["delta"]<$this->contestants[$j]["delta"]) {
199 199
                         Log::warning("Second rating invariant failed: {$this->contestants[i]["uid"]} vs.  {$this->contestants[j]["uid"]}.");
200 200
                         return false;
201 201
                     }
Please login to merge, or discard this patch.
app/Models/ContestModel.php 2 patches
Spacing   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -124,9 +124,9 @@  discard block
 block discarded – undo
124 124
         //     "gid"=>$gid
125 125
         // ])->orderBy('begin_time', 'desc')->get()->all();
126 126
         $preQuery=DB::table($this->tableName);
127
-        $paginator=$preQuery->where('gid','=',$gid)->orderBy('begin_time', 'desc')->paginate(10);
127
+        $paginator=$preQuery->where('gid', '=', $gid)->orderBy('begin_time', 'desc')->paginate(10);
128 128
         $contest_list=$paginator->all();
129
-        if(empty($contest_list)){
129
+        if (empty($contest_list)) {
130 130
             return null;
131 131
         }
132 132
 
@@ -161,13 +161,13 @@  discard block
 block discarded – undo
161 161
                 ->join('contest', 'group_member.gid', '=', 'contest.gid')
162 162
                 ->leftJoin('contest_participant', 'contest.cid', '=', 'contest_participant.cid')
163 163
                 ->where(
164
-                    function ($query) {
164
+                    function($query) {
165 165
                         $query->where('public', 1)
166 166
                               ->where('audit_status', 1);
167 167
                     }
168 168
                 )
169 169
                 ->orWhere(
170
-                    function ($query) use ($uid) {
170
+                    function($query) use ($uid) {
171 171
                         $query->where('group_member.uid', $uid)
172 172
                                 ->where('group_member.role', '>', 0);
173 173
                             //     ->where(function ($query) use ($uid) {
@@ -232,14 +232,14 @@  discard block
 block discarded – undo
232 232
         }
233 233
     }
234 234
 
235
-    public function registContest($cid,$uid)
235
+    public function registContest($cid, $uid)
236 236
     {
237 237
         $registered=DB::table("contest_participant")->where([
238 238
             "cid"=>$cid,
239 239
             "uid"=>$uid
240 240
         ])->first();
241 241
 
242
-        if(empty($registered)){
242
+        if (empty($registered)) {
243 243
             DB::table("contest_participant")->insert([
244 244
                 "cid"=>$cid,
245 245
                 "uid"=>$uid,
@@ -540,7 +540,7 @@  discard block
 block discarded – undo
540 540
                     "problem_detail" => $prob_detail
541 541
                 ];
542 542
             }
543
-            usort($ret, function ($a, $b) {
543
+            usort($ret, function($a, $b) {
544 544
                 if ($a["score"]==$b["score"]) {
545 545
                     if ($a["penalty"]==$b["penalty"]) {
546 546
                         return 0;
@@ -587,7 +587,7 @@  discard block
 block discarded – undo
587 587
                     "problem_detail" => $prob_detail
588 588
                 ];
589 589
             }
590
-            usort($ret, function ($a, $b) {
590
+            usort($ret, function($a, $b) {
591 591
                 if ($a["score"]==$b["score"]) {
592 592
                     if ($a["solved"]==$b["solved"]) {
593 593
                         return 0;
@@ -680,7 +680,7 @@  discard block
 block discarded – undo
680 680
     {
681 681
         return DB::table("contest_clarification")->where([
682 682
             "cid"=>$cid
683
-        ])->where(function ($query) {
683
+        ])->where(function($query) {
684 684
             $query->where([
685 685
                 "public"=>1
686 686
             ])->orWhere([
@@ -833,7 +833,7 @@  discard block
 block discarded – undo
833 833
                 "users.id",
834 834
                 "=",
835 835
                 "submission.uid"
836
-            )->where(function ($query) use ($frozen_time) {
836
+            )->where(function($query) use ($frozen_time) {
837 837
                 $query->where(
838 838
                     "submission_date",
839 839
                     "<",
@@ -1026,12 +1026,12 @@  discard block
 block discarded – undo
1026 1026
     public function updateProfessionalRate($cid)
1027 1027
     {
1028 1028
         $basic=$this->basic($cid);
1029
-        if($basic["rated"]&&!$basic["is_rated"]){
1029
+        if ($basic["rated"] && !$basic["is_rated"]) {
1030 1030
             $ratingCalculator=new RatingCalculator($cid);
1031
-            if($ratingCalculator->calculate()){
1031
+            if ($ratingCalculator->calculate()) {
1032 1032
                 $ratingCalculator->storage();
1033 1033
                 return true;
1034
-            }else{
1034
+            } else {
1035 1035
                 return false;
1036 1036
             }
1037 1037
         } else {
@@ -1041,7 +1041,7 @@  discard block
 block discarded – undo
1041 1041
 
1042 1042
     public function arrangeContest($gid, $config, $problems)
1043 1043
     {
1044
-        DB::transaction(function () use ($gid, $config, $problems) {
1044
+        DB::transaction(function() use ($gid, $config, $problems) {
1045 1045
             $cid=DB::table($this->tableName)->insertGetId([
1046 1046
                 "gid"=>$gid,
1047 1047
                 "name"=>$config["name"],
@@ -1077,31 +1077,31 @@  discard block
 block discarded – undo
1077 1077
         }, 5);
1078 1078
     }
1079 1079
 
1080
-    public function updateContestRankTable($cid,$sub){
1081
-        $lock = Cache::lock("contestrank$cid",10);
1082
-        try{
1083
-            if($lock->get()){
1084
-                if(Cache::tags(['contest','rank'])->get($cid) != null){
1085
-                    $chache = Cache::tags(['contest','data'])->get($cid);
1086
-                    $ret = Cache::tags(['contest','rank'])->get($cid);
1087
-                    if (time() > $chache['frozen_time'])
1080
+    public function updateContestRankTable($cid, $sub) {
1081
+        $lock=Cache::lock("contestrank$cid", 10);
1082
+        try {
1083
+            if ($lock->get()) {
1084
+                if (Cache::tags(['contest', 'rank'])->get($cid)!=null) {
1085
+                    $chache=Cache::tags(['contest', 'data'])->get($cid);
1086
+                    $ret=Cache::tags(['contest', 'rank'])->get($cid);
1087
+                    if (time()>$chache['frozen_time'])
1088 1088
                         return;
1089 1089
 
1090
-                    $id = 0;
1090
+                    $id=0;
1091 1091
 
1092
-                    foreach($chache['problemSet'] as $key => $p){
1093
-                        if ($p['pid'] == $sub['pid']){
1094
-                            $chache['problemSet'][$key]['cpid'] = $key;
1095
-                            $id = $key;
1092
+                    foreach ($chache['problemSet'] as $key => $p) {
1093
+                        if ($p['pid']==$sub['pid']) {
1094
+                            $chache['problemSet'][$key]['cpid']=$key;
1095
+                            $id=$key;
1096 1096
                         }
1097 1097
                     }
1098 1098
 
1099
-                    $ret = $this->updateContestRankDetail($chache['contest_info'],$chache['problemSet'][$id],$cid,$sub['uid'],$ret);
1100
-                    $ret = $this->sortContestRankTable($chache['contest_info'],$cid,$ret);
1099
+                    $ret=$this->updateContestRankDetail($chache['contest_info'], $chache['problemSet'][$id], $cid, $sub['uid'], $ret);
1100
+                    $ret=$this->sortContestRankTable($chache['contest_info'], $cid, $ret);
1101 1101
 
1102 1102
                     Cache::tags(['contest', 'rank'])->put($cid, $ret);
1103 1103
                 }
1104
-                else{
1104
+                else {
1105 1105
                     $ret=[];
1106 1106
                     $chache=[];
1107 1107
                     $chache['contest_info']=DB::table("contest")->where("cid", $cid)->first();
@@ -1118,7 +1118,7 @@  discard block
 block discarded – undo
1118 1118
                             "cid"=>$cid,
1119 1119
                             "audit"=>1
1120 1120
                         ])->select('uid')->get()->all();
1121
-                    }else{
1121
+                    } else {
1122 1122
                         $submissionUsers=DB::table("submission")->where([
1123 1123
                             "cid"=>$cid
1124 1124
                         ])->where(
@@ -1129,24 +1129,24 @@  discard block
 block discarded – undo
1129 1129
                     }
1130 1130
                     foreach ($submissionUsers as $s) {
1131 1131
                         foreach ($chache['problemSet'] as $key => $p) {
1132
-                            $p['cpid'] = $key;
1133
-                            $ret = $this->updateContestRankDetail($chache['contest_info'],$p,$cid,$s['uid'],$ret);
1132
+                            $p['cpid']=$key;
1133
+                            $ret=$this->updateContestRankDetail($chache['contest_info'], $p, $cid, $s['uid'], $ret);
1134 1134
                         }
1135 1135
                     }
1136
-                    $ret = $this->sortContestRankTable($chache['contest_info'],$cid,$ret);
1136
+                    $ret=$this->sortContestRankTable($chache['contest_info'], $cid, $ret);
1137 1137
                     Cache::tags(['contest', 'rank'])->put($cid, $ret);
1138 1138
                 }
1139 1139
             }
1140
-        }catch(LockTimeoutException $e){
1140
+        } catch (LockTimeoutException $e) {
1141 1141
             Log::warning("Contest Rank Lock Timed Out");
1142
-        }finally{
1142
+        } finally {
1143 1143
             optional($lock)->release();
1144 1144
         }
1145 1145
     }
1146 1146
 
1147
-    public function sortContestRankTable($contest_info,$cid,$ret){
1148
-        if ($contest_info["rule"]==1){
1149
-            usort($ret, function ($a, $b) {
1147
+    public function sortContestRankTable($contest_info, $cid, $ret) {
1148
+        if ($contest_info["rule"]==1) {
1149
+            usort($ret, function($a, $b) {
1150 1150
                 if ($a["score"]==$b["score"]) {
1151 1151
                     if ($a["penalty"]==$b["penalty"]) {
1152 1152
                         return 0;
@@ -1161,8 +1161,8 @@  discard block
 block discarded – undo
1161 1161
                     return 1;
1162 1162
                 }
1163 1163
             });
1164
-        }else if ($contest_info["rule"]==2){
1165
-            usort($ret, function ($a, $b) {
1164
+        } else if ($contest_info["rule"]==2) {
1165
+            usort($ret, function($a, $b) {
1166 1166
                 if ($a["score"]==$b["score"]) {
1167 1167
                     if ($a["solved"]==$b["solved"]) {
1168 1168
                         return 0;
@@ -1181,15 +1181,15 @@  discard block
 block discarded – undo
1181 1181
         return $ret;
1182 1182
     }
1183 1183
 
1184
-    public function updateContestRankDetail($contest_info,$problem,$cid,$uid,$ret){
1185
-        $id = count($ret);
1186
-        foreach($ret as $key => $r){
1187
-            if($r['uid'] == $uid)
1188
-                $id = $key;
1184
+    public function updateContestRankDetail($contest_info, $problem, $cid, $uid, $ret) {
1185
+        $id=count($ret);
1186
+        foreach ($ret as $key => $r) {
1187
+            if ($r['uid']==$uid)
1188
+                $id=$key;
1189 1189
         }
1190 1190
         if ($contest_info["rule"]==1) {
1191 1191
             // ACM/ICPC Mode
1192
-                $prob_detail = $ret[$id]['problem_detail'];
1192
+                $prob_detail=$ret[$id]['problem_detail'];
1193 1193
                 $totPen=$ret[$id]['penalty'];
1194 1194
                 $totScore=$ret[$id]['score'];
1195 1195
 
@@ -1223,7 +1223,7 @@  discard block
 block discarded – undo
1223 1223
                 ];
1224 1224
         } elseif ($contest_info["rule"]==2) {
1225 1225
             // OI Mode
1226
-            $prob_detail = $ret[$id]['problem_detail'];
1226
+            $prob_detail=$ret[$id]['problem_detail'];
1227 1227
             $totScore=$ret[$id]['score'];
1228 1228
             $totSolved=$ret[$id]['solved'];
1229 1229
 
Please login to merge, or discard this patch.
Braces   +12 added lines, -11 removed lines patch added patch discarded remove patch
@@ -1031,7 +1031,7 @@  discard block
 block discarded – undo
1031 1031
             if($ratingCalculator->calculate()){
1032 1032
                 $ratingCalculator->storage();
1033 1033
                 return true;
1034
-            }else{
1034
+            } else{
1035 1035
                 return false;
1036 1036
             }
1037 1037
         } else {
@@ -1084,8 +1084,9 @@  discard block
 block discarded – undo
1084 1084
                 if(Cache::tags(['contest','rank'])->get($cid) != null){
1085 1085
                     $chache = Cache::tags(['contest','data'])->get($cid);
1086 1086
                     $ret = Cache::tags(['contest','rank'])->get($cid);
1087
-                    if (time() > $chache['frozen_time'])
1088
-                        return;
1087
+                    if (time() > $chache['frozen_time']) {
1088
+                                            return;
1089
+                    }
1089 1090
 
1090 1091
                     $id = 0;
1091 1092
 
@@ -1100,8 +1101,7 @@  discard block
 block discarded – undo
1100 1101
                     $ret = $this->sortContestRankTable($chache['contest_info'],$cid,$ret);
1101 1102
 
1102 1103
                     Cache::tags(['contest', 'rank'])->put($cid, $ret);
1103
-                }
1104
-                else{
1104
+                } else{
1105 1105
                     $ret=[];
1106 1106
                     $chache=[];
1107 1107
                     $chache['contest_info']=DB::table("contest")->where("cid", $cid)->first();
@@ -1118,7 +1118,7 @@  discard block
 block discarded – undo
1118 1118
                             "cid"=>$cid,
1119 1119
                             "audit"=>1
1120 1120
                         ])->select('uid')->get()->all();
1121
-                    }else{
1121
+                    } else{
1122 1122
                         $submissionUsers=DB::table("submission")->where([
1123 1123
                             "cid"=>$cid
1124 1124
                         ])->where(
@@ -1137,9 +1137,9 @@  discard block
 block discarded – undo
1137 1137
                     Cache::tags(['contest', 'rank'])->put($cid, $ret);
1138 1138
                 }
1139 1139
             }
1140
-        }catch(LockTimeoutException $e){
1140
+        } catch(LockTimeoutException $e){
1141 1141
             Log::warning("Contest Rank Lock Timed Out");
1142
-        }finally{
1142
+        } finally{
1143 1143
             optional($lock)->release();
1144 1144
         }
1145 1145
     }
@@ -1161,7 +1161,7 @@  discard block
 block discarded – undo
1161 1161
                     return 1;
1162 1162
                 }
1163 1163
             });
1164
-        }else if ($contest_info["rule"]==2){
1164
+        } else if ($contest_info["rule"]==2){
1165 1165
             usort($ret, function ($a, $b) {
1166 1166
                 if ($a["score"]==$b["score"]) {
1167 1167
                     if ($a["solved"]==$b["solved"]) {
@@ -1184,8 +1184,9 @@  discard block
 block discarded – undo
1184 1184
     public function updateContestRankDetail($contest_info,$problem,$cid,$uid,$ret){
1185 1185
         $id = count($ret);
1186 1186
         foreach($ret as $key => $r){
1187
-            if($r['uid'] == $uid)
1188
-                $id = $key;
1187
+            if($r['uid'] == $uid) {
1188
+                            $id = $key;
1189
+            }
1189 1190
         }
1190 1191
         if ($contest_info["rule"]==1) {
1191 1192
             // ACM/ICPC Mode
Please login to merge, or discard this patch.
app/Models/SubmissionModel.php 1 patch
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -425,15 +425,15 @@  discard block
 block discarded – undo
425 425
         if (isset($sub['verdict'])) {
426 426
             $sub["color"]=$this->colorScheme[$sub['verdict']];
427 427
         }
428
-        $result = DB::table($this->tableName)->where(['sid'=>$sid])->update($sub);
429
-
430
-        $contestModel = new ContestModel();
431
-        $submission_info = DB::table($this->tableName) -> where(['sid'=>$sid]) -> get() -> first();
432
-        if ($submission_info['cid'] && $contestModel->isContestRunning($submission_info['cid'])){
433
-            $sub['pid'] = $submission_info['pid'];
434
-            $sub['uid'] = $submission_info['uid'];
435
-            $sub['cid'] = $submission_info['cid'];
436
-            $contestModel->updateContestRankTable($submission_info['cid'],$sub);
428
+        $result=DB::table($this->tableName)->where(['sid'=>$sid])->update($sub);
429
+
430
+        $contestModel=new ContestModel();
431
+        $submission_info=DB::table($this->tableName) -> where(['sid'=>$sid]) -> get() -> first();
432
+        if ($submission_info['cid'] && $contestModel->isContestRunning($submission_info['cid'])) {
433
+            $sub['pid']=$submission_info['pid'];
434
+            $sub['uid']=$submission_info['uid'];
435
+            $sub['cid']=$submission_info['cid'];
436
+            $contestModel->updateContestRankTable($submission_info['cid'], $sub);
437 437
         }
438 438
         return $result;
439 439
     }
@@ -504,15 +504,15 @@  discard block
 block discarded – undo
504 504
             'desc'
505 505
         );
506 506
 
507
-        if($filter["pcode"]){
507
+        if ($filter["pcode"]) {
508 508
             $paginator=$paginator->where(["pcode"=>$filter["pcode"]]);
509 509
         }
510 510
 
511
-        if($filter["result"]){
511
+        if ($filter["result"]) {
512 512
             $paginator=$paginator->where(["verdict"=>$filter["result"]]);
513 513
         }
514 514
 
515
-        if($filter["account"]){
515
+        if ($filter["account"]) {
516 516
             $paginator=$paginator->where(["name"=>$filter["account"]]);
517 517
         }
518 518
 
Please login to merge, or discard this patch.