@@ -78,7 +78,7 @@ |
||
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 | } |
@@ -17,14 +17,14 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 | } |
@@ -7,7 +7,7 @@ discard block |
||
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,26 +65,26 @@ discard block |
||
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() |
79 | 79 | { |
80 | 80 | $rankList=Cache::tags(['rank'])->get('general'); |
81 | - $userInfoRaw=DB::table("users")->select("id as uid","avatar","name")->get()->all(); |
|
81 | + $userInfoRaw=DB::table("users")->select("id as uid", "avatar", "name")->get()->all(); |
|
82 | 82 | $userInfo=[]; |
83 | - foreach($userInfoRaw as $u){ |
|
83 | + foreach ($userInfoRaw as $u) { |
|
84 | 84 | $userInfo[$u["uid"]]=$u; |
85 | 85 | } |
86 | - foreach($rankList as &$r){ |
|
87 | - $r["details"]=isset($userInfo[$r["uid"]])?$userInfo[$r["uid"]]:[]; |
|
86 | + foreach ($rankList as &$r) { |
|
87 | + $r["details"]=isset($userInfo[$r["uid"]]) ? $userInfo[$r["uid"]] : []; |
|
88 | 88 | } |
89 | 89 | // var_dump($rankList); exit(); |
90 | 90 | return $rankList; |
@@ -107,8 +107,8 @@ discard block |
||
107 | 107 | $rankSolved=$rankItem["totValue"]; |
108 | 108 | } |
109 | 109 | $rankTitle=$this->getRankTitle($rankValue); |
110 | - Cache::tags(['rank',$rankItem["uid"]])->put("rank", $rankValue, 86400); |
|
111 | - Cache::tags(['rank',$rankItem["uid"]])->put("title", $rankTitle, 86400); |
|
110 | + Cache::tags(['rank', $rankItem["uid"]])->put("rank", $rankValue, 86400); |
|
111 | + Cache::tags(['rank', $rankItem["uid"]])->put("title", $rankTitle, 86400); |
|
112 | 112 | $rankListCached[]=[ |
113 | 113 | "uid"=>$rankItem["uid"], |
114 | 114 | "rank"=>$rankValue, |
@@ -125,14 +125,14 @@ discard block |
||
125 | 125 | |
126 | 126 | public function getProfessionalRanking() |
127 | 127 | { |
128 | - $professionalRankList = []; |
|
129 | - $verifiedUsers = DB::table("users")->select("professional_rate","id as uid","avatar","name")->get()->all(); |
|
130 | - $rankIter = 0; |
|
131 | - foreach($verifiedUsers as $user) { |
|
132 | - $rankVal = $user['professional_rate']; |
|
133 | - $rankTitle = self::getProfessionalTitle($rankVal); |
|
134 | - $titleColor = self::getProfessionalColor($rankTitle); |
|
135 | - $professionalRankList[$rankIter++] = [ |
|
128 | + $professionalRankList=[]; |
|
129 | + $verifiedUsers=DB::table("users")->select("professional_rate", "id as uid", "avatar", "name")->get()->all(); |
|
130 | + $rankIter=0; |
|
131 | + foreach ($verifiedUsers as $user) { |
|
132 | + $rankVal=$user['professional_rate']; |
|
133 | + $rankTitle=self::getProfessionalTitle($rankVal); |
|
134 | + $titleColor=self::getProfessionalColor($rankTitle); |
|
135 | + $professionalRankList[$rankIter++]=[ |
|
136 | 136 | "name"=>$user["name"], |
137 | 137 | "uid"=>$user["uid"], |
138 | 138 | "avatar"=>$user["avatar"], |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | $tot+=$c; |
155 | 155 | } |
156 | 156 | foreach ($this->casualRankingPer as &$c) { |
157 | - $c=round($c*$totUsers/$tot); |
|
157 | + $c=round($c * $totUsers / $tot); |
|
158 | 158 | $cur+=$c; |
159 | 159 | $c=$cur; |
160 | 160 | } |
@@ -165,16 +165,16 @@ discard block |
||
165 | 165 | |
166 | 166 | public function getRankTitle($rankVal) |
167 | 167 | { |
168 | - foreach($this->casualRankingPer as $title=>$c){ |
|
169 | - if($rankVal<=$c) return $title; |
|
168 | + foreach ($this->casualRankingPer as $title=>$c) { |
|
169 | + if ($rankVal<=$c) return $title; |
|
170 | 170 | } |
171 | 171 | return Arr::last($this->casualRankingPer); |
172 | 172 | } |
173 | 173 | |
174 | 174 | public static function getProfessionalTitle($rankVal) |
175 | 175 | { |
176 | - foreach(self::$professionalRankingPer as $title=>$point) { |
|
177 | - if($rankVal >= $point) return $title; |
|
176 | + foreach (self::$professionalRankingPer as $title=>$point) { |
|
177 | + if ($rankVal>=$point) return $title; |
|
178 | 178 | } |
179 | 179 | return Arr::last(self::$professionalRankingPer); |
180 | 180 | } |
@@ -65,13 +65,17 @@ discard block |
||
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 | |
@@ -166,7 +170,9 @@ discard block |
||
166 | 170 | public function getRankTitle($rankVal) |
167 | 171 | { |
168 | 172 | foreach($this->casualRankingPer as $title=>$c){ |
169 | - if($rankVal<=$c) return $title; |
|
173 | + if($rankVal<=$c) { |
|
174 | + return $title; |
|
175 | + } |
|
170 | 176 | } |
171 | 177 | return Arr::last($this->casualRankingPer); |
172 | 178 | } |
@@ -174,7 +180,9 @@ discard block |
||
174 | 180 | public static function getProfessionalTitle($rankVal) |
175 | 181 | { |
176 | 182 | foreach(self::$professionalRankingPer as $title=>$point) { |
177 | - if($rankVal >= $point) return $title; |
|
183 | + if($rankVal >= $point) { |
|
184 | + return $title; |
|
185 | + } |
|
178 | 186 | } |
179 | 187 | return Arr::last(self::$professionalRankingPer); |
180 | 188 | } |
@@ -992,7 +992,7 @@ |
||
992 | 992 | if($ratingCalculator->calculate()){ |
993 | 993 | $ratingCalculator->storage(); |
994 | 994 | return true; |
995 | - }else{ |
|
995 | + } else{ |
|
996 | 996 | return false; |
997 | 997 | } |
998 | 998 | } else { |
@@ -153,7 +153,7 @@ |
||
153 | 153 | ->where( |
154 | 154 | function ($query) { |
155 | 155 | $query->where('public', 1) |
156 | - ->where('audit_status', 1); |
|
156 | + ->where('audit_status', 1); |
|
157 | 157 | } |
158 | 158 | ) |
159 | 159 | ->orWhere( |
@@ -123,9 +123,9 @@ discard block |
||
123 | 123 | // "gid"=>$gid |
124 | 124 | // ])->orderBy('begin_time', 'desc')->get()->all(); |
125 | 125 | $preQuery=DB::table($this->tableName); |
126 | - $paginator=$preQuery->where('gid','=',$gid)->orderBy('begin_time', 'desc')->paginate(10); |
|
126 | + $paginator=$preQuery->where('gid', '=', $gid)->orderBy('begin_time', 'desc')->paginate(10); |
|
127 | 127 | $contest_list=$paginator->all(); |
128 | - if(empty($contest_list)){ |
|
128 | + if (empty($contest_list)) { |
|
129 | 129 | return null; |
130 | 130 | } |
131 | 131 | |
@@ -160,13 +160,13 @@ discard block |
||
160 | 160 | ->join('contest', 'group_member.gid', '=', 'contest.gid') |
161 | 161 | ->leftJoin('contest_participant', 'contest.cid', '=', 'contest_participant.cid') |
162 | 162 | ->where( |
163 | - function ($query) { |
|
163 | + function($query) { |
|
164 | 164 | $query->where('public', 1) |
165 | 165 | ->where('audit_status', 1); |
166 | 166 | } |
167 | 167 | ) |
168 | 168 | ->orWhere( |
169 | - function ($query) use ($uid) { |
|
169 | + function($query) use ($uid) { |
|
170 | 170 | $query->where('group_member.uid', $uid) |
171 | 171 | ->where('group_member.role', '>', 0); |
172 | 172 | // ->where(function ($query) use ($uid) { |
@@ -231,14 +231,14 @@ discard block |
||
231 | 231 | } |
232 | 232 | } |
233 | 233 | |
234 | - public function registContest($cid,$uid) |
|
234 | + public function registContest($cid, $uid) |
|
235 | 235 | { |
236 | 236 | $registered=DB::table("contest_participant")->where([ |
237 | 237 | "cid"=>$cid, |
238 | 238 | "uid"=>$uid |
239 | 239 | ])->first(); |
240 | 240 | |
241 | - if(empty($registered)){ |
|
241 | + if (empty($registered)) { |
|
242 | 242 | DB::table("contest_participant")->insert([ |
243 | 243 | "cid"=>$cid, |
244 | 244 | "uid"=>$uid, |
@@ -539,7 +539,7 @@ discard block |
||
539 | 539 | "problem_detail" => $prob_detail |
540 | 540 | ]; |
541 | 541 | } |
542 | - usort($ret, function ($a, $b) { |
|
542 | + usort($ret, function($a, $b) { |
|
543 | 543 | if ($a["score"]==$b["score"]) { |
544 | 544 | if ($a["penalty"]==$b["penalty"]) { |
545 | 545 | return 0; |
@@ -586,7 +586,7 @@ discard block |
||
586 | 586 | "problem_detail" => $prob_detail |
587 | 587 | ]; |
588 | 588 | } |
589 | - usort($ret, function ($a, $b) { |
|
589 | + usort($ret, function($a, $b) { |
|
590 | 590 | if ($a["score"]==$b["score"]) { |
591 | 591 | if ($a["solved"]==$b["solved"]) { |
592 | 592 | return 0; |
@@ -679,7 +679,7 @@ discard block |
||
679 | 679 | { |
680 | 680 | return DB::table("contest_clarification")->where([ |
681 | 681 | "cid"=>$cid |
682 | - ])->where(function ($query) { |
|
682 | + ])->where(function($query) { |
|
683 | 683 | $query->where([ |
684 | 684 | "public"=>1 |
685 | 685 | ])->orWhere([ |
@@ -827,7 +827,7 @@ discard block |
||
827 | 827 | "users.id", |
828 | 828 | "=", |
829 | 829 | "submission.uid" |
830 | - )->where(function ($query) use ($frozen_time) { |
|
830 | + )->where(function($query) use ($frozen_time) { |
|
831 | 831 | $query->where( |
832 | 832 | "submission_date", |
833 | 833 | "<", |
@@ -1020,12 +1020,12 @@ discard block |
||
1020 | 1020 | public function updateProfessionalRate($cid) |
1021 | 1021 | { |
1022 | 1022 | $basic=$this->basic($cid); |
1023 | - if($basic["rated"]&&!$basic["is_rated"]){ |
|
1023 | + if ($basic["rated"] && !$basic["is_rated"]) { |
|
1024 | 1024 | $ratingCalculator=new RatingCalculator($cid); |
1025 | - if($ratingCalculator->calculate()){ |
|
1025 | + if ($ratingCalculator->calculate()) { |
|
1026 | 1026 | $ratingCalculator->storage(); |
1027 | 1027 | return true; |
1028 | - }else{ |
|
1028 | + } else { |
|
1029 | 1029 | return false; |
1030 | 1030 | } |
1031 | 1031 | } else { |
@@ -1035,7 +1035,7 @@ discard block |
||
1035 | 1035 | |
1036 | 1036 | public function arrangeContest($gid, $config, $problems) |
1037 | 1037 | { |
1038 | - DB::transaction(function () use ($gid, $config, $problems) { |
|
1038 | + DB::transaction(function() use ($gid, $config, $problems) { |
|
1039 | 1039 | $cid=DB::table($this->tableName)->insertGetId([ |
1040 | 1040 | "gid"=>$gid, |
1041 | 1041 | "name"=>$config["name"], |
@@ -39,7 +39,7 @@ |
||
39 | 39 | $groupModel=new GroupModel(); |
40 | 40 | $contestModel=new ContestModel(); |
41 | 41 | $basic_info=$groupModel->details($gcode); |
42 | - if(empty($basic_info)) return Redirect::route('group_index'); |
|
42 | + if (empty($basic_info)) return Redirect::route('group_index'); |
|
43 | 43 | $my_profile=$groupModel->userProfile(Auth::user()->id, $basic_info["gid"]); |
44 | 44 | $clearance=$groupModel->judgeClearance($basic_info["gid"], Auth::user()->id); |
45 | 45 | $member_list=$groupModel->userList($basic_info["gid"]); |
@@ -39,7 +39,9 @@ |
||
39 | 39 | $groupModel=new GroupModel(); |
40 | 40 | $contestModel=new ContestModel(); |
41 | 41 | $basic_info=$groupModel->details($gcode); |
42 | - if(empty($basic_info)) return Redirect::route('group_index'); |
|
42 | + if(empty($basic_info)) { |
|
43 | + return Redirect::route('group_index'); |
|
44 | + } |
|
43 | 45 | $my_profile=$groupModel->userProfile(Auth::user()->id, $basic_info["gid"]); |
44 | 46 | $clearance=$groupModel->judgeClearance($basic_info["gid"], Auth::user()->id); |
45 | 47 | $member_list=$groupModel->userList($basic_info["gid"]); |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | $all_data=$request->all(); |
45 | 45 | |
46 | 46 | $contestModel=new ContestModel(); |
47 | - return $contestModel->updateProfessionalRate($all_data["cid"])?ResponseModel::success(200):ResponseModel::err(1001); |
|
47 | + return $contestModel->updateProfessionalRate($all_data["cid"]) ?ResponseModel::success(200) : ResponseModel::err(1001); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | public function requestClarification(Request $request) |
@@ -101,16 +101,16 @@ discard block |
||
101 | 101 | $groupModel=new GroupModel(); |
102 | 102 | $basic=$contestModel->basic($all_data["cid"]); |
103 | 103 | |
104 | - if(!$basic["registration"]){ |
|
104 | + if (!$basic["registration"]) { |
|
105 | 105 | return ResponseModel::err(4003); |
106 | 106 | } |
107 | - if(strtotime($basic["registration_due"])<time()){ |
|
107 | + if (strtotime($basic["registration_due"])<time()) { |
|
108 | 108 | return ResponseModel::err(4004); |
109 | 109 | } |
110 | - if(!$basic["registant_type"]){ |
|
110 | + if (!$basic["registant_type"]) { |
|
111 | 111 | return ResponseModel::err(4005); |
112 | 112 | } |
113 | - if($basic["registant_type"]==1 && !$groupModel->isMember($basic["gid"], Auth::user()->id)){ |
|
113 | + if ($basic["registant_type"]==1 && !$groupModel->isMember($basic["gid"], Auth::user()->id)) { |
|
114 | 114 | return ResponseModel::err(4005); |
115 | 115 | } |
116 | 116 |
@@ -153,7 +153,7 @@ |
||
153 | 153 | $ret['secret_level'] = $secret_level; |
154 | 154 | } |
155 | 155 | DB::table('users_extra')->where('uid',$uid)->where('key',$key)->update($ret); |
156 | - }else{ |
|
156 | + } else{ |
|
157 | 157 | return DB::table('users_extra')->insertGetId( |
158 | 158 | [ |
159 | 159 | 'uid' => $uid, |
@@ -25,8 +25,8 @@ discard block |
||
25 | 25 | public function feed($uid=null) |
26 | 26 | { |
27 | 27 | $ret=[]; |
28 | - $solution=DB::table("problem_solution")->join("problem","problem.pid","=","problem_solution.pid")->where(["uid"=>$uid,"audit"=>1])->select("problem.pid as pid","pcode","title","problem_solution.created_at as created_at")->orderBy("problem_solution.created_at","DESC")->get()->all(); |
|
29 | - foreach($solution as &$s){ |
|
28 | + $solution=DB::table("problem_solution")->join("problem", "problem.pid", "=", "problem_solution.pid")->where(["uid"=>$uid, "audit"=>1])->select("problem.pid as pid", "pcode", "title", "problem_solution.created_at as created_at")->orderBy("problem_solution.created_at", "DESC")->get()->all(); |
|
29 | + foreach ($solution as &$s) { |
|
30 | 30 | $s["type"]="event"; |
31 | 31 | $s["color"]="wemd-orange"; |
32 | 32 | $s["icon"]="comment-check-outline"; |
@@ -92,14 +92,14 @@ discard block |
||
92 | 92 | ])->join("problem", "problem.pid", "=", "submission.pid")->select('pcode')->distinct()->get()->all(); |
93 | 93 | $ret["solvedCount"]=count($ret["solved"]); |
94 | 94 | // Casual |
95 | - $ret["rank"]=Cache::tags(['rank',$ret["id"]])->get("rank", "N/A"); |
|
96 | - $ret["rankTitle"]=Cache::tags(['rank',$ret["id"]])->get("title"); |
|
95 | + $ret["rank"]=Cache::tags(['rank', $ret["id"]])->get("rank", "N/A"); |
|
96 | + $ret["rankTitle"]=Cache::tags(['rank', $ret["id"]])->get("title"); |
|
97 | 97 | $ret["rankTitleColor"]=RankModel::getColor($ret["rankTitle"]); |
98 | 98 | // Professional |
99 | 99 | $ret["professionalTitle"]=RankModel::getProfessionalTitle($ret["professional_rate"]); |
100 | 100 | $ret["professionalTitleColor"]=RankModel::getProfessionalColor($ret["professionalTitle"]); |
101 | 101 | // Administration Group |
102 | - $ret["admin"]=$uid==1?1:0; |
|
102 | + $ret["admin"]=$uid==1 ? 1 : 0; |
|
103 | 103 | if (Cache::tags(['bing', 'pic'])->get(date("Y-m-d"))==null) { |
104 | 104 | $bing=new BingPhoto([ |
105 | 105 | 'locale' => 'zh-CN', |
@@ -111,9 +111,9 @@ discard block |
||
111 | 111 | return $ret; |
112 | 112 | } |
113 | 113 | |
114 | - public function getExtraInfo($uid,$secret_level = 0){ |
|
115 | - $ret = DB::table('users_extra')->where('uid',$uid)->get()->all(); |
|
116 | - $key_meaning = [ |
|
114 | + public function getExtraInfo($uid, $secret_level=0) { |
|
115 | + $ret=DB::table('users_extra')->where('uid', $uid)->get()->all(); |
|
116 | + $key_meaning=[ |
|
117 | 117 | 0 => 'gender', |
118 | 118 | 1 => 'contact', |
119 | 119 | 2 => 'school', |
@@ -121,20 +121,20 @@ discard block |
||
121 | 121 | 4 => 'location', |
122 | 122 | 5 => 'editor_left_width', |
123 | 123 | ]; |
124 | - $result = []; |
|
125 | - if(!empty($ret)){ |
|
124 | + $result=[]; |
|
125 | + if (!empty($ret)) { |
|
126 | 126 | foreach ($ret as $value) { |
127 | - if(empty($value['secret_level']) || $value['secret_level'] <= $secret_level){ |
|
128 | - $key_name = $key_meaning[$value['key']] ?? 'unknown'; |
|
129 | - $result[$key_name] = $value['value']; |
|
127 | + if (empty($value['secret_level']) || $value['secret_level']<=$secret_level) { |
|
128 | + $key_name=$key_meaning[$value['key']] ?? 'unknown'; |
|
129 | + $result[$key_name]=$value['value']; |
|
130 | 130 | } |
131 | 131 | } |
132 | 132 | } |
133 | 133 | return $result; |
134 | 134 | } |
135 | 135 | |
136 | - public function setExtraInfo($uid,$key_name,$value = null,$secret_level = -1){ |
|
137 | - $key_value = [ |
|
136 | + public function setExtraInfo($uid, $key_name, $value=null, $secret_level=-1) { |
|
137 | + $key_value=[ |
|
138 | 138 | 'gender' => 0, |
139 | 139 | 'contact' => 1, |
140 | 140 | 'school' => 2, |
@@ -143,31 +143,31 @@ discard block |
||
143 | 143 | 'editor_left_width' => 5, |
144 | 144 | //TODO... |
145 | 145 | ]; |
146 | - $key = $key_value[$key_name]; |
|
147 | - $ret = DB::table('users_extra')->where('uid',$uid)->where('key',$key)->first(); |
|
148 | - if(!empty($ret)){ |
|
146 | + $key=$key_value[$key_name]; |
|
147 | + $ret=DB::table('users_extra')->where('uid', $uid)->where('key', $key)->first(); |
|
148 | + if (!empty($ret)) { |
|
149 | 149 | unset($ret['id']); |
150 | - if(!is_null($value)){ |
|
151 | - $ret['value'] = $value; |
|
150 | + if (!is_null($value)) { |
|
151 | + $ret['value']=$value; |
|
152 | 152 | } |
153 | - if($secret_level != -1){ |
|
154 | - $ret['secret_level'] = $secret_level; |
|
153 | + if ($secret_level!=-1) { |
|
154 | + $ret['secret_level']=$secret_level; |
|
155 | 155 | } |
156 | - DB::table('users_extra')->where('uid',$uid)->where('key',$key)->update($ret); |
|
157 | - }else{ |
|
156 | + DB::table('users_extra')->where('uid', $uid)->where('key', $key)->update($ret); |
|
157 | + } else { |
|
158 | 158 | return DB::table('users_extra')->insertGetId( |
159 | 159 | [ |
160 | 160 | 'uid' => $uid, |
161 | 161 | 'key' => $key, |
162 | 162 | 'value' => $value, |
163 | - 'secret_level' => $secret_level == -1 ? 0 : $secret_level, |
|
163 | + 'secret_level' => $secret_level==-1 ? 0 : $secret_level, |
|
164 | 164 | ] |
165 | 165 | ); |
166 | 166 | } |
167 | 167 | } |
168 | 168 | |
169 | - public function unsetExtraInfoIfExist($uid,$key_name){ |
|
170 | - $key_value = [ |
|
169 | + public function unsetExtraInfoIfExist($uid, $key_name) { |
|
170 | + $key_value=[ |
|
171 | 171 | 'gender' => 0, |
172 | 172 | 'contact' => 1, |
173 | 173 | 'school' => 2, |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | 'editor_left_width' => 5, |
177 | 177 | //TODO... |
178 | 178 | ]; |
179 | - $key = $key_value[$key_name]; |
|
180 | - $ret = DB::table('users_extra')->where('uid',$uid)->where('key',$key)->delete(); |
|
179 | + $key=$key_value[$key_name]; |
|
180 | + $ret=DB::table('users_extra')->where('uid', $uid)->where('key', $key)->delete(); |
|
181 | 181 | } |
182 | 182 | } |
@@ -53,7 +53,7 @@ |
||
53 | 53 | if (!function_exists('emailVerified')) { |
54 | 54 | function emailVerified() |
55 | 55 | { |
56 | - if(Auth::check()){ |
|
56 | + if (Auth::check()) { |
|
57 | 57 | return !is_null(Auth::user()->email_verified_at); |
58 | 58 | } |
59 | 59 |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | $accountModel=new AccountModel(); |
29 | 29 | $info=$accountModel->detail(Auth::user()->id); |
30 | 30 | $feed=$accountModel->feed(Auth::user()->id); |
31 | - $extraInfo = $accountModel->getExtraInfo(Auth::user()->id,100); |
|
31 | + $extraInfo=$accountModel->getExtraInfo(Auth::user()->id, 100); |
|
32 | 32 | return view("account.dashboard", [ |
33 | 33 | 'page_title'=>"DashBoard", |
34 | 34 | 'site_title'=>"NOJ", |
@@ -45,10 +45,10 @@ discard block |
||
45 | 45 | { |
46 | 46 | $accountModel=new AccountModel(); |
47 | 47 | $info=$accountModel->detail(Auth::user()->id); |
48 | - if(!empty(session('last_email_send'))){ |
|
49 | - $email_cooldown = 300 - (time() - session('last_email_send')); |
|
48 | + if (!empty(session('last_email_send'))) { |
|
49 | + $email_cooldown=300-(time()-session('last_email_send')); |
|
50 | 50 | } |
51 | - $extraInfo = $accountModel->getExtraInfo(Auth::user()->id,100); |
|
51 | + $extraInfo=$accountModel->getExtraInfo(Auth::user()->id, 100); |
|
52 | 52 | return view("account.dashboard", [ |
53 | 53 | 'page_title'=>"Settings", |
54 | 54 | 'site_title'=>"NOJ", |
@@ -28,7 +28,7 @@ |
||
28 | 28 | $accountModel=new AccountModel(); |
29 | 29 | $info=$accountModel->detail($uid); |
30 | 30 | $feed=$accountModel->feed($uid); |
31 | - $extraInfo = $accountModel->getExtraInfo($uid,0); |
|
31 | + $extraInfo=$accountModel->getExtraInfo($uid, 0); |
|
32 | 32 | return view("account.dashboard", [ |
33 | 33 | 'page_title'=>$info["name"], |
34 | 34 | 'site_title'=>"NOJ", |