Working on Case2: New League Creation after Qualification
This commit is contained in:
parent
d8a7f78cbd
commit
66671b1e81
11 changed files with 12726 additions and 40 deletions
|
|
@ -32,15 +32,20 @@ class Match extends Model
|
|||
$leagues = League::where('season_id', '=', $currentSeason->id)->get();
|
||||
foreach ($leagues as $league) {
|
||||
|
||||
Log::info("Creating matchups for league_id=".$league->id);
|
||||
// Wenn es keine previous League gibt, dann ist $league->rank immer RANK_QUALIFICATION,
|
||||
// ansonsten ist es einer von RANK_LEAGUE1, RANK_LEAGUE2, RANK_LEAGUE3
|
||||
|
||||
Log::info("rank_id of league_id ".$league->id." = ".$league->rank);
|
||||
|
||||
if ($league->rank <= League::RANK_QUALIFICATION) {
|
||||
|
||||
$rounds = Round::where('id','>=',$league->start_round_id)->get();
|
||||
$roundNr=1;
|
||||
$neededRoundCount = Match::getNumberOfNeededRounds($league->id);
|
||||
|
||||
$allPairings=Match::getAllPairings($league->id, sizeof($rounds));
|
||||
Log::info("Match::createMatchups( league_id=".$league->id.", numberOfrounds=".sizeof($rounds));
|
||||
$allPairings=Match::getAllPairings($league->id);
|
||||
|
||||
foreach ($rounds as $round) {
|
||||
$pairings = $allPairings[$roundNr];
|
||||
|
|
@ -54,12 +59,13 @@ class Match extends Model
|
|||
'user2_id' => $pair[1]
|
||||
]);
|
||||
$newMatch->save();
|
||||
}
|
||||
//Log::info("Saving match: league_id=".$league->id.", round_id=".$round->id.", ".$pair[0]." vs ".$pair[2]);
|
||||
}
|
||||
$roundNr += 1;
|
||||
if ($roundNr > $neededRoundCount) break;
|
||||
}
|
||||
|
||||
}
|
||||
} else {Log::info("Skipped match creation because of unfitting rank=".$league->rank);}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -114,16 +120,22 @@ class Match extends Model
|
|||
|
||||
|
||||
// Hier findet RoundRobin statt.
|
||||
public static function getAllPairings($leagueId, $roundCount) {
|
||||
public static function getAllPairings($leagueId) {
|
||||
$members = LeagueMember::getMembers($leagueId);
|
||||
|
||||
$roundCount=sizeof($members)-1;
|
||||
|
||||
if (sizeof($members) % 2 == 1) { // ungerade memberzahl => freilos einfügen
|
||||
error_log("Adding -1 free entry");
|
||||
array_push($members,-1);
|
||||
}
|
||||
|
||||
shuffle($members);
|
||||
//error_log("Number of members:".sizeof($members));
|
||||
error_log("Number of members:".sizeof($members));
|
||||
$pairingCount = Match::getNumberOfPairingsPerRound($leagueId);
|
||||
|
||||
error_log("pairingCount=".$pairingCount);
|
||||
|
||||
$all = array();
|
||||
|
||||
for ($currentRoundNr=1; $currentRoundNr<= $roundCount; $currentRoundNr++) {
|
||||
|
|
@ -133,8 +145,8 @@ class Match extends Model
|
|||
array_push($roundRobin, $userId);
|
||||
}
|
||||
|
||||
//error_log("RoundNr ".$currentRoundNr." Array start:");
|
||||
//error_log(implode(",",$roundRobin));
|
||||
error_log("RoundNr ".$currentRoundNr." Array start:");
|
||||
error_log(implode(",",$roundRobin));
|
||||
|
||||
$_roundNr = $currentRoundNr;
|
||||
while ($_roundNr >= 1) {
|
||||
|
|
@ -165,8 +177,11 @@ class Match extends Model
|
|||
// Matches die nur einen Teilnehmer haben entfernen. Passiert bei ungerader Teilnehmerzahl.
|
||||
// Der nicht im Pairing befindliche Spieler hat einen spielfreien Tag.
|
||||
|
||||
//error_log(" Cleaning up Round pairings");
|
||||
$pairings_clean=array();
|
||||
//error_log(":".$pairings[0]);
|
||||
foreach($pairings as $idx => $pairing) {
|
||||
|
||||
if ($pairing[0] == -1 || $pairing[1] == -1) {
|
||||
//error_log("DONT ADD");
|
||||
} else {
|
||||
|
|
@ -209,10 +224,13 @@ class Match extends Model
|
|||
}
|
||||
|
||||
public static function getMatchResults($leagueId, $maxRoundId=-1) {
|
||||
$roundtipps = Tipp::getRoundTipps($maxRoundId);
|
||||
|
||||
$league=League::where('id','=',$leagueId)->first();
|
||||
$season=Season::where('id','=',$league->season_id)->first();
|
||||
|
||||
$roundtipps = Tipp::getRoundTipps($maxRoundId, $season->id);
|
||||
$roundtipps = $roundtipps["roundtipps"];
|
||||
$matches = Match::getLeagueMatches($leagueId, $maxRoundId);
|
||||
$season = Season::getCurrent();
|
||||
|
||||
if ($maxRoundId==-1) { $maxRoundId = Round::getLastRoundId($season->id); }
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue