| @@ -18,16 +18,16 @@ | ||
| 18 | 18 | public function handle($request, Closure $next) | 
| 19 | 19 |      { | 
| 20 | 20 |          if (Auth::check()) { | 
| 21 | -            if(isset($request->gcode)){ | |
| 21 | +            if (isset($request->gcode)) { | |
| 22 | 22 | //group privilege | 
| 23 | 23 | $groupModel=new GroupModel(); | 
| 24 | -                if($groupModel->judgeClearance($groupModel->gid($request->gcode), Auth::user()->id)>=2){ | |
| 24 | +                if ($groupModel->judgeClearance($groupModel->gid($request->gcode), Auth::user()->id)>=2) { | |
| 25 | 25 | return $next($request); | 
| 26 | 26 | } | 
| 27 | -            }elseif(isset($request->cid)) { | |
| 27 | +            }elseif (isset($request->cid)) { | |
| 28 | 28 | //contest privilege | 
| 29 | 29 | $contestModel=new ContestModel(); | 
| 30 | -                if($contestModel->judgeClearance($request->cid, Auth::user()->id)==3){ | |
| 30 | +                if ($contestModel->judgeClearance($request->cid, Auth::user()->id)==3) { | |
| 31 | 31 | return $next($request); | 
| 32 | 32 | } | 
| 33 | 33 | } | 
| @@ -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,28 +65,28 @@ 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($num) | 
| 79 | 79 |      { | 
| 80 | 80 |          $rankList=Cache::tags(['rank'])->get('general'); | 
| 81 | - if($rankList==null) $rankList=[]; | |
| 82 | - $rankList=array_slice($rankList,0,$num); | |
| 83 | -        $userInfoRaw=DB::table("users")->select("id as uid","avatar","name")->get()->all(); | |
| 81 | + if ($rankList==null) $rankList=[]; | |
| 82 | + $rankList=array_slice($rankList, 0, $num); | |
| 83 | +        $userInfoRaw=DB::table("users")->select("id as uid", "avatar", "name")->get()->all(); | |
| 84 | 84 | $userInfo=[]; | 
| 85 | -        foreach($userInfoRaw as $u){ | |
| 85 | +        foreach ($userInfoRaw as $u) { | |
| 86 | 86 | $userInfo[$u["uid"]]=$u; | 
| 87 | 87 | } | 
| 88 | -        foreach($rankList as &$r){ | |
| 89 | - $r["details"]=isset($userInfo[$r["uid"]])?$userInfo[$r["uid"]]:[]; | |
| 88 | +        foreach ($rankList as &$r) { | |
| 89 | + $r["details"]=isset($userInfo[$r["uid"]]) ? $userInfo[$r["uid"]] : []; | |
| 90 | 90 | } | 
| 91 | 91 | // var_dump($rankList); exit(); | 
| 92 | 92 | return $rankList; | 
| @@ -109,8 +109,8 @@ discard block | ||
| 109 | 109 | $rankSolved=$rankItem["totValue"]; | 
| 110 | 110 | } | 
| 111 | 111 | $rankTitle=$this->getRankTitle($rankValue); | 
| 112 | -                Cache::tags(['rank',$rankItem["uid"]])->put("rank", $rankValue, 86400); | |
| 113 | -                Cache::tags(['rank',$rankItem["uid"]])->put("title", $rankTitle, 86400); | |
| 112 | +                Cache::tags(['rank', $rankItem["uid"]])->put("rank", $rankValue, 86400); | |
| 113 | +                Cache::tags(['rank', $rankItem["uid"]])->put("title", $rankTitle, 86400); | |
| 114 | 114 | $rankListCached[]=[ | 
| 115 | 115 | "uid"=>$rankItem["uid"], | 
| 116 | 116 | "rank"=>$rankValue, | 
| @@ -127,14 +127,14 @@ discard block | ||
| 127 | 127 | |
| 128 | 128 | public function getProfessionalRanking() | 
| 129 | 129 |      { | 
| 130 | - $professionalRankList = []; | |
| 131 | -        $verifiedUsers = DB::table("users")->select("professional_rate","id as uid","avatar","name")->get()->all(); | |
| 132 | - $rankIter = 0; | |
| 133 | -        foreach($verifiedUsers as $user) { | |
| 134 | - $rankVal = $user['professional_rate']; | |
| 135 | - $rankTitle = self::getProfessionalTitle($rankVal); | |
| 136 | - $titleColor = self::getProfessionalColor($rankTitle); | |
| 137 | - $professionalRankList[$rankIter++] = [ | |
| 130 | + $professionalRankList=[]; | |
| 131 | +        $verifiedUsers=DB::table("users")->select("professional_rate", "id as uid", "avatar", "name")->get()->all(); | |
| 132 | + $rankIter=0; | |
| 133 | +        foreach ($verifiedUsers as $user) { | |
| 134 | + $rankVal=$user['professional_rate']; | |
| 135 | + $rankTitle=self::getProfessionalTitle($rankVal); | |
| 136 | + $titleColor=self::getProfessionalColor($rankTitle); | |
| 137 | + $professionalRankList[$rankIter++]=[ | |
| 138 | 138 | "name"=>$user["name"], | 
| 139 | 139 | "uid"=>$user["uid"], | 
| 140 | 140 | "avatar"=>$user["avatar"], | 
| @@ -156,7 +156,7 @@ discard block | ||
| 156 | 156 | $tot+=$c; | 
| 157 | 157 | } | 
| 158 | 158 |              foreach ($this->casualRankingPer as &$c) { | 
| 159 | - $c=round($c*$totUsers/$tot); | |
| 159 | + $c=round($c * $totUsers / $tot); | |
| 160 | 160 | $cur+=$c; | 
| 161 | 161 | $c=$cur; | 
| 162 | 162 | } | 
| @@ -167,16 +167,16 @@ discard block | ||
| 167 | 167 | |
| 168 | 168 | public function getRankTitle($rankVal) | 
| 169 | 169 |      { | 
| 170 | -        foreach($this->casualRankingPer as $title=>$c){ | |
| 171 | - if($rankVal<=$c) return $title; | |
| 170 | +        foreach ($this->casualRankingPer as $title=>$c) { | |
| 171 | + if ($rankVal<=$c) return $title; | |
| 172 | 172 | } | 
| 173 | 173 | return Arr::last($this->casualRankingPer); | 
| 174 | 174 | } | 
| 175 | 175 | |
| 176 | 176 | public static function getProfessionalTitle($rankVal) | 
| 177 | 177 |      { | 
| 178 | -        foreach(self::$professionalRankingPer as $title=>$point) { | |
| 179 | - if($rankVal >= $point) return $title; | |
| 178 | +        foreach (self::$professionalRankingPer as $title=>$point) { | |
| 179 | + if ($rankVal>=$point) return $title; | |
| 180 | 180 | } | 
| 181 | 181 | return Arr::last(self::$professionalRankingPer); | 
| 182 | 182 | } | 
| @@ -14,14 +14,14 @@ discard block | ||
| 14 | 14 | * | 
| 15 | 15 | * @var string | 
| 16 | 16 | */ | 
| 17 | -    protected $signature = 'babel:sync {extension : The package name of the extension} {--vcid= : The target contest of the Crawler} {--gid=1 : The holding group}'; | |
| 17 | +    protected $signature='babel:sync {extension : The package name of the extension} {--vcid= : The target contest of the Crawler} {--gid=1 : The holding group}'; | |
| 18 | 18 | |
| 19 | 19 | /** | 
| 20 | 20 | * The console command description. | 
| 21 | 21 | * | 
| 22 | 22 | * @var string | 
| 23 | 23 | */ | 
| 24 | - protected $description = 'Crawl contests for a given Babel Extension to NOJ'; | |
| 24 | + protected $description='Crawl contests for a given Babel Extension to NOJ'; | |
| 25 | 25 | |
| 26 | 26 | /** | 
| 27 | 27 | * Create a new command instance. | 
| @@ -40,16 +40,16 @@ discard block | ||
| 40 | 40 | */ | 
| 41 | 41 | public function handle() | 
| 42 | 42 |      { | 
| 43 | -        $extension = $this->argument('extension'); | |
| 44 | -        $vcid = $this->option('vcid'); | |
| 45 | -        $gid = $this->option('gid'); | |
| 46 | - $className = "App\\Babel\\Extension\\$extension\\Synchronizer"; | |
| 47 | - $all_data = [ | |
| 43 | +        $extension=$this->argument('extension'); | |
| 44 | +        $vcid=$this->option('vcid'); | |
| 45 | +        $gid=$this->option('gid'); | |
| 46 | + $className="App\\Babel\\Extension\\$extension\\Synchronizer"; | |
| 47 | + $all_data=[ | |
| 48 | 48 | 'oj'=>$extension, | 
| 49 | 49 | 'vcid'=>$vcid, | 
| 50 | 50 | 'gid'=>$gid, | 
| 51 | 51 | ]; | 
| 52 | - $Sync = new $className($all_data); | |
| 52 | + $Sync=new $className($all_data); | |
| 53 | 53 | $Sync->crawlContest(); | 
| 54 | 54 | } | 
| 55 | 55 | } | 
| @@ -14,14 +14,14 @@ discard block | ||
| 14 | 14 | * | 
| 15 | 15 | * @var string | 
| 16 | 16 | */ | 
| 17 | -    protected $signature = 'babel:rerank {extension : The package name of the extension} {--vcid= : The target contest of the Crawler} {--gid=1 : The holding group} {--cid= : The NOJ contest}'; | |
| 17 | +    protected $signature='babel:rerank {extension : The package name of the extension} {--vcid= : The target contest of the Crawler} {--gid=1 : The holding group} {--cid= : The NOJ contest}'; | |
| 18 | 18 | |
| 19 | 19 | /** | 
| 20 | 20 | * The console command description. | 
| 21 | 21 | * | 
| 22 | 22 | * @var string | 
| 23 | 23 | */ | 
| 24 | - protected $description = 'Refresh Rank from a remote contest'; | |
| 24 | + protected $description='Refresh Rank from a remote contest'; | |
| 25 | 25 | |
| 26 | 26 | /** | 
| 27 | 27 | * Create a new command instance. | 
| @@ -40,18 +40,18 @@ discard block | ||
| 40 | 40 | */ | 
| 41 | 41 | public function handle() | 
| 42 | 42 |      { | 
| 43 | -        $extension = $this->argument('extension'); | |
| 44 | -        $vcid = $this->option('vcid'); | |
| 45 | -        $gid = $this->option('gid'); | |
| 46 | -        $cid = $this->option('cid'); | |
| 47 | - $className = "App\\Babel\\Extension\\$extension\\Synchronizer"; | |
| 48 | - $all_data = [ | |
| 43 | +        $extension=$this->argument('extension'); | |
| 44 | +        $vcid=$this->option('vcid'); | |
| 45 | +        $gid=$this->option('gid'); | |
| 46 | +        $cid=$this->option('cid'); | |
| 47 | + $className="App\\Babel\\Extension\\$extension\\Synchronizer"; | |
| 48 | + $all_data=[ | |
| 49 | 49 | 'oj'=>$extension, | 
| 50 | 50 | 'vcid'=>$vcid, | 
| 51 | 51 | 'gid'=>$gid, | 
| 52 | 52 | 'cid'=>$cid, | 
| 53 | 53 | ]; | 
| 54 | - $Sync = new $className($all_data); | |
| 54 | + $Sync=new $className($all_data); | |
| 55 | 55 | $Sync->crawlRank(); | 
| 56 | 56 | } | 
| 57 | 57 | } | 
| @@ -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 | } | 
| @@ -23,34 +23,34 @@ | ||
| 23 | 23 |          if (!$request->has('search_key')) { | 
| 24 | 24 | return ResponseModel::err(1003); | 
| 25 | 25 | } | 
| 26 | -        $key  = $request->input('search_key'); | |
| 27 | - $all_result = []; | |
| 28 | - $search_from = [ | |
| 26 | +        $key=$request->input('search_key'); | |
| 27 | + $all_result=[]; | |
| 28 | + $search_from=[ | |
| 29 | 29 | 'users' => \App\Models\Search\UserSearchModel::class, | 
| 30 | 30 | 'problems' => \App\Models\Search\ProblemSearchModel::class, | 
| 31 | 31 | 'contests' => \App\Models\Search\ContestSearchModel::class, | 
| 32 | 32 | 'groups' => \App\Models\Search\GroupSearchModel::class, | 
| 33 | 33 | ]; | 
| 34 | 34 |          foreach ($search_from as $name => $model_class) { | 
| 35 | -            if(class_exists($model_class)){ | |
| 36 | - $model = new $model_class(); | |
| 37 | -                if(!method_exists($model,'search')){ | |
| 38 | - $all_result[$name] = [ | |
| 35 | +            if (class_exists($model_class)) { | |
| 36 | + $model=new $model_class(); | |
| 37 | +                if (!method_exists($model, 'search')) { | |
| 38 | + $all_result[$name]=[ | |
| 39 | 39 | 'code' => -1, | 
| 40 | 40 | 'msg' => 'cannot find search method in '.$model_class | 
| 41 | 41 | ]; | 
| 42 | 42 | continue; | 
| 43 | 43 | } | 
| 44 | - $result = $model->search($key); | |
| 45 | - $all_result[$name] = $result; | |
| 46 | -            }else{ | |
| 47 | - $all_result[$name] = [ | |
| 44 | + $result=$model->search($key); | |
| 45 | + $all_result[$name]=$result; | |
| 46 | +            } else { | |
| 47 | + $all_result[$name]=[ | |
| 48 | 48 | 'code' => -1, | 
| 49 | 49 | 'msg' => 'cannot find class named '.$model_class | 
| 50 | - ];; | |
| 50 | + ]; ; | |
| 51 | 51 | continue; | 
| 52 | 52 | } | 
| 53 | 53 | } | 
| 54 | - return ResponseModel::success(200,'Successful',$all_result); | |
| 54 | + return ResponseModel::success(200, 'Successful', $all_result); | |
| 55 | 55 | } | 
| 56 | 56 | } | 
| @@ -12,19 +12,19 @@ | ||
| 12 | 12 | |
| 13 | 13 | public function search($key) | 
| 14 | 14 |      { | 
| 15 | - $result = []; | |
| 15 | + $result=[]; | |
| 16 | 16 | //group name or gcode find | 
| 17 | -        if(strlen($key) >= 2){ | |
| 18 | -            $ret = self::where(function($query) use ($key){ | |
| 19 | -                $query->whereRaw('MATCH(`name`) AGAINST (? IN BOOLEAN MODE)',[$key]) | |
| 17 | +        if (strlen($key)>=2) { | |
| 18 | +            $ret=self::where(function($query) use ($key){ | |
| 19 | +                $query->whereRaw('MATCH(`name`) AGAINST (? IN BOOLEAN MODE)', [$key]) | |
| 20 | 20 |                      ->orWhere('gcode', $key); | 
| 21 | 21 | }) | 
| 22 | -                ->where('public',1) | |
| 23 | -                ->select('gid','gcode', 'img', 'name', 'description') | |
| 22 | +                ->where('public', 1) | |
| 23 | +                ->select('gid', 'gcode', 'img', 'name', 'description') | |
| 24 | 24 | ->limit(120) | 
| 25 | 25 | ->get()->all(); | 
| 26 | -            if(!empty($ret)){ | |
| 27 | - $result += $ret; | |
| 26 | +            if (!empty($ret)) { | |
| 27 | + $result+=$ret; | |
| 28 | 28 | } | 
| 29 | 29 | } | 
| 30 | 30 | |
| @@ -15,26 +15,26 @@ | ||
| 15 | 15 | |
| 16 | 16 | public function search($key) | 
| 17 | 17 |      { | 
| 18 | - $result = []; | |
| 18 | + $result=[]; | |
| 19 | 19 | //contest name find | 
| 20 | -        if(strlen($key) >= 2){ | |
| 21 | -            $ret = self::whereRaw('MATCH(`name`) AGAINST (? IN BOOLEAN MODE)',[$key]) | |
| 20 | +        if (strlen($key)>=2) { | |
| 21 | +            $ret=self::whereRaw('MATCH(`name`) AGAINST (? IN BOOLEAN MODE)', [$key]) | |
| 22 | 22 |                  ->select('cid', 'gid', 'name', 'rule', 'public', 'verified', 'practice', 'rated', 'anticheated', 'begin_time', 'end_time') | 
| 23 | -                ->orderBy('end_time','DESC') | |
| 23 | +                ->orderBy('end_time', 'DESC') | |
| 24 | 24 | ->limit(120) | 
| 25 | 25 | ->get()->all(); | 
| 26 | - $user_id = Auth::user()->id; | |
| 27 | - $contestModel = new ContestModel(); | |
| 28 | -            foreach($ret as $c_index => $c){ | |
| 29 | -                if(!$contestModel->judgeClearance($c['cid'],$user_id)){ | |
| 26 | + $user_id=Auth::user()->id; | |
| 27 | + $contestModel=new ContestModel(); | |
| 28 | +            foreach ($ret as $c_index => $c) { | |
| 29 | +                if (!$contestModel->judgeClearance($c['cid'], $user_id)) { | |
| 30 | 30 | unset($ret[$c_index]); | 
| 31 | 31 | } | 
| 32 | 32 | } | 
| 33 | -            if(!empty($ret)){ | |
| 34 | - $result += $ret; | |
| 33 | +            if (!empty($ret)) { | |
| 34 | + $result+=$ret; | |
| 35 | 35 | } | 
| 36 | 36 | } | 
| 37 | -        if(!empty($result)) { | |
| 37 | +        if (!empty($result)) { | |
| 38 | 38 |              foreach ($result as &$contest) { | 
| 39 | 39 | $contest["rule_parsed"]=$this->rule[$contest["rule"]]; | 
| 40 | 40 | $contest["date_parsed"]=[ | 
| @@ -10,16 +10,16 @@ | ||
| 10 | 10 | |
| 11 | 11 | public function search($key) | 
| 12 | 12 |      { | 
| 13 | - $result = []; | |
| 14 | -        if(strlen($key) >= 2){ | |
| 15 | -            $ret = self::where('email',$key) | |
| 16 | -                ->orWhereRaw('MATCH(`name`) AGAINST (? IN BOOLEAN MODE)',[$key]) | |
| 17 | -                ->select('id','avatar', 'name',  'describes', 'professional_rate') | |
| 18 | -                ->orderBy('professional_rate','DESC') | |
| 13 | + $result=[]; | |
| 14 | +        if (strlen($key)>=2) { | |
| 15 | +            $ret=self::where('email', $key) | |
| 16 | +                ->orWhereRaw('MATCH(`name`) AGAINST (? IN BOOLEAN MODE)', [$key]) | |
| 17 | +                ->select('id', 'avatar', 'name', 'describes', 'professional_rate') | |
| 18 | +                ->orderBy('professional_rate', 'DESC') | |
| 19 | 19 | ->limit(120) | 
| 20 | 20 | ->get()->all(); | 
| 21 | -            if(!empty($ret)){ | |
| 22 | - $result += $ret; | |
| 21 | +            if (!empty($ret)) { | |
| 22 | + $result+=$ret; | |
| 23 | 23 | } | 
| 24 | 24 | } | 
| 25 | 25 | return $result; |