Passed
Pull Request — master (#104)
by Chenyi
04:34
created
app/Jobs/ProcessSubmission.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
 {
15 15
     use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
16 16
 
17
-    public $tries = 5;
17
+    public $tries=5;
18 18
     protected $all_data=[];
19 19
 
20 20
     /**
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
 
41 41
     public function failed()
42 42
     {
43
-        $submissionModel = new SubmissionModel();
43
+        $submissionModel=new SubmissionModel();
44 44
         $submissionModel->updateSubmission($this->all_data["sid"], ["verdict"=>"Submission Error"]);
45 45
     }
46 46
 }
Please login to merge, or discard this patch.
app/Http/Controllers/Ajax/SubmissionController.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -57,14 +57,14 @@
 block discarded – undo
57 57
             return ResponseModel::err(3002);
58 58
         }
59 59
         $submissionModel=new SubmissionModel();
60
-        if($all_data["method"]==1){
60
+        if ($all_data["method"]==1) {
61 61
             // NOJ Share
62 62
             $status=$submissionModel->share($all_data["sid"], Auth::check() ? Auth::user()->id : null);
63
-            return empty($status)?ResponseModel::err(1001):ResponseModel::success(200, null, $status);
64
-        } elseif($all_data["method"]==2){
63
+            return empty($status) ?ResponseModel::err(1001) : ResponseModel::success(200, null, $status);
64
+        } elseif ($all_data["method"]==2) {
65 65
             // Pastebin
66 66
             $status=$submissionModel->sharePB($all_data["sid"], Auth::check() ? Auth::user()->id : null);
67
-            return empty($status)?ResponseModel::err(1001):ResponseModel::success(200, null, $status);
67
+            return empty($status) ?ResponseModel::err(1001) : ResponseModel::success(200, null, $status);
68 68
         } else {
69 69
             return ResponseModel::err(6002);
70 70
         }
Please login to merge, or discard this patch.
app/Http/Controllers/Ajax/ProblemController.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -111,8 +111,8 @@  discard block
 block discarded – undo
111 111
         if (empty($basic)) {
112 112
             return ResponseModel::err(3001);
113 113
         }
114
-        $ret=$problemModel->addSolution($pid,Auth::user()->id,$content);
115
-        return $ret?ResponseModel::success(200):ResponseModel::err(3003);
114
+        $ret=$problemModel->addSolution($pid, Auth::user()->id, $content);
115
+        return $ret ?ResponseModel::success(200) : ResponseModel::err(3003);
116 116
     }
117 117
     /**
118 118
      * The Ajax Problem Solution Discussion Update.
@@ -127,8 +127,8 @@  discard block
 block discarded – undo
127 127
         $problemModel=new ProblemModel();
128 128
         $psoid=$all_data["psoid"];
129 129
         $content=$all_data["content"];
130
-        $ret=$problemModel->updateSolution($psoid,Auth::user()->id,$content);
131
-        return $ret?ResponseModel::success(200):ResponseModel::err(3004);
130
+        $ret=$problemModel->updateSolution($psoid, Auth::user()->id, $content);
131
+        return $ret ?ResponseModel::success(200) : ResponseModel::err(3004);
132 132
     }
133 133
     /**
134 134
      * The Ajax Problem Solution Discussion Delete.
@@ -142,8 +142,8 @@  discard block
 block discarded – undo
142 142
         $all_data=$request->all();
143 143
         $problemModel=new ProblemModel();
144 144
         $psoid=$all_data["psoid"];
145
-        $ret=$problemModel->removeSolution($psoid,Auth::user()->id);
146
-        return $ret?ResponseModel::success(200):ResponseModel::err(3004);
145
+        $ret=$problemModel->removeSolution($psoid, Auth::user()->id);
146
+        return $ret ?ResponseModel::success(200) : ResponseModel::err(3004);
147 147
     }
148 148
     /**
149 149
      * The Ajax Problem Solution Discussion Vote.
@@ -158,8 +158,8 @@  discard block
 block discarded – undo
158 158
         $problemModel=new ProblemModel();
159 159
         $psoid=$all_data["psoid"];
160 160
         $type=$all_data["type"];
161
-        $ret=$problemModel->voteSolution($psoid,Auth::user()->id,$type);
162
-        return $ret["ret"]?ResponseModel::success(200,null,["votes"=>$ret["votes"],"select"=>$ret["select"]]):ResponseModel::err(3004);
161
+        $ret=$problemModel->voteSolution($psoid, Auth::user()->id, $type);
162
+        return $ret["ret"] ?ResponseModel::success(200, null, ["votes"=>$ret["votes"], "select"=>$ret["select"]]) : ResponseModel::err(3004);
163 163
     }
164 164
     /**
165 165
      * The Ajax Problem Solution Submit.
Please login to merge, or discard this patch.
app/Models/JudgerModel.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -61,7 +61,7 @@
 block discarded – undo
61 61
     {
62 62
         $curl=curl_init();
63 63
 
64
-        if($curl===false) return [];
64
+        if ($curl===false) return [];
65 65
 
66 66
         curl_setopt_array($curl, array(
67 67
             CURLOPT_PORT => $port,
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/RankModel.php 1 patch
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
     }
Please login to merge, or discard this patch.
app/Models/Rating/RatingCalculator.php 1 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($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
 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
         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
 block discarded – undo
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
 block discarded – undo
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
                     }
Please login to merge, or discard this patch.
app/Http/Controllers/GroupController.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -39,7 +39,7 @@
 block discarded – undo
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"]);
Please login to merge, or discard this patch.