Passed
Pull Request — master (#88)
by Chenyi
04:29
created
app/Http/Controllers/VirtualJudge/Judge.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -398,7 +398,7 @@
 block discarded – undo
398 398
      */
399 399
     private function get_last_uva($earliest)
400 400
     {
401
-        $ret = [];
401
+        $ret=[];
402 402
         if (!$earliest) {
403 403
             return $ret;
404 404
         }
Please login to merge, or discard this patch.
app/Models/AccountModel.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -25,8 +25,8 @@  discard block
 block discarded – undo
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")->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")->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";
@@ -91,8 +91,8 @@  discard block
 block discarded – undo
91 91
             "verdict"=>"Accepted"
92 92
         ])->join("problem", "problem.pid", "=", "submission.pid")->select('pcode')->distinct()->get()->all();
93 93
         $ret["solvedCount"]=count($ret["solved"]);
94
-        $ret["rank"]=Cache::tags(['rank',$ret["id"]])->get("rank", "N/A");
95
-        $ret["rankTitle"]=Cache::tags(['rank',$ret["id"]])->get("title");
94
+        $ret["rank"]=Cache::tags(['rank', $ret["id"]])->get("rank", "N/A");
95
+        $ret["rankTitle"]=Cache::tags(['rank', $ret["id"]])->get("title");
96 96
         $ret["rankTitleColor"]=RankModel::getColor($ret["rankTitle"]);
