Fixing creation of new player league
This commit is contained in:
parent
9126d54dfb
commit
d6a51ea2c6
16 changed files with 154 additions and 507 deletions
|
|
@ -32,7 +32,7 @@ class Match extends Model
|
|||
$leagues = League::where('season_id', '=', $currentSeason->id)->get();
|
||||
foreach ($leagues as $league) {
|
||||
error_log("Match::createMatchups league_id=".$league->id);
|
||||
Log::info("Creating matchups for league_id=".$league->id);
|
||||
Log::info("Match::createMatchups: 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
|
||||
|
||||
|
|
@ -50,7 +50,7 @@ class Match extends Model
|
|||
Log::info("Match::createMatchups( league_id=".$league->id.", numberOfrounds=".sizeof($rounds));
|
||||
$allPairings=Match::getAllPairings($league->id);
|
||||
|
||||
Log::info("Rounds:");
|
||||
Log::info("Match::createMatchups: Rounds:");
|
||||
$counter=1;
|
||||
foreach($rounds as $round) {
|
||||
Log::info($counter);
|
||||
|
|
@ -58,13 +58,13 @@ class Match extends Model
|
|||
$counter+=1;
|
||||
}
|
||||
|
||||
Log::info("League-id=".$league->id.", Size of allPairings:".sizeof($allPairings));
|
||||
Log::info("Match::createMatchups: League-id=".$league->id.", Size of allPairings:".sizeof($allPairings));
|
||||
foreach ($rounds as $round) {
|
||||
Log::info("Fetching roundNr/index=".$roundNr);
|
||||
Log::info("Match::createMatchups: Fetching roundNr/index=".$roundNr);
|
||||
$pairings = $allPairings[$roundNr];
|
||||
// Save pairings
|
||||
foreach($pairings as $pair) {
|
||||
Log::info("Saving match. " . $pair[0] . " vs " . $pair[1] . " roundid=" . $round->id);
|
||||
Log::info("Match::createMatchups: Saving match. " . $pair[0] . " vs " . $pair[1] . " roundid=" . $round->id);
|
||||
$newMatch = Match::create([
|
||||
'league_id' => $league->id,
|
||||
'round_id' => $round->id,
|
||||
|
|
@ -78,7 +78,7 @@ class Match extends Model
|
|||
if ($roundNr > $neededRoundCount) break;
|
||||
}
|
||||
|
||||
} else {Log::info("Skipped match creation because of unfitting rank=".$league->rank);}
|
||||
} else {Log::info("Match::createMatchups: Skipped match creation because of unfitting rank=".$league->rank);}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -134,21 +134,24 @@ class Match extends Model
|
|||
|
||||
// Hier findet RoundRobin statt.
|
||||
public static function getAllPairings($leagueId) {
|
||||
Log::info("GetAllPairings for LeagueId=".$leagueId);
|
||||
$members = LeagueMember::getMembers($leagueId);
|
||||
|
||||
$roundCount=Match::getNumberOfNeededRounds($leagueId);
|
||||
|
||||
if (sizeof($members) % 2 == 1) { // ungerade memberzahl => freilos einfügen
|
||||
error_log("Adding -1 free entry");
|
||||
Log::info("Adding -1 free entry");
|
||||
array_push($members,-1);
|
||||
}
|
||||
|
||||
shuffle($members);
|
||||
error_log("Number of members:".sizeof($members));
|
||||
Log::info("Number of members.".sizeof($members));
|
||||
$pairingCount = Match::getNumberOfPairingsPerRound($leagueId);
|
||||
|
||||
error_log("pairingCount=".$pairingCount);
|
||||
|
||||
Log::info("pairingCount=".$pairingCount);
|
||||
$all = array();
|
||||
|
||||
for ($currentRoundNr=1; $currentRoundNr<= $roundCount; $currentRoundNr++) {
|
||||
|
|
@ -160,6 +163,10 @@ class Match extends Model
|
|||
|
||||
//error_log("RoundNr ".$currentRoundNr." Array start:");
|
||||
//error_log(implode(",",$roundRobin));
|
||||
Log::info("RoundNr ".$currentRoundNr." Array start:");
|
||||
Log::info(implode(",",$roundRobin));
|
||||
|
||||
|
||||
|
||||
$_roundNr = $currentRoundNr;
|
||||
while ($_roundNr >= 1) {
|
||||
|
|
@ -173,6 +180,8 @@ class Match extends Model
|
|||
|
||||
//error_log("RoundNr ".$currentRoundNr." Array end:");
|
||||
//error_log(implode(",",$roundRobin));
|
||||
Log::info("RoundNr ".$currentRoundNr." Array end:");
|
||||
Log::info(implode(",",$roundRobin));
|
||||
|
||||
$idx = 0;
|
||||
$slot = 0;
|
||||
|
|
@ -185,20 +194,24 @@ class Match extends Model
|
|||
}
|
||||
$pairings[$idx][$slot] = $userId;
|
||||
//error_log($idx.",".$slot." => ".$userId);
|
||||
Log::info($idx.",".$slot." => ".$userId);
|
||||
}
|
||||
|
||||
// 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");
|
||||
Log::info("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");
|
||||
Log::info("DONT ADD");
|
||||
} else {
|
||||
//error_log("adding...");
|
||||
Log::info("adding...");
|
||||
$pairings_clean[$idx] = $pairing;
|
||||
}
|
||||
}
|
||||
|
|
@ -210,8 +223,8 @@ class Match extends Model
|
|||
foreach ($all as $roundNr => $pairings) {
|
||||
foreach ($pairings as $slotIdx => $pairing) {
|
||||
error_log($pairing[0]." vs ".$pairing[1]);
|
||||
Log::info($pairing[0]." vs ".$pairing[1]);
|
||||
}
|
||||
error_log("");
|
||||
}
|
||||
|
||||
return $all; // $all[$roundnr]= Array of Tuples ( UserId1, UserId2 )
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue