Passed
Pull Request — master (#86)
by Chenyi
05:01
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/RankModel.php 2 patches
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -46,7 +46,9 @@  discard block
 block discarded – undo
46 46
 
47 47
     public static function getColor($rankTitle)
48 48
     {
49
-        if(is_null($rankTitle)) return "";
49
+        if(is_null($rankTitle)) {
50
+            return "";
51
+        }
50 52
         return self::$casualRanking[$rankTitle];
51 53
     }
52 54
 
@@ -99,7 +101,9 @@  discard block
 block discarded – undo
99 101
     private function getRankTitle($rankVal)
100 102
     {
101 103
         foreach($this->casualRankingPer as $title=>$c){
102
-            if($rankVal<=$c) return $title;
104
+            if($rankVal<=$c) {
105
+                return $title;
106
+            }
103 107
         }
104 108
         return Arr::last($this->casualRankingPer);
105 109
     }
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 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
 {
@@ -46,20 +46,20 @@  discard block
 block discarded – undo
46 46
 
47 47
     public static function getColor($rankTitle)
48 48
     {
49
-        if(is_null($rankTitle)) return "";
49
+        if (is_null($rankTitle)) return "";
50 50
         return self::$casualRanking[$rankTitle];
51 51
     }
52 52
 
53 53
     public function list()
54 54
     {
55 55
         $rankList=Cache::tags(['rank'])->get('general');
56
-        $userInfoRaw=DB::table("users")->select("id as uid","avatar","name")->get()->all();
56
+        $userInfoRaw=DB::table("users")->select("id as uid", "avatar", "name")->get()->all();
57 57
         $userInfo=[];
58
-        foreach($userInfoRaw as $u){
58
+        foreach ($userInfoRaw as $u) {
59 59
             $userInfo[$u["uid"]]=$u;
60 60
         }
61
-        foreach($rankList as &$r){
62
-            $r["details"]=isset($userInfo[$r["uid"]])?$userInfo[$r["uid"]]:[];
61
+        foreach ($rankList as &$r) {
62
+            $r["details"]=isset($userInfo[$r["uid"]]) ? $userInfo[$r["uid"]] : [];
63 63
         }
64 64
         // var_dump($rankList); exit();
65 65
         return $rankList;
@@ -82,8 +82,8 @@  discard block
 block discarded – undo
82 82
                     $rankSolved=$rankItem["totValue"];
83 83
                 }
84 84
                 $rankTitle=$this->getRankTitle($rankValue);
85
-                Cache::tags(['rank',$rankItem["uid"]])->put("rank", $rankValue, 86400);
86
-                Cache::tags(['rank',$rankItem["uid"]])->put("title", $rankTitle, 86400);
85
+                Cache::tags(['rank', $rankItem["uid"]])->put("rank", $rankValue, 86400);
86
+                Cache::tags(['rank', $rankItem["uid"]])->put("title", $rankTitle, 86400);
87 87
                 $rankListCached[]=[
88 88
                     "uid"=>$rankItem["uid"],
89 89
                     "rank"=>$rankValue,
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
                 $tot+=$c;
109 109
             }
110 110
             foreach ($this->casualRankingPer as &$c) {
111
-                $c=round($c*$totUsers/$tot);
111
+                $c=round($c * $totUsers / $tot);
112 112
                 $cur+=$c;
113 113
                 $c=$cur;
114 114
             }
@@ -119,8 +119,8 @@  discard block
 block discarded – undo
119 119
 
120 120
     private function getRankTitle($rankVal)
121 121
     {
122
-        foreach($this->casualRankingPer as $title=>$c){
123
-            if($rankVal<=$c) return $title;
122
+        foreach ($this->casualRankingPer as $title=>$c) {
123
+            if ($rankVal<=$c) return $title;
124 124
         }
125 125
         return Arr::last($this->casualRankingPer);
126 126
     }
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.