97 97
         if (Cache::tags(['bing', 'pic'])->get(date("Y-m-d"))==null) {
98 98
             $bing=new BingPhoto([
Please login to merge, or discard this patch.
app/Http/Controllers/Auth/ForgotPasswordController.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@
 block discarded – undo
37 37
      */
38 38
     public function showLinkRequestForm()
39 39
     {
40
-        return view('auth.passwords.email',[
40
+        return view('auth.passwords.email', [
41 41
             'page_title'=>"Reset Password",
42 42
             'site_title'=>"NOJ",
43 43
             'navigation' => "Account"
Please login to merge, or discard this patch.
app/Http/Controllers/Auth/ResetPasswordController.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -52,9 +52,9 @@
 block discarded – undo
52 52
      * @param  string|null  $token
53 53
      * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
54 54
      */
55
-    public function showResetForm(Request $request, $token = null)
55
+    public function showResetForm(Request $request, $token=null)
56 56
     {
57
-        return view('auth.passwords.reset',[
57
+        return view('auth.passwords.reset', [
58 58
             'token' => $token,
59 59
             'email' => $request->email,
60 60
             'page_title'=>"Reset Password",
Please login to merge, or discard this patch.
app/Models/Rating/RatingCalculator.php 2 patches
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -78,7 +78,7 @@
 block discarded – undo
78 78
             $mid = floor(($right + $left)/2);
79 79
             if($this->getSeed($mid) < $rank){
80 80
                 $right = $mid;
81
-            }else{
81
+            } else{
82 82
                 $left = $mid;
83 83
             }
84 84
         }
Please login to merge, or discard this patch.
Spacing   +70 added lines, -70 removed lines patch added patch discarded remove patch
@@ -17,14 +17,14 @@  discard block
 block discarded – undo
17 17
     public $totParticipants=0;
18 18
     public $INITIAL_RATING=1500;
19 19
 
20
-    public function __construct($cid){
20
+    public function __construct($cid) {
21 21
         $this->cid=$cid;
22 22
 
23 23
         // get rank
24 24
         $this->getRecord();
25 25
     }
26 26
 
27
-    private function getRecord(){
27
+    private function getRecord() {
28 28
         $contestRankRaw=Cache::tags(['contest', 'rank'])->get($this->$cid);
29 29
 
30 30
         if ($contestRankRaw==null) {
@@ -32,8 +32,8 @@  discard block
 block discarded – undo
32 32
             $contestRankRaw=$contestModel->contestRankCache($this->$cid);
33 33
         }
34 34
 
35
-        $this->totParticipants = count($ret);
36
-        foreach($contestRankRaw as $c){
35
+        $this->totParticipants=count($ret);
36
+        foreach ($contestRankRaw as $c) {
37 37
             $this->contestants[]=[
38 38
                 "uid"=>$c["uid"],
39 39
                 "points"=>$c["score"],
@@ -42,121 +42,121 @@  discard block
 block discarded – undo
42 42
         }
43 43
     }
44 44
 
45
-    private function reassignRank(){
45
+    private function reassignRank() {
46 46
         $this->sort("points");
47
-        $idx = 0;
48
-        $points = $this->contestants[0]["points"];
49
-        $i = 1;
50
-        while($i < $this->totParticipants){
51
-            if($this->contestants[$i]["points"] < $points){
52
-                $j = $idx;
53
-                while($j < $i){
54
-                    $this->contestants[$j]["rank"] = $i;
55
-                    $j += 1;
47
+        $idx=0;
48
+        $points=$this->contestants[0]["points"];
49
+        $i=1;
50
+        while ($i<$this->totParticipants) {
51
+            if ($this->contestants[$i]["points"]<$points) {
52
+                $j=$idx;
53
+                while ($j<$i) {
54
+                    $this->contestants[$j]["rank"]=$i;
55
+                    $j+=1;
56 56
                 }
57
-                $idx = $i;
58
-                $points = $this->contestants[$i]["points"];
57
+                $idx=$i;
58
+                $points=$this->contestants[$i]["points"];
59 59
             }
60
-            $i += 1;
60
+            $i+=1;
61 61
         }
62
-        $j = $idx;
63
-        while($j < $this->totParticipants){
64
-            $this->contestants[$j]["rank"] = $this->totParticipants;
65
-            $j += 1;
62
+        $j=$idx;
63
+        while ($j<$this->totParticipants) {
64
+            $this->contestants[$j]["rank"]=$this->totParticipants;
65
+            $j+=1;
66 66
         }
67 67
     }
68 68
 
69
-    private function getEloWinProbability($Ra, $Rb){
70
-        return 1.0 / (1 + pow(10, ($Rb-$Ra)/400.0));
69
+    private function getEloWinProbability($Ra, $Rb) {
70
+        return 1.0 / (1+pow(10, ($Rb-$Ra) / 400.0));
71 71
     }
72 72
 
73
-    private function getSeed($rating){
74
-        $result = 1.0;
75
-        foreach($this->contestants as $other){
76
-            $result += $this->getEloWinProbability($other["rating"], $rating);
73
+    private function getSeed($rating) {
74
+        $result=1.0;
75
+        foreach ($this->contestants as $other) {
76
+            $result+=$this->getEloWinProbability($other["rating"], $rating);
77 77
         }
78 78
         return $result;
79 79
     }
80 80
 
81
-    private function getRatingToRank($rank){
81
+    private function getRatingToRank($rank) {
82 82
         $left=1;
83 83
         $right=8000;
84
-        while($right - $left > 1){
85
-            $mid = floor(($right + $left)/2);
86
-            if($this->getSeed($mid) < $rank){
87
-                $right = $mid;
88
-            }else{
89
-                $left = $mid;
84
+        while ($right-$left>1) {
85
+            $mid=floor(($right+$left) / 2);
86
+            if ($this->getSeed($mid)<$rank) {
87
+                $right=$mid;
88
+            } else {
89
+                $left=$mid;
90 90
             }
91 91
         }
92 92
         return $left;
93 93
     }
94 94
 
95
-    private function sort($key){
96
-        usort($this->contestants, function ($a, $b) use ($key) {
95
+    private function sort($key) {
96
+        usort($this->contestants, function($a, $b) use ($key) {
97 97
             return $b[$key] <=> $a[$key];
98 98
         });
99 99
     }
100 100
 
101
-    public function calculate(){
102
-        if(empty($this->contestants)){
101
+    public function calculate() {
102
+        if (empty($this->contestants)) {
103 103
             return;
104 104
         }
105 105
 
106 106
         // recalc rank
107 107
         $this->reassignRank();
108 108
 
109
-        foreach($this->contestants as $member){
110
-            $member["seed"] = 1.0;
111
-            foreach($this->contestants as $other){
112
-                if($member["uid"] != $other["uid"]){
113
-                    $member["seed"] += $this->getEloWinProbability($other["rating"], $member["rating"]);
109
+        foreach ($this->contestants as $member) {
110
+            $member["seed"]=1.0;
111
+            foreach ($this->contestants as $other) {
112
+                if ($member["uid"]!=$other["uid"]) {
113
+                    $member["seed"]+=$this->getEloWinProbability($other["rating"], $member["rating"]);
114 114
                 }
115 115
             }
116 116
         }
117 117
 
118
-        foreach($this->contestants as $contestant){
119
-            $midRank = sqrt($contestant["rank"] * $contestant["seed"]);
120
-            $contestant["needRating"] = $this->getRatingToRank($midRank);
121
-            $contestant["delta"] = floor(($contestant["needRating"] - $contestant["rating"])/2);
118
+        foreach ($this->contestants as $contestant) {
119
+            $midRank=sqrt($contestant["rank"] * $contestant["seed"]);
120
+            $contestant["needRating"]=$this->getRatingToRank($midRank);
121
+            $contestant["delta"]=floor(($contestant["needRating"]-$contestant["rating"]) / 2);
122 122
         }
123 123
 
124 124
         $this->sort("rating");
125 125
 
126 126
         // DO some adjuct
127 127
         // Total sum should not be more than ZERO.
128
-        $sum = 0;
128
+        $sum=0;
129 129
 
130
-        foreach($this->contestants as $contestant){
131
-            $sum += $contestant["delta"];
130
+        foreach ($this->contestants as $contestant) {
131
+            $sum+=$contestant["delta"];
132 132
         }
133
-        $inc = -floor($sum / $this->totParticipants) - 1;
134
-        foreach($this->contestants as $contestant){
135
-            $contestant["delta"] += $inc;
133
+        $inc=-floor($sum / $this->totParticipants)-1;
134
+        foreach ($this->contestants as $contestant) {
135
+            $contestant["delta"]+=$inc;
136 136
         }
137 137
 
138 138
         // Sum of top-4*sqrt should be adjusted to ZERO.
139 139
 
140
-        $sum = 0;
141
-        $zeroSumCount = min(intval(4*round(sqrt($this->totParticipants))), $this->totParticipants);
140
+        $sum=0;
141
+        $zeroSumCount=min(intval(4 * round(sqrt($this->totParticipants))), $this->totParticipants);
142 142
 
143
-        for($i=0;$i<$zeroSumCount;$i++){
144
-            $sum += $this->contestants[i]["delta"];
143
+        for ($i=0; $i<$zeroSumCount; $i++) {
144
+            $sum+=$this->contestants[i]["delta"];
145 145
         }
146 146
 
147
-        $inc = min(max(-floor($sum / $zeroSumCount), -10), 0);
147
+        $inc=min(max(-floor($sum / $zeroSumCount), -10), 0);
148 148
 
149
-        for($i=0;$i<$zeroSumCount;$i++){
150
-            $this->contestants[i]["delta"] += $inc;
149
+        for ($i=0; $i<$zeroSumCount; $i++) {
150
+            $this->contestants[i]["delta"]+=$inc;
151 151
         }
152 152
 
153 153
         return $this->validateDeltas();
154 154
     }
155 155
 
156
-    public function storage(){
156
+    public function storage() {
157 157
         $contestants=$this->contestants;
158
-        DB::transaction(function () use ($contestants) {
159
-            foreach($contestants as $contestant){
158
+        DB::transaction(function() use ($contestants) {
159
+            foreach ($contestants as $contestant) {
160 160
                 $newRating=$contestant["rating"]+$contestant["delta"];
161 161
                 DB::table("users")->where([
162 162
                     "uid"=>$contestant["uid"]
@@ -167,20 +167,20 @@  discard block
 block discarded – undo
167 167
         }, 5);
168 168
     }
169 169
 
170
-    private function validateDeltas(){
170
+    private function validateDeltas() {
171 171
         $this->sort("points");
172 172
 
173
-        for($i=0;$i<$this->totParticipants;$i++){
174
-            for($j=$i+1;$j<$this->totParticipants;$j++){
175
-                if($this->contestants[i]["rating"] > $this->contestants[j]["rating"]){
176
-                    if($this->contestants[i]["rating"] + $this->contestants[i]["delta"] < $this->contestants[j]["rating"] + $this->contestants[j]["delta"]){
173
+        for ($i=0; $i<$this->totParticipants; $i++) {
174
+            for ($j=$i+1; $j<$this->totParticipants; $j++) {
175
+                if ($this->contestants[i]["rating"]>$this->contestants[j]["rating"]) {
176
+                    if ($this->contestants[i]["rating"]+$this->contestants[i]["delta"]<$this->contestants[j]["rating"]+$this->contestants[j]["delta"]) {
177 177
                         Log::warning("First rating invariant failed: {$this->contestants[i]["uid"]} vs. {$this->contestants[j]["uid"]}.");
178 178
                         return false;
179 179
                     }
180 180
                 }
181 181
 
182
-                if($this->contestants[i]["rating"] < $this->contestants[j]["rating"]){
183
-                    if($this->contestants[i]["delta"] < $this->contestants[j]["delta"]){
182
+                if ($this->contestants[i]["rating"]<$this->contestants[j]["rating"]) {
183
+                    if ($this->contestants[i]["delta"]<$this->contestants[j]["delta"]) {
184 184
                         Log::warning("Second rating invariant failed: {$this->contestants[i]["uid"]} vs.  {$this->contestants[j]["uid"]}.");
185 185
                         return false;
186 186
                     }
Please login to merge, or discard this patch.
app/Models/RankModel.php 2 patches
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
 use Illuminate\Database\Eloquent\Model;
7 7
 use Illuminate\Support\Facades\DB;
8 8
 use Illuminate\Support\Arr;
9
-use Cache,Redis;
9
+use Cache, Redis;
10 10
 
11 11
 class RankModel extends Model
12 12
 {
@@ -64,26 +64,26 @@  discard block
 block discarded – undo
64 64
 
65 65
     public static function getColor($rankTitle)
66 66
     {
67
-        if(is_null($rankTitle)) return "";
67
+        if (is_null($rankTitle)) return "";
68 68
         return self::$casualRanking[$rankTitle];
69 69
     }
70 70
 
71 71
     public static function getProfessionalColor($rankTitle)
72 72
     {
73
-        if(is_null($rankTitle)) return self::$professionalRanking["None"];
73
+        if (is_null($rankTitle)) return self::$professionalRanking["None"];
74 74
         return self::$professionalRanking[$rankTitle];
75 75
     }
76 76
 
77 77
     public function list()
78 78
     {
79 79
         $rankList=Cache::tags(['rank'])->get('general');
80
-        $userInfoRaw=DB::table("users")->select("id as uid","avatar","name")->get()->all();
80
+        $userInfoRaw=DB::table("users")->select("id as uid", "avatar", "name")->get()->all();
81 81
         $userInfo=[];
82
-        foreach($userInfoRaw as $u){
82
+        foreach ($userInfoRaw as $u) {
83 83
             $userInfo[$u["uid"]]=$u;
84 84
         }
85
-        foreach($rankList as &$r){
86
-            $r["details"]=isset($userInfo[$r["uid"]])?$userInfo[$r["uid"]]:[];
85
+        foreach ($rankList as &$r) {
86
+            $r["details"]=isset($userInfo[$r["uid"]]) ? $userInfo[$r["uid"]] : [];
87 87
         }
88 88
         // var_dump($rankList); exit();
89 89
         return $rankList;
@@ -106,8 +106,8 @@  discard block
 block discarded – undo
106 106
                     $rankSolved=$rankItem["totValue"];
107 107
                 }
108 108
                 $rankTitle=$this->getRankTitle($rankValue);
109
-                Cache::tags(['rank',$rankItem["uid"]])->put("rank", $rankValue, 86400);
110
-                Cache::tags(['rank',$rankItem["uid"]])->put("title", $rankTitle, 86400);
109
+                Cache::tags(['rank', $rankItem["uid"]])->put("rank", $rankValue, 86400);
110
+                Cache::tags(['rank', $rankItem["uid"]])->put("title", $rankTitle, 86400);
111 111
                 $rankListCached[]=[
112 112
                     "uid"=>$rankItem["uid"],
113 113
                     "rank"=>$rankValue,
@@ -124,14 +124,14 @@  discard block
 block discarded – undo
124 124
 
125 125
     private function getProfessionalRanking()
126 126
     {
127
-        $professionalRankList = [];
128
-        $verifiedUsers = DB::table("users")->select("professional_rate","id as uid","avatar","name")->get()->all();
129
-        $rankIter = 0;
130
-        foreach($verifiedUsers as $user) {
131
-            $rankVal = $user['professional_rate'];
132
-            $rankTitle = $this->getProfessionalTitle($rankVal);
133
-            $titleColor = self::getProfessionalColor($rankTitle);
134
-            $professionalRankList[$rankIter++] = [
127
+        $professionalRankList=[];
128
+        $verifiedUsers=DB::table("users")->select("professional_rate", "id as uid", "avatar", "name")->get()->all();
129
+        $rankIter=0;
130
+        foreach ($verifiedUsers as $user) {
131
+            $rankVal=$user['professional_rate'];
132
+            $rankTitle=$this->getProfessionalTitle($rankVal);
133
+            $titleColor=self::getProfessionalColor($rankTitle);
134
+            $professionalRankList[$rankIter++]=[
135 135
                 "name"=>$user["name"],
136 136
                 "uid"=>$user["uid"],
137 137
                 "avatar"=>$user["avatar"],
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
                 $tot+=$c;
154 154
             }
155 155
             foreach ($this->casualRankingPer as &$c) {
156
-                $c=round($c*$totUsers/$tot);
156
+                $c=round($c * $totUsers / $tot);
157 157
                 $cur+=$c;
158 158
                 $c=$cur;
159 159
             }
@@ -164,16 +164,16 @@  discard block
 block discarded – undo
164 164
 
165 165
     private function getRankTitle($rankVal)
166 166
     {
167
-        foreach($this->casualRankingPer as $title=>$c){
168
-            if($rankVal<=$c) return $title;
167
+        foreach ($this->casualRankingPer as $title=>$c) {
168
+            if ($rankVal<=$c) return $title;
169 169
         }
170 170
         return Arr::last($this->casualRankingPer);
171 171
     }
172 172
 
173 173
     private function getProfessionalTitle($rankVal)
174 174
     {
175
-        foreach($this->professionalRankingPer as $title=>$point) {
176
-            if($rankVal >= $point) return $title;
175
+        foreach ($this->professionalRankingPer as $title=>$point) {
176
+            if ($rankVal>=$point) return $title;
177 177
         }
178 178
         return Arr::last($this->professionalRankingPer);
179 179
     }
Please login to merge, or discard this patch.
Braces   +12 added lines, -4 removed lines patch added patch discarded remove patch
@@ -64,13 +64,17 @@  discard block
 block discarded – undo
64 64
 
65 65
     public static function getColor($rankTitle)
66 66
     {
67
-        if(is_null($rankTitle)) return "";
67
+        if(is_null($rankTitle)) {
68
+            return "";
69
+        }
68 70
         return self::$casualRanking[$rankTitle];
69 71
     }
70 72
 
71 73
     public static function getProfessionalColor($rankTitle)
72 74
     {
73
-        if(is_null($rankTitle)) return self::$professionalRanking["None"];
75
+        if(is_null($rankTitle)) {
76
+            return self::$professionalRanking["None"];
77
+        }
74 78
         return self::$professionalRanking[$rankTitle];
75 79
     }
76 80
 
@@ -165,7 +169,9 @@  discard block
 block discarded – undo
165 169
     private function getRankTitle($rankVal)
166 170
     {
167 171
         foreach($this->casualRankingPer as $title=>$c){
168
-            if($rankVal<=$c) return $title;
172
+            if($rankVal<=$c) {
173
+                return $title;
174
+            }
169 175
         }
170 176
         return Arr::last($this->casualRankingPer);
171 177
     }
@@ -173,7 +179,9 @@  discard block
 block discarded – undo
173 179
     private function getProfessionalTitle($rankVal)
174 180
     {
175 181
         foreach($this->professionalRankingPer as $title=>$point) {
176
-            if($rankVal >= $point) return $title;
182
+            if($rankVal >= $point) {
183
+                return $title;
184
+            }
177 185
         }
178 186
         return Arr::last($this->professionalRankingPer);
179 187
     }
Please login to merge, or discard this patch.