Fixed League Auf + Abstieg
This commit is contained in:
parent
3f5db4d78c
commit
02329d5c21
3 changed files with 93 additions and 17 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -6,6 +6,21 @@
|
|||
|
||||
<h2>{{ $season->name }}</h2>
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<td style="width:50px;background-color:{{$cols[1]}}"></td>
|
||||
<td style="width:250px;"> = Qualifikationsplatz Liga 1</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="width:50px;background-color:{{$cols[2]}}"></td>
|
||||
<td style="width:250px;"> = Qualifikationsplatz Liga 2</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="width:50px;background-color:{{$cols[3]}}"></td>
|
||||
<td style="width:250px;"> = Qualifikationsplatz Liga 3</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
@foreach($leagueScores as $leagueId => $playerTuples)
|
||||
<h2>{{ $leagueNames[$leagueId] }}</h2>
|
||||
|
||||
|
|
@ -22,7 +37,7 @@
|
|||
<!-- Start Matchgruppen-Loop-->
|
||||
@foreach($playerTuples as $pos => $player)
|
||||
<tr class="table-bordered">
|
||||
<td> {{$pos+1}} </td>
|
||||
<td style="width:50px;background-color:{{ $cols[$rankInfo[$player[0]]] }}"> {{$pos+1}} </td>
|
||||
<td> <a name="playerid_{{$player[0]}}" class="{{ $player[0]==Auth::user()->id ? 'blink_text' : '' }}" href="/league/showSingleUserMatches/user_id={{$player[0]}}"> {{$userNames[$player[0]]}} </a> </td>
|
||||
<td> {{$player[1]}} </td>
|
||||
<td> {{$player[2]-$player[3]}} </td>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue