From 02329d5c21e5d86a59b0347e340ebae1540063ca Mon Sep 17 00:00:00 2001 From: Torsten Date: Tue, 7 Nov 2017 16:59:58 +0100 Subject: [PATCH] Fixed League Auf + Abstieg --- .../Controllers/Leagues/LeaguesController.php | 17 +++-- pfosten/app/leagues/League.php | 76 ++++++++++++++++--- .../resources/views/leagues/chart.blade.php | 17 ++++- 3 files changed, 93 insertions(+), 17 deletions(-) diff --git a/pfosten/app/Http/Controllers/Leagues/LeaguesController.php b/pfosten/app/Http/Controllers/Leagues/LeaguesController.php index cd7a7db0..dfca9a87 100644 --- a/pfosten/app/Http/Controllers/Leagues/LeaguesController.php +++ b/pfosten/app/Http/Controllers/Leagues/LeaguesController.php @@ -113,15 +113,22 @@ class LeaguesController extends Controller $totalRanking = League::getTotalRankingOverall(); // Nur für Auf/Abstiegsinfo benötigt. $rankInfo=array(); + + foreach($totalRanking as $index => $entry) { $userId=$entry[0]; - $rank=3; - if ($index<44) { $rank=2; } - if ($index<22) { $rank=1; } - $rankInfo[$userId]=$rank; + $rankInfo[$userId]=$totalRanking[$index][4]; } - return view ('leagues.chart',compact('season','leagues', 'leagueNames', 'userNames','leagueScores','rankInfo')); + $cols=array(); + $cols[1]="greenyellow"; + $cols[2]="orange"; + $cols[3]="lightgrey"; + $cols[4]=""; + + + + return view ('leagues.chart',compact('season','leagues', 'leagueNames', 'userNames','leagueScores','rankInfo','rank','cols')); } public static function showSingleUserMatches($userId) { diff --git a/pfosten/app/leagues/League.php b/pfosten/app/leagues/League.php index 541eff8c..1023bd3f 100644 --- a/pfosten/app/leagues/League.php +++ b/pfosten/app/leagues/League.php @@ -73,7 +73,6 @@ class League extends Model $rank1 = -1; if (array_key_exists(4, $score1 )) { $rank1 = $score1[4]; } - $_score2 = $score2[1]; $goals2 = $score2[2]; $cGoals2 = $score2[3]; @@ -83,8 +82,8 @@ class League extends Model $diff1 = $goals1-$cGoals1; $diff2 = $goals2-$cGoals2; - if ($rank1 < $rank2) return true; - if ($rank2 < $rank1) return false; + if ($rank1 > $rank2) return true; + if ($rank1 < $rank2) return false; if ($_score1 == $_score2) { if ($diff1==$diff2) { @@ -99,6 +98,46 @@ class League extends Model return ($_score1 < $_score2); } + // Funktioniert nur auf bereits sortierter Liste, nur für Selektion Gruppe 3 Auf & Abstieg + public static function cmpScoreForPos($score1, $score2) { + // [0] = user-id + // [4] = rank + $_score1 = $score1[1]; + $goals1 = $score1[2]; + $cGoals1 = $score1[3]; + $rank1 = $score1[4]; + $pos1 = $score1[5]; + + $_score2 = $score2[1]; + $goals2 = $score2[2]; + $cGoals2 = $score2[3]; + $rank2 = $score2[4]; + $pos2 = $score2[5]; + + $diff1 = $goals1-$cGoals1; + $diff2 = $goals2-$cGoals2; + + if ($rank1 > $rank2) return true; + if ($rank1 < $rank2) return false; + + if ($pos1 > $pos2) return true; + if ($pos1 < $pos2) return false; + + if ($_score1 == $_score2) { + if ($diff1==$diff2) { + if ($goals1 == $goals2) { + return $cGoals1 > $cGoals2; + } + return ( $goals1 < $goals2 ); + } + return ($diff1<$diff2); + } + + return ($_score1 < $_score2); + } + + + public static function getRanking($rank, $seasonId=-1) { $season = Season::getCurrent(); @@ -148,38 +187,53 @@ class League extends Model foreach($leagueScores as $leagueId => $singleLeagueScores) { foreach ($singleLeagueScores as $placeNr => $singleLeagueScore) { $userId=$singleLeagueScores[$placeNr][0]; - $unifiedScores[$userId]=$singleLeagueScores[$placeNr]; + $scoreWithPos=$singleLeagueScores[$placeNr]; + $scoreWithPos[4]=$placeNr+1; + $unifiedScores[$userId]=$scoreWithPos; } } usort($unifiedScores,array('App\Leagues\League','cmpScore')); return $unifiedScores; } - // Nur für Auf und Abstieg + // Nur für Auf und Abstiegsberechnung. + // Schreibt den zukünftigen Rank auf Index4 public static function getTotalRankingOverall($seasonId=-1) { $totalRanking=array(); $hasRank4 = false; foreach([1,2,3,4] as $rank) { foreach (League::getUnifiedRanking($rank, $seasonId) as $rankEntry) { - // Tuple: [0] = userId, [1] = league_score [2] = goals, [3] = counter_goals + // Tuple: [0] = userId, [1] = league_score [2] = goals, [3] = counter_goals [4] = LigaPos $tpl = array(); - $tpl[0] = $rankEntry[0]; - $tpl[1] = $rankEntry[1]; - $tpl[2] = $rankEntry[2]; - $tpl[3] = $rankEntry[3]; - $tpl[4] = $rank; + $tpl[0] = $rankEntry[0]; // userId + $tpl[1] = $rankEntry[1]; // league_score + $tpl[2] = $rankEntry[2]; // goals + $tpl[3] = $rankEntry[3]; // countergoals + $tpl[4] = $rank; // league_rank (1,2,3, 4=quali) + $tpl[5] = $rankEntry[4]; // league_pos (for multiple leagues per rank, usually ranks 3 and 4) + if ($rank==4) { $hasRank4=true;} array_push($totalRanking, $tpl); } } usort($totalRanking, array('App\Leagues\League','cmpScore')); + usort($totalRanking, array('App\Leagues\League','cmpScoreForPos')); // Dieser Sort funktioniert nur auf bereits sortierter Liste !! Nur für GruppenRank=3 + + // Neuen Rang auf Index 4 schreiben + foreach ($totalRanking as $index => $entry) { + $rank=3; + if ($index<44) { $rank=2; } + if ($index<22) { $rank=1; } + $totalRanking[$index][4]=$rank; + } // kein Rank4 ==> Ligaspiel ==> Auf & Abstieg wird angewendet. if (!$hasRank4) { // Liga 1/2: Swap rank 17-22 <> 23-28 ==> index 16-21 to rank=2, index 22-27 to rank=1 // Liga 2/3: Swap rank 39-44 <> 45-50 ==> index 38-43 to rank=3, index 44-49 to rank=2 + $totalRanking[16][4]=2; $totalRanking[17][4]=2; $totalRanking[18][4]=2; diff --git a/pfosten/resources/views/leagues/chart.blade.php b/pfosten/resources/views/leagues/chart.blade.php index bf9e5f20..8f2a67df 100755 --- a/pfosten/resources/views/leagues/chart.blade.php +++ b/pfosten/resources/views/leagues/chart.blade.php @@ -6,6 +6,21 @@

{{ $season->name }}

+ + + + + + + + + + + + + +
= Qualifikationsplatz Liga 1
= Qualifikationsplatz Liga 2
= Qualifikationsplatz Liga 3
+ @foreach($leagueScores as $leagueId => $playerTuples)

{{ $leagueNames[$leagueId] }}

@@ -22,7 +37,7 @@ @foreach($playerTuples as $pos => $player) -   {{$pos+1}}  +   {{$pos+1}}    {{$userNames[$player[0]]}}     {{$player[1]}}     {{$player[2]-$player[3]}}