@@ -12,7 +12,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
82 | 82 | |
83 | 83 | public static function list($num) |
84 | 84 | { |
85 | - $rankList = Cache::tags(['rank'])->get('general'); |
|
86 | - if ($rankList == null) { |
|
87 | - $rankList = []; |
|
88 | - } |
|
89 | - $rankList = collect($rankList)->slice(0, $num); |
|
90 | - $userIDArr = $rankList->pluck('uid'); |
|
91 | - $userInfoRaw = User::whereIntegerInRaw('id', $userIDArr)->get(); |
|
92 | - $userInfo = []; |
|
85 | + $rankList=Cache::tags(['rank'])->get('general'); |
|
86 | + if ($rankList==null) { |
|
87 | + $rankList=[]; |
|
88 | + } |
|
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); |
|
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; |
|
119 | - } |
|
120 | - foreach($userAcceptedRecords as $userAcceptedRecord) { |
|
121 | - $rankList[$userAcceptedRecord['uid']]['solved'] = $userAcceptedRecord['solved']; |
|
122 | - } |
|
123 | - foreach($userCommunityRecords as $userCommunityRecord) { |
|
124 | - $rankList[$userCommunityRecord['uid']]['community'] = $userCommunityRecord['community']; |
|
125 | - } |
|
126 | - foreach($rankList as &$rankItem) { |
|
127 | - $rankItem['tot'] = $rankItem['solved'] + $rankItem['community']; |
|
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 | + } |
|
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 | + } |
|
120 | + foreach ($userAcceptedRecords as $userAcceptedRecord) { |
|
121 | + $rankList[$userAcceptedRecord['uid']]['solved']=$userAcceptedRecord['solved']; |
|
122 | + } |
|
123 | + foreach ($userCommunityRecords as $userCommunityRecord) { |
|
124 | + $rankList[$userCommunityRecord['uid']]['community']=$userCommunityRecord['community']; |
|
125 | + } |
|
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 |
||
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']; |
@@ -155,25 +155,25 @@ discard block |
||
155 | 155 | public static function rankList() |
156 | 156 | { |
157 | 157 | Cache::tags(['rank'])->flush(); |
158 | - $rankList = self::getRecords(); |
|
159 | - $totUsers = count($rankList); |
|
160 | - if ($totUsers > 0) { |
|
158 | + $rankList=self::getRecords(); |
|
159 | + $totUsers=count($rankList); |
|
160 | + if ($totUsers>0) { |
|
161 | 161 | // $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"); |
162 | - $rankList = self::parseCoefficient($rankList); |
|
163 | - $rankIter = 1; |
|
164 | - $rankValue = 1; |
|
165 | - $rankSolved = -1; |
|
166 | - $rankListCached = []; |
|
162 | + $rankList=self::parseCoefficient($rankList); |
|
163 | + $rankIter=1; |
|
164 | + $rankValue=1; |
|
165 | + $rankSolved=-1; |
|
166 | + $rankListCached=[]; |
|
167 | 167 | self::procRankingPer($totUsers); |
168 | 168 | foreach ($rankList as $rankItem) { |
169 | - if ($rankSolved != $rankItem["points"]) { |
|
170 | - $rankValue = $rankIter; |
|
171 | - $rankSolved = $rankItem["points"]; |
|
169 | + if ($rankSolved!=$rankItem["points"]) { |
|
170 | + $rankValue=$rankIter; |
|
171 | + $rankSolved=$rankItem["points"]; |
|
172 | 172 | } |
173 | - $rankTitle = self::getRankTitle($rankValue); |
|
173 | + $rankTitle=self::getRankTitle($rankValue); |
|
174 | 174 | Cache::tags(['rank', $rankItem["uid"]])->put("rank", $rankValue, 86400); |
175 | 175 | Cache::tags(['rank', $rankItem["uid"]])->put("title", $rankTitle, 86400); |
176 | - $rankListCached[] = [ |
|
176 | + $rankListCached[]=[ |
|
177 | 177 | "uid" => $rankItem["uid"], |
178 | 178 | "rank" => $rankValue, |
179 | 179 | "title" => $rankTitle, |
@@ -190,14 +190,14 @@ discard block |
||
190 | 190 | |
191 | 191 | public static function getProfessionalRanking() |
192 | 192 | { |
193 | - $professionalRankList = []; |
|
194 | - $verifiedUsers = User::all(); |
|
195 | - $rankIter = 0; |
|
193 | + $professionalRankList=[]; |
|
194 | + $verifiedUsers=User::all(); |
|
195 | + $rankIter=0; |
|
196 | 196 | foreach ($verifiedUsers as $user) { |
197 | - $rankVal = $user->professional_rate; |
|
198 | - $rankTitle = self::getProfessionalTitle($rankVal); |
|
199 | - $titleColor = self::getProfessionalColor($rankTitle); |
|
200 | - $professionalRankList[$rankIter++] = [ |
|
197 | + $rankVal=$user->professional_rate; |
|
198 | + $rankTitle=self::getProfessionalTitle($rankVal); |
|
199 | + $titleColor=self::getProfessionalColor($rankTitle); |
|
200 | + $professionalRankList[$rankIter++]=[ |
|
201 | 201 | "name" => $user->name, |
202 | 202 | "uid" => $user->id, |
203 | 203 | "avatar" => $user->avatar, |
@@ -211,18 +211,18 @@ discard block |
||
211 | 211 | |
212 | 212 | private static function procRankingPer($totUsers) |
213 | 213 | { |
214 | - if ($totUsers > 0) { |
|
215 | - $tot = 0; |
|
216 | - $cur = 0; |
|
214 | + if ($totUsers>0) { |
|
215 | + $tot=0; |
|
216 | + $cur=0; |
|
217 | 217 | foreach (self::$casualRankingPer as $c) { |
218 | - $tot += $c; |
|
218 | + $tot+=$c; |
|
219 | 219 | } |
220 | 220 | foreach (self::$casualRankingPer as &$c) { |
221 | - $c = round($c * $totUsers / $tot); |
|
222 | - $cur += $c; |
|
223 | - $c = $cur; |
|
221 | + $c=round($c * $totUsers / $tot); |
|
222 | + $cur+=$c; |
|
223 | + $c=$cur; |
|
224 | 224 | } |
225 | - $c = $totUsers; |
|
225 | + $c=$totUsers; |
|
226 | 226 | unset($c); |
227 | 227 | } |
228 | 228 | } |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | public static function getRankTitle($rankVal) |
231 | 231 | { |
232 | 232 | foreach (self::$casualRankingPer as $title => $c) { |
233 | - if ($rankVal <= $c) { |
|
233 | + if ($rankVal<=$c) { |
|
234 | 234 | return $title; |
235 | 235 | } |
236 | 236 | } |
@@ -240,7 +240,7 @@ discard block |
||
240 | 240 | public static function getProfessionalTitle($rankVal) |
241 | 241 | { |
242 | 242 | foreach (self::$professionalRankingPer as $title => $point) { |
243 | - if ($rankVal >= $point) { |
|
243 | + if ($rankVal>=$point) { |
|
244 | 244 | return $title; |
245 | 245 | } |
246 | 246 | } |
@@ -12,7 +12,7 @@ |
||
12 | 12 | { |
13 | 13 | public static function generate() |
14 | 14 | { |
15 | - $sitemap = App::make("sitemap"); |
|
15 | + $sitemap=App::make("sitemap"); |
|
16 | 16 | |
17 | 17 | $sitemap->add(route('home'), Carbon::now(), '1.0', 'daily'); |
18 | 18 | $sitemap->add(route('problem.index'), Carbon::now(), '1.0', 'daily'); |
@@ -13,53 +13,53 @@ |
||
13 | 13 | * @param $isAnd |
14 | 14 | * @return \Illuminate\Database\Eloquent\Builder |
15 | 15 | */ |
16 | - public function scopeLike($query, $column, $value, $side = 'both', $isNotLike = false, $isAnd = true) |
|
16 | + public function scopeLike($query, $column, $value, $side='both', $isNotLike=false, $isAnd=true) |
|
17 | 17 | { |
18 | - $operator = $isNotLike ? 'not like' : 'like'; |
|
18 | + $operator=$isNotLike ? 'not like' : 'like'; |
|
19 | 19 | |
20 | - $escape_like_str = function ($str) { |
|
21 | - $like_escape_char = '!'; |
|
20 | + $escape_like_str=function($str) { |
|
21 | + $like_escape_char='!'; |
|
22 | 22 | |
23 | 23 | return str_replace([$like_escape_char, '%', '_'], [ |
24 | - $like_escape_char . $like_escape_char, |
|
25 | - $like_escape_char . '%', |
|
26 | - $like_escape_char . '_', |
|
24 | + $like_escape_char.$like_escape_char, |
|
25 | + $like_escape_char.'%', |
|
26 | + $like_escape_char.'_', |
|
27 | 27 | ], $str); |
28 | 28 | }; |
29 | 29 | |
30 | 30 | switch ($side) { |
31 | 31 | case 'none': |
32 | - $value = $escape_like_str($value); |
|
32 | + $value=$escape_like_str($value); |
|
33 | 33 | break; |
34 | 34 | case 'before': |
35 | 35 | case 'left': |
36 | - $value = "%{$escape_like_str($value)}"; |
|
36 | + $value="%{$escape_like_str($value)}"; |
|
37 | 37 | break; |
38 | 38 | case 'after': |
39 | 39 | case 'right': |
40 | - $value = "{$escape_like_str($value)}%"; |
|
40 | + $value="{$escape_like_str($value)}%"; |
|
41 | 41 | break; |
42 | 42 | case 'both': |
43 | 43 | case 'all': |
44 | 44 | default: |
45 | - $value = "%{$escape_like_str($value)}%"; |
|
45 | + $value="%{$escape_like_str($value)}%"; |
|
46 | 46 | break; |
47 | 47 | } |
48 | 48 | |
49 | 49 | return $isAnd ? $query->where($column, $operator, $value) : $query->orWhere($column, $operator, $value); |
50 | 50 | } |
51 | 51 | |
52 | - public function scopeOrLike($query, $column, $value, $side = 'both', $isNotLike = false) |
|
52 | + public function scopeOrLike($query, $column, $value, $side='both', $isNotLike=false) |
|
53 | 53 | { |
54 | 54 | return $query->like($column, $value, $side, $isNotLike, false); |
55 | 55 | } |
56 | 56 | |
57 | - public function scopeNotLike($query, $column, $value, $side = 'both', $isAnd = true) |
|
57 | + public function scopeNotLike($query, $column, $value, $side='both', $isAnd=true) |
|
58 | 58 | { |
59 | 59 | return $query->like($column, $value, $side, true, $isAnd); |
60 | 60 | } |
61 | 61 | |
62 | - public function scopeOrNotLike($query, $column, $value, $side = 'both') |
|
62 | + public function scopeOrNotLike($query, $column, $value, $side='both') |
|
63 | 63 | { |
64 | 64 | return $query->like($column, $value, $side, true, false); |
65 | 65 | } |