@@ -14,14 +14,14 @@ discard block |
||
14 | 14 | * |
15 | 15 | * @var string |
16 | 16 | */ |
17 | - protected $signature = 'babel:update {extension : The package name of the extension}'; |
|
17 | + protected $signature='babel:update {extension : The package name of the extension}'; |
|
18 | 18 | |
19 | 19 | /** |
20 | 20 | * The console command description. |
21 | 21 | * |
22 | 22 | * @var string |
23 | 23 | */ |
24 | - protected $description = 'Update a given Babel Extension to NOJ'; |
|
24 | + protected $description='Update a given Babel Extension to NOJ'; |
|
25 | 25 | |
26 | 26 | /** |
27 | 27 | * Create a new command instance. |
@@ -40,8 +40,8 @@ discard block |
||
40 | 40 | */ |
41 | 41 | public function handle() |
42 | 42 | { |
43 | - $extension = $this->argument('extension'); |
|
44 | - $output = new BufferedOutput(); |
|
43 | + $extension=$this->argument('extension'); |
|
44 | + $output=new BufferedOutput(); |
|
45 | 45 | $this->line("Updating <fg=green>$extension</>"); |
46 | 46 | try { |
47 | 47 | $BabelConfig=json_decode(file_get_contents(babel_path("Extension/$extension/babel.json")), true); |
@@ -90,8 +90,8 @@ discard block |
||
90 | 90 | if (!is_dir($dir)) { |
91 | 91 | return; |
92 | 92 | } |
93 | - $it = new \RecursiveDirectoryIterator($dir, \RecursiveDirectoryIterator::SKIP_DOTS); |
|
94 | - $files = new \RecursiveIteratorIterator($it, \RecursiveIteratorIterator::CHILD_FIRST); |
|
93 | + $it=new \RecursiveDirectoryIterator($dir, \RecursiveDirectoryIterator::SKIP_DOTS); |
|
94 | + $files=new \RecursiveIteratorIterator($it, \RecursiveIteratorIterator::CHILD_FIRST); |
|
95 | 95 | foreach ($files as $file) { |
96 | 96 | if ($file->isDir()) { |
97 | 97 | rmdir($file->getRealPath()); |
@@ -14,14 +14,14 @@ discard block |
||
14 | 14 | * |
15 | 15 | * @var string |
16 | 16 | */ |
17 | - protected $signature = 'babel:require {extension : The package name of the extension} {--exception}'; |
|
17 | + protected $signature='babel:require {extension : The package name of the extension} {--exception}'; |
|
18 | 18 | |
19 | 19 | /** |
20 | 20 | * The console command description. |
21 | 21 | * |
22 | 22 | * @var string |
23 | 23 | */ |
24 | - protected $description = 'Download a given Babel Extension to NOJ'; |
|
24 | + protected $description='Download a given Babel Extension to NOJ'; |
|
25 | 25 | |
26 | 26 | /** |
27 | 27 | * Create a new command instance. |
@@ -40,9 +40,9 @@ discard block |
||
40 | 40 | */ |
41 | 41 | public function handle() |
42 | 42 | { |
43 | - $extension = $this->argument('extension'); |
|
44 | - $exception = $this->option('exception'); |
|
45 | - $output = new BufferedOutput(); |
|
43 | + $extension=$this->argument('extension'); |
|
44 | + $exception=$this->option('exception'); |
|
45 | + $output=new BufferedOutput(); |
|
46 | 46 | if (is_dir(babel_path("Extension/$extension/"))) { |
47 | 47 | if (!$exception) { |
48 | 48 | $this->line("\n <bg=red;fg=white> Exception </> : <fg=yellow>An extension named <fg=green>$extension</> already took place, did you mean <fg=green>php artisan bable:update $extension</>?</>\n"); |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | mkdir(babel_path("Tmp/$extension/")); |
75 | 75 | } |
76 | 76 | try { |
77 | - $zipFile = new ZipFile(); |
|
77 | + $zipFile=new ZipFile(); |
|
78 | 78 | $zipFile->openFile(babel_path("Tmp/$filename"))->extractTo(babel_path("Tmp/$extension/"))->close(); |
79 | 79 | $babelPath=glob_recursive(babel_path("Tmp/$extension/babel.json")); |
80 | 80 | if (empty($babelPath)) { |
@@ -123,8 +123,8 @@ discard block |
||
123 | 123 | if (!is_dir($dir)) { |
124 | 124 | return; |
125 | 125 | } |
126 | - $it = new \RecursiveDirectoryIterator($dir, \RecursiveDirectoryIterator::SKIP_DOTS); |
|
127 | - $files = new \RecursiveIteratorIterator($it, \RecursiveIteratorIterator::CHILD_FIRST); |
|
126 | + $it=new \RecursiveDirectoryIterator($dir, \RecursiveDirectoryIterator::SKIP_DOTS); |
|
127 | + $files=new \RecursiveIteratorIterator($it, \RecursiveIteratorIterator::CHILD_FIRST); |
|
128 | 128 | foreach ($files as $file) { |
129 | 129 | if ($file->isDir()) { |
130 | 130 | rmdir($file->getRealPath()); |
@@ -12,14 +12,14 @@ discard block |
||
12 | 12 | * |
13 | 13 | * @var string |
14 | 14 | */ |
15 | - protected $signature = 'babel:uninstall {extension : The package name of the extension}'; |
|
15 | + protected $signature='babel:uninstall {extension : The package name of the extension}'; |
|
16 | 16 | |
17 | 17 | /** |
18 | 18 | * The console command description. |
19 | 19 | * |
20 | 20 | * @var string |
21 | 21 | */ |
22 | - protected $description = 'Uninstall a given Babel Extension to NOJ'; |
|
22 | + protected $description='Uninstall a given Babel Extension to NOJ'; |
|
23 | 23 | |
24 | 24 | /** |
25 | 25 | * Create a new command instance. |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | */ |
39 | 39 | public function handle() |
40 | 40 | { |
41 | - $extension = $this->argument('extension'); |
|
41 | + $extension=$this->argument('extension'); |
|
42 | 42 | $submitter=self::create($extension, $this); |
43 | 43 | if (!is_null($submitter)) { |
44 | 44 | $submitter->uninstall(); |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | } catch (ErrorException $e) { |
57 | 57 | } catch (Exception $e) { |
58 | 58 | } |
59 | - $className = "App\\Babel\\Extension\\$oj\\$installerProvider"; |
|
59 | + $className="App\\Babel\\Extension\\$oj\\$installerProvider"; |
|
60 | 60 | if (class_exists($className)) { |
61 | 61 | return new $className($class); |
62 | 62 | } else { |
@@ -84,9 +84,9 @@ |
||
84 | 84 | $installed_timestamp=intval($info["compiler_timestamp"]); |
85 | 85 | } |
86 | 86 | $latest_timestamp=$installed_timestamp; |
87 | - $ConpilerConfig = glob(babel_path("Extension/$ocode/compiler/*.*")); |
|
87 | + $ConpilerConfig=glob(babel_path("Extension/$ocode/compiler/*.*")); |
|
88 | 88 | foreach ($ConpilerConfig as $file) { |
89 | - if (intval(basename($file)) > $installed_timestamp) { |
|
89 | + if (intval(basename($file))>$installed_timestamp) { |
|
90 | 90 | try { |
91 | 91 | $this->commitCompiler($file, json_decode(file_get_contents($file), true)); |
92 | 92 | $latest_timestamp=intval(basename($file)); |
@@ -39,8 +39,8 @@ discard block |
||
39 | 39 | //writing database |
40 | 40 | $this->transactionDB(); |
41 | 41 | |
42 | - }catch(Throwable $e){ |
|
43 | - if ($e->getMessage()!==""){ |
|
42 | + } catch (Throwable $e) { |
|
43 | + if ($e->getMessage()!=="") { |
|
44 | 44 | $this->command->line("\n <bg=red;fg=white> {$e->getMessage()} </>\n"); |
45 | 45 | } |
46 | 46 | } |
@@ -59,12 +59,12 @@ discard block |
||
59 | 59 | public function __construct($class) |
60 | 60 | { |
61 | 61 | $this->command=$class; |
62 | - $this->versionParser = new VersionConstraintParser(); |
|
62 | + $this->versionParser=new VersionConstraintParser(); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | private function parseVersion() |
66 | 66 | { |
67 | - if(empty($this->babelConfig)){ |
|
67 | + if (empty($this->babelConfig)) { |
|
68 | 68 | throw new Exception('Missing babel.json Config file.'); |
69 | 69 | } |
70 | 70 | |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | |
135 | 135 | DB::commit(); |
136 | 136 | |
137 | - }catch(Throwable $e){ |
|
137 | + } catch (Throwable $e) { |
|
138 | 138 | DB::rollback(); |
139 | 139 | if ($e->getMessage()!=="") { |
140 | 140 | $this->command->line("\n <bg=red;fg=white> {$e->getMessage()} </>\n"); |
@@ -48,11 +48,11 @@ discard block |
||
48 | 48 | |
49 | 49 | $groupModel=new GroupModel(); |
50 | 50 | $clearance=$groupModel->judgeClearance($all_data["gid"], Auth::user()->id); |
51 | - if ($clearance < 2) { |
|
51 | + if ($clearance<2) { |
|
52 | 52 | return ResponseModel::err(7002); |
53 | 53 | } |
54 | - $tags = $groupModel->problemTags($all_data['gid'],$all_data['pid']); |
|
55 | - if(in_array($all_data['tag'],$tags)){ |
|
54 | + $tags=$groupModel->problemTags($all_data['gid'], $all_data['pid']); |
|
55 | + if (in_array($all_data['tag'], $tags)) { |
|
56 | 56 | return ResponseModel::err(7007); |
57 | 57 | } |
58 | 58 | |
@@ -84,9 +84,9 @@ discard block |
||
84 | 84 | $request->validate([ |
85 | 85 | 'gid' => 'required|string', |
86 | 86 | ]); |
87 | - $gid = $request->input('gid'); |
|
87 | + $gid=$request->input('gid'); |
|
88 | 88 | $groupModel=new GroupModel(); |
89 | - if($groupModel->judgeClearance($gid,Auth::user()->id) < 2) { |
|
89 | + if ($groupModel->judgeClearance($gid, Auth::user()->id)<2) { |
|
90 | 90 | return ResponseModel::err(2001); |
91 | 91 | } |
92 | 92 | $groupModel->refreshElo($gid); |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | "oid"=>$oid, |
60 | 60 | "available"=>1, |
61 | 61 | "status"=>0 |
62 | - ])->orderBy('usage','desc')->get()->first(); |
|
62 | + ])->orderBy('usage', 'desc')->get()->first(); |
|
63 | 63 | |
64 | 64 | return $serverList; |
65 | 65 | } |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | { |
69 | 69 | $serverList=DB::table("judge_server")->where(["oid"=>$oid])->get()->all(); |
70 | 70 | foreach ($serverList as &$server) { |
71 | - $server["status_parsed"]=is_null($server["status"])?self::$status["-1"]:self::$status[$server["status"]]; |
|
71 | + $server["status_parsed"]=is_null($server["status"]) ?self::$status["-1"] : self::$status[$server["status"]]; |
|
72 | 72 | } |
73 | 73 | return $serverList; |
74 | 74 | } |
@@ -14,36 +14,36 @@ discard block |
||
14 | 14 | public $totParticipants=0; |
15 | 15 | public $INITIAL_RATING=1500; |
16 | 16 | |
17 | - public function __construct($cid){ |
|
18 | - $contestModel = new ContestModel(); |
|
19 | - $this->cid = $cid; |
|
20 | - $this->gid = $contestModel->gid($cid); |
|
17 | + public function __construct($cid) { |
|
18 | + $contestModel=new ContestModel(); |
|
19 | + $this->cid=$cid; |
|
20 | + $this->gid=$contestModel->gid($cid); |
|
21 | 21 | // get rank |
22 | 22 | $this->getRecord(); |
23 | 23 | } |
24 | 24 | |
25 | - private function getRecord(){ |
|
26 | - $contestModel = new ContestModel(); |
|
27 | - $contestRankRaw = $contestModel->contestRank($this->cid); |
|
28 | - foreach($contestRankRaw as $key => $contestRank){ |
|
29 | - if(isset($contestRank['remote']) && $contestRank['remote']){ |
|
25 | + private function getRecord() { |
|
26 | + $contestModel=new ContestModel(); |
|
27 | + $contestRankRaw=$contestModel->contestRank($this->cid); |
|
28 | + foreach ($contestRankRaw as $key => $contestRank) { |
|
29 | + if (isset($contestRank['remote']) && $contestRank['remote']) { |
|
30 | 30 | unset($contestRankRaw[$key]); |
31 | 31 | } |
32 | 32 | } |
33 | - $contestRankRaw = array_values($contestRankRaw); |
|
34 | - $members = array_column($contestRankRaw,'uid'); |
|
35 | - $ratings_temp = DB::table('group_member') |
|
33 | + $contestRankRaw=array_values($contestRankRaw); |
|
34 | + $members=array_column($contestRankRaw, 'uid'); |
|
35 | + $ratings_temp=DB::table('group_member') |
|
36 | 36 | ->where([ |
37 | 37 | 'gid' => $this->gid, |
38 | - ])->whereIn('uid',$members) |
|
39 | - ->select('uid','ranking') |
|
38 | + ])->whereIn('uid', $members) |
|
39 | + ->select('uid', 'ranking') |
|
40 | 40 | ->get()->all(); |
41 | - $ratings = []; |
|
41 | + $ratings=[]; |
|
42 | 42 | foreach ($ratings_temp as $rating) { |
43 | - $ratings[$rating['uid']] = $rating['ranking']; |
|
43 | + $ratings[$rating['uid']]=$rating['ranking']; |
|
44 | 44 | } |
45 | - foreach($contestRankRaw as $c){ |
|
46 | - if(!isset($ratings[$c['uid']])){ |
|
45 | + foreach ($contestRankRaw as $c) { |
|
46 | + if (!isset($ratings[$c['uid']])) { |
|
47 | 47 | continue; |
48 | 48 | } |
49 | 49 | $this->contestants[]=[ |
@@ -52,87 +52,87 @@ discard block |
||
52 | 52 | "rating"=>$ratings[$c['uid']], |
53 | 53 | ]; |
54 | 54 | } |
55 | - $this->totParticipants = count($this->contestants); |
|
55 | + $this->totParticipants=count($this->contestants); |
|
56 | 56 | } |
57 | 57 | |
58 | - private function reassignRank(){ |
|
58 | + private function reassignRank() { |
|
59 | 59 | $this->sort("points"); |
60 | - $idx = 0; |
|
61 | - $points = $this->contestants[0]["points"]; |
|
62 | - $i = 1; |
|
63 | - while($i < $this->totParticipants){ |
|
64 | - if($this->contestants[$i]["points"] < $points){ |
|
65 | - $j = $idx; |
|
66 | - while($j < $i){ |
|
67 | - $this->contestants[$j]["rank"] = $i; |
|
68 | - $j += 1; |
|
60 | + $idx=0; |
|
61 | + $points=$this->contestants[0]["points"]; |
|
62 | + $i=1; |
|
63 | + while ($i<$this->totParticipants) { |
|
64 | + if ($this->contestants[$i]["points"]<$points) { |
|
65 | + $j=$idx; |
|
66 | + while ($j<$i) { |
|
67 | + $this->contestants[$j]["rank"]=$i; |
|
68 | + $j+=1; |
|
69 | 69 | } |
70 | - $idx = $i; |
|
71 | - $points = $this->contestants[$i]["points"]; |
|
70 | + $idx=$i; |
|
71 | + $points=$this->contestants[$i]["points"]; |
|
72 | 72 | } |
73 | - $i += 1; |
|
73 | + $i+=1; |
|
74 | 74 | } |
75 | - $j = $idx; |
|
76 | - while($j < $this->totParticipants){ |
|
77 | - $this->contestants[$j]["rank"] = $this->totParticipants; |
|
78 | - $j += 1; |
|
75 | + $j=$idx; |
|
76 | + while ($j<$this->totParticipants) { |
|
77 | + $this->contestants[$j]["rank"]=$this->totParticipants; |
|
78 | + $j+=1; |
|
79 | 79 | } |
80 | 80 | } |
81 | 81 | |
82 | - private function getEloWinProbability($Ra, $Rb){ |
|
83 | - return 1.0 / (1 + pow(10, ($Rb-$Ra)/400.0)); |
|
82 | + private function getEloWinProbability($Ra, $Rb) { |
|
83 | + return 1.0 / (1+pow(10, ($Rb-$Ra) / 400.0)); |
|
84 | 84 | } |
85 | 85 | |
86 | - private function getSeed($rating){ |
|
87 | - $result = 1.0; |
|
88 | - foreach($this->contestants as $other){ |
|
89 | - $result += $this->getEloWinProbability($other["rating"], $rating); |
|
86 | + private function getSeed($rating) { |
|
87 | + $result=1.0; |
|
88 | + foreach ($this->contestants as $other) { |
|
89 | + $result+=$this->getEloWinProbability($other["rating"], $rating); |
|
90 | 90 | } |
91 | 91 | return $result; |
92 | 92 | } |
93 | 93 | |
94 | - private function getRatingToRank($rank){ |
|
94 | + private function getRatingToRank($rank) { |
|
95 | 95 | $left=1; |
96 | 96 | $right=8000; |
97 | - while($right - $left > 1){ |
|
98 | - $mid = floor(($right + $left)/2); |
|
99 | - if($this->getSeed($mid) < $rank){ |
|
100 | - $right = $mid; |
|
101 | - }else{ |
|
102 | - $left = $mid; |
|
97 | + while ($right-$left>1) { |
|
98 | + $mid=floor(($right+$left) / 2); |
|
99 | + if ($this->getSeed($mid)<$rank) { |
|
100 | + $right=$mid; |
|
101 | + } else { |
|
102 | + $left=$mid; |
|
103 | 103 | } |
104 | 104 | } |
105 | 105 | return $left; |
106 | 106 | } |
107 | 107 | |
108 | - private function sort($key){ |
|
109 | - usort($this->contestants, function ($a, $b) use ($key) { |
|
108 | + private function sort($key) { |
|
109 | + usort($this->contestants, function($a, $b) use ($key) { |
|
110 | 110 | return $b[$key] <=> $a[$key]; |
111 | 111 | }); |
112 | 112 | } |
113 | 113 | |
114 | - public function calculate(){ |
|
115 | - if(empty($this->contestants)){ |
|
114 | + public function calculate() { |
|
115 | + if (empty($this->contestants)) { |
|
116 | 116 | return; |
117 | 117 | } |
118 | 118 | |
119 | 119 | // recalc rank |
120 | 120 | $this->reassignRank(); |
121 | 121 | |
122 | - foreach($this->contestants as &$member){ |
|
123 | - $member["seed"] = 1.0; |
|
124 | - foreach($this->contestants as $other){ |
|
125 | - if($member["uid"] != $other["uid"]){ |
|
126 | - $member["seed"] += $this->getEloWinProbability($other["rating"], $member["rating"]); |
|
122 | + foreach ($this->contestants as &$member) { |
|
123 | + $member["seed"]=1.0; |
|
124 | + foreach ($this->contestants as $other) { |
|
125 | + if ($member["uid"]!=$other["uid"]) { |
|
126 | + $member["seed"]+=$this->getEloWinProbability($other["rating"], $member["rating"]); |
|
127 | 127 | } |
128 | 128 | } |
129 | 129 | } |
130 | 130 | unset($member); |
131 | 131 | |
132 | - foreach($this->contestants as &$contestant){ |
|
133 | - $midRank = sqrt($contestant["rank"] * $contestant["seed"]); |
|
134 | - $contestant["needRating"] = $this->getRatingToRank($midRank); |
|
135 | - $contestant["delta"] = floor(($contestant["needRating"] - $contestant["rating"])/2); |
|
132 | + foreach ($this->contestants as &$contestant) { |
|
133 | + $midRank=sqrt($contestant["rank"] * $contestant["seed"]); |
|
134 | + $contestant["needRating"]=$this->getRatingToRank($midRank); |
|
135 | + $contestant["delta"]=floor(($contestant["needRating"]-$contestant["rating"]) / 2); |
|
136 | 136 | } |
137 | 137 | unset($contestant); |
138 | 138 | |
@@ -140,39 +140,39 @@ discard block |
||
140 | 140 | |
141 | 141 | // DO some adjuct |
142 | 142 | // Total sum should not be more than ZERO. |
143 | - $sum = 0; |
|
143 | + $sum=0; |
|
144 | 144 | |
145 | - foreach($this->contestants as $contestant){ |
|
146 | - $sum += $contestant["delta"]; |
|
145 | + foreach ($this->contestants as $contestant) { |
|
146 | + $sum+=$contestant["delta"]; |
|
147 | 147 | } |
148 | - $inc = -floor($sum / $this->totParticipants) - 1; |
|
149 | - foreach($this->contestants as &$contestant){ |
|
150 | - $contestant["delta"] += $inc; |
|
148 | + $inc=-floor($sum / $this->totParticipants)-1; |
|
149 | + foreach ($this->contestants as &$contestant) { |
|
150 | + $contestant["delta"]+=$inc; |
|
151 | 151 | } |
152 | 152 | unset($contestant); |
153 | 153 | |
154 | 154 | // Sum of top-4*sqrt should be adjusted to ZERO. |
155 | 155 | |
156 | - $sum = 0; |
|
157 | - $zeroSumCount = min(intval(4*round(sqrt($this->totParticipants))), $this->totParticipants); |
|
156 | + $sum=0; |
|
157 | + $zeroSumCount=min(intval(4 * round(sqrt($this->totParticipants))), $this->totParticipants); |
|
158 | 158 | |
159 | - for($i=0;$i<$zeroSumCount;$i++){ |
|
160 | - $sum += $this->contestants[$i]["delta"]; |
|
159 | + for ($i=0; $i<$zeroSumCount; $i++) { |
|
160 | + $sum+=$this->contestants[$i]["delta"]; |
|
161 | 161 | } |
162 | 162 | |
163 | - $inc = min(max(-floor($sum / $zeroSumCount), -10), 0); |
|
163 | + $inc=min(max(-floor($sum / $zeroSumCount), -10), 0); |
|
164 | 164 | |
165 | - for($i=0;$i<$zeroSumCount;$i++){ |
|
166 | - $this->contestants[$i]["delta"] += $inc; |
|
165 | + for ($i=0; $i<$zeroSumCount; $i++) { |
|
166 | + $this->contestants[$i]["delta"]+=$inc; |
|
167 | 167 | } |
168 | 168 | |
169 | 169 | return $this->validateDeltas(); |
170 | 170 | } |
171 | 171 | |
172 | - public function storage(){ |
|
172 | + public function storage() { |
|
173 | 173 | $contestants=$this->contestants; |
174 | - DB::transaction(function () use ($contestants) { |
|
175 | - foreach($contestants as $contestant){ |
|
174 | + DB::transaction(function() use ($contestants) { |
|
175 | + foreach ($contestants as $contestant) { |
|
176 | 176 | $newRating=$contestant["rating"]+$contestant["delta"]; |
177 | 177 | DB::table("group_member")->where([ |
178 | 178 | 'gid' => $this->gid, |
@@ -190,20 +190,20 @@ discard block |
||
190 | 190 | }, 5); |
191 | 191 | } |
192 | 192 | |
193 | - private function validateDeltas(){ |
|
193 | + private function validateDeltas() { |
|
194 | 194 | $this->sort("points"); |
195 | 195 | |
196 | - for($i=0;$i<$this->totParticipants;$i++){ |
|
197 | - for($j=$i+1;$j<$this->totParticipants;$j++){ |
|
198 | - if($this->contestants[$i]["rating"] > $this->contestants[$j]["rating"]){ |
|
199 | - if($this->contestants[$i]["rating"] + $this->contestants[$i]["delta"] < $this->contestants[$j]["rating"] + $this->contestants[$j]["delta"]){ |
|
196 | + for ($i=0; $i<$this->totParticipants; $i++) { |
|
197 | + for ($j=$i+1; $j<$this->totParticipants; $j++) { |
|
198 | + if ($this->contestants[$i]["rating"]>$this->contestants[$j]["rating"]) { |
|
199 | + if ($this->contestants[$i]["rating"]+$this->contestants[$i]["delta"]<$this->contestants[$j]["rating"]+$this->contestants[$j]["delta"]) { |
|
200 | 200 | Log::warning("First rating invariant failed: {$this->contestants[$i]["uid"]} vs. {$this->contestants[$j]["uid"]}."); |
201 | 201 | return false; |
202 | 202 | } |
203 | 203 | } |
204 | 204 | |
205 | - if($this->contestants[$i]["rating"] < $this->contestants[$j]["rating"]){ |
|
206 | - if($this->contestants[$i]["delta"] < $this->contestants[$j]["delta"]){ |
|
205 | + if ($this->contestants[$i]["rating"]<$this->contestants[$j]["rating"]) { |
|
206 | + if ($this->contestants[$i]["delta"]<$this->contestants[$j]["delta"]) { |
|
207 | 207 | Log::warning("Second rating invariant failed: {$this->contestants[$i]["uid"]} vs. {$this->contestants[$j]["uid"]}."); |
208 | 208 | return false; |
209 | 209 | } |
@@ -16,16 +16,16 @@ discard block |
||
16 | 16 | private $member_data; |
17 | 17 | private $config; |
18 | 18 | |
19 | - public function __construct($data, $config = []) |
|
19 | + public function __construct($data, $config=[]) |
|
20 | 20 | { |
21 | - if ($config['mode'] == 'contest') { |
|
22 | - $this->contest_data = $data['contest_data']; |
|
23 | - $this->member_data = $data['member_data']; |
|
21 | + if ($config['mode']=='contest') { |
|
22 | + $this->contest_data=$data['contest_data']; |
|
23 | + $this->member_data=$data['member_data']; |
|
24 | 24 | } else { |
25 | - $this->member_data = $data['member_data']; |
|
26 | - $this->tag_problems = $data['tag_problems']; |
|
25 | + $this->member_data=$data['member_data']; |
|
26 | + $this->tag_problems=$data['tag_problems']; |
|
27 | 27 | } |
28 | - $this->config = $config; |
|
28 | + $this->config=$config; |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | /** |
@@ -34,9 +34,9 @@ discard block |
||
34 | 34 | public function registerEvents(): array |
35 | 35 | { |
36 | 36 | return [ |
37 | - AfterSheet::class => function (AfterSheet $event) { |
|
38 | - if ($this->config['mode'] === 'contest') { |
|
39 | - $mergeCell = ['A1:A2','B1:E1']; |
|
37 | + AfterSheet::class => function(AfterSheet $event) { |
|
38 | + if ($this->config['mode']==='contest') { |
|
39 | + $mergeCell=['A1:A2', 'B1:E1']; |
|
40 | 40 | foreach ($this->contest_data as $c) { |
41 | 41 | array_push($mergeCell, $this->mergeCellColumnNext()); |
42 | 42 | } |
@@ -51,46 +51,46 @@ discard block |
||
51 | 51 | */ |
52 | 52 | public function collection() |
53 | 53 | { |
54 | - $maxium = $this->config['maxium'] ?? false; |
|
55 | - $percent = $this->config['percent'] ?? false; |
|
54 | + $maxium=$this->config['maxium'] ?? false; |
|
55 | + $percent=$this->config['percent'] ?? false; |
|
56 | 56 | |
57 | - if ($this->config['mode'] == 'contest') { |
|
58 | - $row_1 = ['Member','Total','','','']; |
|
59 | - $row_2 = ['','Elo','Rank','Solved','Penalty']; |
|
57 | + if ($this->config['mode']=='contest') { |
|
58 | + $row_1=['Member', 'Total', '', '', '']; |
|
59 | + $row_2=['', 'Elo', 'Rank', 'Solved', 'Penalty']; |
|
60 | 60 | foreach ($this->contest_data as $contest) { |
61 | - array_push($row_1, $contest['name'], '',''); |
|
62 | - array_push($row_2, 'Rank','Solved', 'Penalty'); |
|
61 | + array_push($row_1, $contest['name'], '', ''); |
|
62 | + array_push($row_2, 'Rank', 'Solved', 'Penalty'); |
|
63 | 63 | } |
64 | - $data = [$row_1,$row_2]; |
|
64 | + $data=[$row_1, $row_2]; |
|
65 | 65 | foreach ($this->member_data as $member) { |
66 | - $display_name = $member['name']; |
|
66 | + $display_name=$member['name']; |
|
67 | 67 | if (!empty($member['nick_name'])) { |
68 | - $display_name .= ' ('.$member['nick_name'].')'; |
|
68 | + $display_name.=' ('.$member['nick_name'].')'; |
|
69 | 69 | } |
70 | - $row = [ |
|
70 | + $row=[ |
|
71 | 71 | $display_name, |
72 | 72 | $member['elo'], |
73 | 73 | !empty($member['rank_ave']) ? round($member['rank_ave'], 1) : '-', |
74 | - $percent === 'true' ? ($member['problem_all'] != 0 ? round($member['solved_all'] / $member['problem_all'] * 100, 1) : '-'). ' %' |
|
75 | - : ($maxium === 'true' ? $member['solved_all'] . ' / ' . $member['problem_all'] : $member['solved_all']), |
|
74 | + $percent==='true' ? ($member['problem_all']!=0 ? round($member['solved_all'] / $member['problem_all'] * 100, 1) : '-').' %' |
|
75 | + : ($maxium==='true' ? $member['solved_all'].' / '.$member['problem_all'] : $member['solved_all']), |
|
76 | 76 | round($member['penalty']), |
77 | 77 | ]; |
78 | 78 | foreach ($this->contest_data as $contest) { |
79 | 79 | if (in_array($contest['cid'], array_keys($member['contest_detial']))) { |
80 | - $contest_detial = $member['contest_detial'][$contest['cid']]; |
|
80 | + $contest_detial=$member['contest_detial'][$contest['cid']]; |
|
81 | 81 | array_push( |
82 | 82 | $row, |
83 | 83 | $contest_detial['rank'], |
84 | - $percent === 'true' ? (round($contest_detial['solved'] / $contest_detial['problems'] * 100, 1) . ' %') |
|
85 | - : ($maxium === 'true' ? $contest_detial['solved'].' / '.$contest_detial['problems'] : $contest_detial['solved']), |
|
84 | + $percent==='true' ? (round($contest_detial['solved'] / $contest_detial['problems'] * 100, 1).' %') |
|
85 | + : ($maxium==='true' ? $contest_detial['solved'].' / '.$contest_detial['problems'] : $contest_detial['solved']), |
|
86 | 86 | round($contest_detial['penalty']) |
87 | 87 | ); |
88 | 88 | } else { |
89 | 89 | array_push( |
90 | 90 | $row, |
91 | 91 | '-', |
92 | - $percent === 'true' ? '- %' |
|
93 | - : ($maxium === 'true' ? '- / -' : ' - '), |
|
92 | + $percent==='true' ? '- %' |
|
93 | + : ($maxium==='true' ? '- / -' : ' - '), |
|
94 | 94 | 0 |
95 | 95 | ); |
96 | 96 | } |
@@ -98,27 +98,27 @@ discard block |
||
98 | 98 | array_push($data, $row); |
99 | 99 | } |
100 | 100 | } else { |
101 | - $row_1 = ['Member']; |
|
102 | - $row_2 = ['']; |
|
101 | + $row_1=['Member']; |
|
102 | + $row_2=['']; |
|
103 | 103 | foreach ($this->tag_problems as $tag => $tag_problem_set) { |
104 | 104 | array_push($row_1, $tag); |
105 | 105 | array_push($row_2, 'Solved'); |
106 | 106 | } |
107 | - $data = [$row_1,$row_2]; |
|
107 | + $data=[$row_1, $row_2]; |
|
108 | 108 | foreach ($this->member_data as $member) { |
109 | - $display_name = $member['name']; |
|
109 | + $display_name=$member['name']; |
|
110 | 110 | if (!empty($member['nick_name'])) { |
111 | - $display_name .= ' ('.$member['nick_name'].')'; |
|
111 | + $display_name.=' ('.$member['nick_name'].')'; |
|
112 | 112 | } |
113 | - $row = [ |
|
113 | + $row=[ |
|
114 | 114 | $display_name, |
115 | 115 | ]; |
116 | 116 | foreach ($member['completion'] as $tag => $tag_completion) { |
117 | - $count = count($tag_completion); |
|
118 | - $solved = eval('return '.join('+', array_values($tag_completion)).';'); |
|
117 | + $count=count($tag_completion); |
|
118 | + $solved=eval('return '.join('+', array_values($tag_completion)).';'); |
|
119 | 119 | array_push( |
120 | 120 | $row, |
121 | - $percent === 'true' ? (round($solved / $count * 100, 1) . ' %') : ($maxium === 'true' ? $solved .' / '.$count : $solved) |
|
121 | + $percent==='true' ? (round($solved / $count * 100, 1).' %') : ($maxium==='true' ? $solved.' / '.$count : $solved) |
|
122 | 122 | ); |
123 | 123 | } |
124 | 124 | array_push($data, $row); |
@@ -129,33 +129,33 @@ discard block |
||
129 | 129 | |
130 | 130 | private function mergeCellColumnNext() |
131 | 131 | { |
132 | - static $columns = [ |
|
133 | - [2],[4] |
|
132 | + static $columns=[ |
|
133 | + [2], [4] |
|
134 | 134 | ]; |
135 | - $columns_str = ['','']; |
|
136 | - $chars = str_split('ABCDEFGHIJKLMNOPQRSTUVWXYZ'); |
|
135 | + $columns_str=['', '']; |
|
136 | + $chars=str_split('ABCDEFGHIJKLMNOPQRSTUVWXYZ'); |
|
137 | 137 | foreach ($columns as $key => &$column) { |
138 | - $column[0] += 3; |
|
139 | - if ($column[0] > 25) { |
|
138 | + $column[0]+=3; |
|
139 | + if ($column[0]>25) { |
|
140 | 140 | if (isset($column[1])) { |
141 | - $column[1] += 1; |
|
142 | - if ($column[1] > 25) { |
|
141 | + $column[1]+=1; |
|
142 | + if ($column[1]>25) { |
|
143 | 143 | if (isset($column[2])) { |
144 | - $column[2] += 1; |
|
144 | + $column[2]+=1; |
|
145 | 145 | } else { |
146 | - $column[2] = 0; |
|
146 | + $column[2]=0; |
|
147 | 147 | } |
148 | 148 | } |
149 | 149 | } else { |
150 | - $column[1] = 0; |
|
150 | + $column[1]=0; |
|
151 | 151 | } |
152 | 152 | } |
153 | - $columns_str[$key] = ''; |
|
154 | - $reverse_column = array_reverse($column); |
|
153 | + $columns_str[$key]=''; |
|
154 | + $reverse_column=array_reverse($column); |
|
155 | 155 | foreach ($reverse_column as $ord) { |
156 | - $columns_str[$key] .= $chars[$ord]; |
|
156 | + $columns_str[$key].=$chars[$ord]; |
|
157 | 157 | } |
158 | - $columns_str[$key] .= '1'; |
|
158 | + $columns_str[$key].='1'; |
|
159 | 159 | } |
160 | 160 | return $columns_str[0].':'.$columns_str[1]; |
161 | 161 | } |