Passed
Pull Request — master (#788)
by John
13:26
created
app/Models/Eloquent/ProblemSolution.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -18,9 +18,9 @@  discard block
 block discarded – undo
18 18
     {
19 19
         parent::boot();
20 20
         static::updating(function($model) {
21
-            $problem = Problem::findOrFail($model->pid);
22
-            if($model->original['audit'] != $model->audit) {
23
-                if($model->audit == 1) {
21
+            $problem=Problem::findOrFail($model->pid);
22
+            if ($model->original['audit']!=$model->audit) {
23
+                if ($model->audit==1) {
24 24
                     // passed
25 25
                     sendMessage([
26 26
                         'sender'   => config('app.official_sender'),
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
                             ]]
36 36
                         ]
37 37
                     ]);
38
-                } elseif($model->audit == 2) {
38
+                } elseif ($model->audit==2) {
39 39
                     // declined
40 40
                     sendMessage([
41 41
                         'sender'   => config('app.official_sender'),
Please login to merge, or discard this patch.
app/Models/Eloquent/Tool/SiteRank.php 1 patch
Spacing   +92 added lines, -92 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
 
13 13
 class SiteRank
14 14
 {
15
-    private static $professionalRanking = [
15
+    private static $professionalRanking=[
16 16
         "Legendary Grandmaster" => "cm-colorful-text",
17 17
         "International Grandmaster" => "wemd-pink-text",
18 18
         "Grandmaster" => "wemd-red-text",
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
         "Newbie" => "wemd-gray-text",
26 26
     ];
27 27
 
28
-    private static $professionalRankingPer = [
28
+    private static $professionalRankingPer=[
29 29
         "Legendary Grandmaster" => 3000,
30 30
         "International Grandmaster" => 2600,
31 31
         "Grandmaster" => 2400,
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
         "Newbie" => 1,
39 39
     ];
40 40
 
41
-    private static $casualRanking = [
41
+    private static $casualRanking=[
42 42
         "Fleet Admiral" => "cm-colorful-text",
43 43
         "Admiral" => "wemd-pink-text",
44 44
         "Vice Admiral" => "wemd-red-text",
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
         "Recruit" => "wemd-gray-text",
52 52
     ];
53 53
 
54
-    private static $casualRankingPer = [
54
+    private static $casualRankingPer=[
55 55
         "Fleet Admiral" => 1,
56 56
         "Admiral" => 5,
57 57
         "Vice Admiral" => 10,
@@ -82,49 +82,49 @@  discard block
 block discarded – undo
82 82
 
83 83
     public static function list($num)
84 84
     {
85
-        $rankList = Cache::tags(['rank'])->get('general');
85
+        $rankList=Cache::tags(['rank'])->get('general');
86 86
         if (blank($rankList)) {
87
-            $rankList = [];
87
+            $rankList=[];
88 88
         }
89
-        $rankList = collect($rankList)->slice(0, $num);
90
-        $userIDArr = $rankList->pluck('uid');
91
-        $userInfoRaw = User::whereIntegerInRaw('id', $userIDArr)->get();
92
-        $userInfo = [];
89
+        $rankList=collect($rankList)->slice(0, $num);
90
+        $userIDArr=$rankList->pluck('uid');
91
+        $userInfoRaw=User::whereIntegerInRaw('id', $userIDArr)->get();
92
+        $userInfo=[];
93 93
         foreach ($userInfoRaw as $u) {
94
-            $userInfo[$u->id] = $u;
94
+            $userInfo[$u->id]=$u;
95 95
         }
96
-        return $rankList->map(function ($item) use ($userInfo) {
97
-            $item["details"] = isset($userInfo[$item["uid"]]) ? $userInfo[$item["uid"]] : [];
96
+        return $rankList->map(function($item) use ($userInfo) {
97
+            $item["details"]=isset($userInfo[$item["uid"]]) ? $userInfo[$item["uid"]] : [];
98 98
             return $item;
99 99
         });
100 100
     }
101 101
 
102
-    private static function getRecords(Carbon $from = null)
102
+    private static function getRecords(Carbon $from=null)
103 103
     {
104
-        $userAcceptedRecords = Submission::select("uid", DB::raw("count(distinct pid) as solved"))->where("verdict", "Accepted");
105
-        $userCommunityRecords = ProblemSolution::select("uid", DB::raw("count(distinct pid) as community"))->where("audit", 1);
106
-        if(filled($from)){
107
-            $userAcceptedRecords = $userAcceptedRecords->where("submission_date", ">", $from->timestamp);
108
-            $userCommunityRecords = $userCommunityRecords->where("created_at", ">", $from);
104
+        $userAcceptedRecords=Submission::select("uid", DB::raw("count(distinct pid) as solved"))->where("verdict", "Accepted");
105
+        $userCommunityRecords=ProblemSolution::select("uid", DB::raw("count(distinct pid) as community"))->where("audit", 1);
106
+        if (filled($from)) {
107
+            $userAcceptedRecords=$userAcceptedRecords->where("submission_date", ">", $from->timestamp);
108
+            $userCommunityRecords=$userCommunityRecords->where("created_at", ">", $from);
109 109
         }
110
-        $userAcceptedRecords = collect($userAcceptedRecords->groupBy("uid")->get()->toArray());
111
-        $userCommunityRecords = collect($userCommunityRecords->groupBy("uid")->get()->toArray());
112
-        $totUserRecords = $userAcceptedRecords->pluck('uid')->merge($userCommunityRecords->pluck('uid'))->unique();
113
-        $rankList = [];
114
-        foreach($totUserRecords as $uid) {
115
-            $rankList[$uid]['uid'] = $uid;
116
-            $rankList[$uid]['solved'] = 0;
117
-            $rankList[$uid]['community'] = 0;
118
-            $rankList[$uid]['tot'] = 0;
110
+        $userAcceptedRecords=collect($userAcceptedRecords->groupBy("uid")->get()->toArray());
111
+        $userCommunityRecords=collect($userCommunityRecords->groupBy("uid")->get()->toArray());
112
+        $totUserRecords=$userAcceptedRecords->pluck('uid')->merge($userCommunityRecords->pluck('uid'))->unique();
113
+        $rankList=[];
114
+        foreach ($totUserRecords as $uid) {
115
+            $rankList[$uid]['uid']=$uid;
116
+            $rankList[$uid]['solved']=0;
117
+            $rankList[$uid]['community']=0;
118
+            $rankList[$uid]['tot']=0;
119 119
         }
120
-        foreach($userAcceptedRecords as $userAcceptedRecord) {
121
-            $rankList[$userAcceptedRecord['uid']]['solved'] = $userAcceptedRecord['solved'];
120
+        foreach ($userAcceptedRecords as $userAcceptedRecord) {
121
+            $rankList[$userAcceptedRecord['uid']]['solved']=$userAcceptedRecord['solved'];
122 122
         }
123
-        foreach($userCommunityRecords as $userCommunityRecord) {
124
-            $rankList[$userCommunityRecord['uid']]['community'] = $userCommunityRecord['community'];
123
+        foreach ($userCommunityRecords as $userCommunityRecord) {
124
+            $rankList[$userCommunityRecord['uid']]['community']=$userCommunityRecord['community'];
125 125
         }
126
-        foreach($rankList as &$rankItem) {
127
-            $rankItem['tot'] = $rankItem['solved'] + $rankItem['community'];
126
+        foreach ($rankList as &$rankItem) {
127
+            $rankItem['tot']=$rankItem['solved']+$rankItem['community'];
128 128
         }
129 129
         unset($rankItem);
130 130
         return $rankList;
@@ -132,19 +132,19 @@  discard block
 block discarded – undo
132 132
 
133 133
     private static function parseCoefficient($rankList)
134 134
     {
135
-        $activityCoefficient = self::getRecords(Carbon::parse('-1 months'));
136
-        $activityCoefficientDivider = collect($activityCoefficient)->max('tot');
137
-        if(blank($activityCoefficientDivider)) {
138
-            $activityCoefficientDivider = 1;
135
+        $activityCoefficient=self::getRecords(Carbon::parse('-1 months'));
136
+        $activityCoefficientDivider=collect($activityCoefficient)->max('tot');
137
+        if (blank($activityCoefficientDivider)) {
138
+            $activityCoefficientDivider=1;
139 139
         }
140 140
         foreach ($rankList as $uid => $rankItem) {
141
-            if(isset($activityCoefficient[$uid])){
142
-                $activityTot = $activityCoefficient[$uid]['tot'];
141
+            if (isset($activityCoefficient[$uid])) {
142
+                $activityTot=$activityCoefficient[$uid]['tot'];
143 143
             } else {
144
-                $activityTot = 0;
144
+                $activityTot=0;
145 145
             }
146
-            $rankList[$uid]["activityCoefficient"] = ($activityTot / $activityCoefficientDivider) + 0.5;
147
-            $rankList[$uid]["points"] = $rankList[$uid]["tot"] * $rankList[$uid]["activityCoefficient"];
146
+            $rankList[$uid]["activityCoefficient"]=($activityTot / $activityCoefficientDivider)+0.5;
147
+            $rankList[$uid]["points"]=$rankList[$uid]["tot"] * $rankList[$uid]["activityCoefficient"];
148 148
         }
149 149
         usort($rankList, function($a, $b) {
150 150
             return $b['points'] <=> $a['points'];
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
 
155 155
     public static function isTopOneHundred($rank)
156 156
     {
157
-        return (1 <= $rank && $rank <= 100);
157
+        return (1<=$rank && $rank<=100);
158 158
     }
159 159
 
160 160
     public static function getRankString($rank)
@@ -164,12 +164,12 @@  discard block
 block discarded – undo
164 164
 
165 165
     private static function sendMessage($userID, $currentRank, $originalRank)
166 166
     {
167
-        if(self::isTopOneHundred($currentRank)) {
168
-            $title = __('message.rank.up.title');
169
-            $level = 1;
167
+        if (self::isTopOneHundred($currentRank)) {
168
+            $title=__('message.rank.up.title');
169
+            $level=1;
170 170
         } else {
171
-            $title = __('message.rank.down.title');
172
-            $level = 2;
171
+            $title=__('message.rank.down.title');
172
+            $level=2;
173 173
         }
174 174
 
175 175
         return sendMessage([
@@ -187,27 +187,27 @@  discard block
 block discarded – undo
187 187
 
188 188
     public static function rankList()
189 189
     {
190
-        $originalRankList = self::list(100);
190
+        $originalRankList=self::list(100);
191 191
         Cache::tags(['rank'])->flush();
192
-        $rankList = self::getRecords();
193
-        $totUsers = count($rankList);
194
-        if ($totUsers > 0) {
192
+        $rankList=self::getRecords();
193
+        $totUsers=count($rankList);
194
+        if ($totUsers>0) {
195 195
             // $rankList = DB::select("SELECT *,solvedCount+communityCount as totValue, 1 as activityCoefficient FROM (SELECT uid,sum(solvedCount) as solvedCount,sum(communityCount) as communityCount FROM ((SELECT uid,count(DISTINCT submission.pid) as solvedCount,0 as communityCount from submission where verdict=\"Accepted\" group by uid) UNION (SELECT uid,0 as solvedCount,count(DISTINCT pid) from problem_solution where audit=1 group by uid)) as temp GROUP BY uid) as temp2 ORDER BY solvedCount+communityCount DESC");
196
-            $rankList = self::parseCoefficient($rankList);
197
-            $rankIter = 1;
198
-            $rankValue = 1;
199
-            $rankSolved = -1;
200
-            $rankListCached = [];
196
+            $rankList=self::parseCoefficient($rankList);
197
+            $rankIter=1;
198
+            $rankValue=1;
199
+            $rankSolved=-1;
200
+            $rankListCached=[];
201 201
             self::procRankingPer($totUsers);
202 202
             foreach ($rankList as $rankItem) {
203
-                if ($rankSolved != $rankItem["points"]) {
204
-                    $rankValue = $rankIter;
205
-                    $rankSolved = $rankItem["points"];
203
+                if ($rankSolved!=$rankItem["points"]) {
204
+                    $rankValue=$rankIter;
205
+                    $rankSolved=$rankItem["points"];
206 206
                 }
207
-                $rankTitle = self::getRankTitle($rankValue);
207
+                $rankTitle=self::getRankTitle($rankValue);
208 208
                 Cache::tags(['rank', $rankItem["uid"]])->put("rank", $rankValue, 86400);
209 209
                 Cache::tags(['rank', $rankItem["uid"]])->put("title", $rankTitle, 86400);
210
-                $rankListCached[] = [
210
+                $rankListCached[]=[
211 211
                     "uid" => $rankItem["uid"],
212 212
                     "rank" => $rankValue,
213 213
                     "title" => $rankTitle,
@@ -219,36 +219,36 @@  discard block
 block discarded – undo
219 219
                 $rankIter++;
220 220
             }
221 221
             Cache::tags(['rank'])->put("general", $rankListCached, 86400);
222
-            $currentRankList = self::list(100);
222
+            $currentRankList=self::list(100);
223 223
             self::sendRankUpDownMessage($originalRankList, $currentRankList);
224 224
         }
225 225
     }
226 226
 
227 227
     private static function sendRankUpDownMessage($originalRankList, $currentRankList)
228 228
     {
229
-        if(blank($originalRankList) || blank($currentRankList)) {
229
+        if (blank($originalRankList) || blank($currentRankList)) {
230 230
             return;
231 231
         }
232 232
 
233
-        $originalRankUID = [];
234
-        foreach($originalRankList as $originalRankItem) {
235
-            $originalRankUID[] = $originalRankItem['uid'];
233
+        $originalRankUID=[];
234
+        foreach ($originalRankList as $originalRankItem) {
235
+            $originalRankUID[]=$originalRankItem['uid'];
236 236
         }
237 237
 
238
-        $currentRankUID = [];
239
-        foreach($currentRankList as $currentRankItem) {
240
-            $currentRankUID[] = $currentRankItem['uid'];
238
+        $currentRankUID=[];
239
+        foreach ($currentRankList as $currentRankItem) {
240
+            $currentRankUID[]=$currentRankItem['uid'];
241 241
         }
242 242
 
243
-        foreach($originalRankList as $originalRankItem) {
244
-            if(in_array($originalRankItem['uid'], $currentRankUID)) {
243
+        foreach ($originalRankList as $originalRankItem) {
244
+            if (in_array($originalRankItem['uid'], $currentRankUID)) {
245 245
                 continue;
246 246
             }
247 247
             self::sendMessage($originalRankItem['uid'], Cache::tags(['rank', $originalRankItem['uid']])->get("rank", null), $originalRankItem['rank']);
248 248
         }
249 249
 
250
-        foreach($currentRankList as $currentRankItem) {
251
-            if(in_array($currentRankItem['uid'], $originalRankUID)) {
250
+        foreach ($currentRankList as $currentRankItem) {
251
+            if (in_array($currentRankItem['uid'], $originalRankUID)) {
252 252
                 continue;
253 253
             }
254 254
             self::sendMessage($currentRankItem['uid'], $currentRankItem['rank'], null);
@@ -257,14 +257,14 @@  discard block
 block discarded – undo
257 257
 
258 258
     public static function getProfessionalRanking()
259 259
     {
260
-        $professionalRankList = [];
261
-        $verifiedUsers = User::all();
262
-        $rankIter = 0;
260
+        $professionalRankList=[];
261
+        $verifiedUsers=User::all();
262
+        $rankIter=0;
263 263
         foreach ($verifiedUsers as $user) {
264
-            $rankVal = $user->professional_rate;
265
-            $rankTitle = self::getProfessionalTitle($rankVal);
266
-            $titleColor = self::getProfessionalColor($rankTitle);
267
-            $professionalRankList[$rankIter++] = [
264
+            $rankVal=$user->professional_rate;
265
+            $rankTitle=self::getProfessionalTitle($rankVal);
266
+            $titleColor=self::getProfessionalColor($rankTitle);
267
+            $professionalRankList[$rankIter++]=[
268 268
                 "name" => $user->name,
269 269
                 "uid" => $user->id,
270 270
                 "avatar" => $user->avatar,
@@ -278,18 +278,18 @@  discard block
 block discarded – undo
278 278
 
279 279
     private static function procRankingPer($totUsers)
280 280
     {
281
-        if ($totUsers > 0) {
282
-            $tot = 0;
283
-            $cur = 0;
281
+        if ($totUsers>0) {
282
+            $tot=0;
283
+            $cur=0;
284 284
             foreach (self::$casualRankingPer as $c) {
285
-                $tot += $c;
285
+                $tot+=$c;
286 286
             }
287 287
             foreach (self::$casualRankingPer as &$c) {
288
-                $c = round($c * $totUsers / $tot);
289
-                $cur += $c;
290
-                $c = $cur;
288
+                $c=round($c * $totUsers / $tot);
289
+                $cur+=$c;
290
+                $c=$cur;
291 291
             }
292
-            $c = $totUsers;
292
+            $c=$totUsers;
293 293
             unset($c);
294 294
         }
295 295
     }
@@ -297,7 +297,7 @@  discard block
 block discarded – undo
297 297
     public static function getRankTitle($rankVal)
298 298
     {
299 299
         foreach (self::$casualRankingPer as $title => $c) {
300
-            if ($rankVal <= $c) {
300
+            if ($rankVal<=$c) {
301 301
                 return $title;
302 302
             }
303 303
         }
@@ -307,7 +307,7 @@  discard block
 block discarded – undo
307 307
     public static function getProfessionalTitle($rankVal)
308 308
     {
309 309
         foreach (self::$professionalRankingPer as $title => $point) {
310
-            if ($rankVal >= $point) {
310
+            if ($rankVal>=$point) {
311 311
                 return $title;
312 312
             }
313 313
         }
Please login to merge, or discard this patch.