Arbeit an Auf/Abstieg

This commit is contained in:
Torsten 2017-10-29 07:13:52 +01:00
parent 5515e13f02
commit d8a7f78cbd
7 changed files with 61 additions and 52 deletions

View file

@ -35,19 +35,18 @@ class Match extends Model
// Wenn es keine previous League gibt, dann ist $league->rank immer RANK_QUALIFICATION,
// ansonsten ist es einer von RANK_LEAGUE1, RANK_LEAGUE2, RANK_LEAGUE3
if ($league->rank == League::RANK_QUALIFICATION) {
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("all pairings:");
Log::info($allPairings);
foreach ($rounds as $round) {
$pairings = $allPairings[$roundNr];
// Save pairings
foreach($pairings as $pair) {
Log::info("Saving match. ".$pair[0]." vs ".$pair[1]." roundid=".$round->id);
Log::info("Saving match. " . $pair[0] . " vs " . $pair[1] . " roundid=" . $round->id);
$newMatch = Match::create([
'league_id' => $league->id,
'round_id' => $round->id,
@ -55,7 +54,7 @@ class Match extends Model
'user2_id' => $pair[1]
]);
$newMatch->save();
}
}
$roundNr += 1;
if ($roundNr > $neededRoundCount) break;
}
@ -114,8 +113,13 @@ class Match extends Model
}
// Hier findet RoundRobin statt.
public static function getAllPairings($leagueId, $roundCount) {
$members = LeagueMember::getMembers($leagueId);
if (sizeof($members) % 2 == 1) { // ungerade memberzahl => freilos einfügen
array_push($members,-1);
}
shuffle($members);
//error_log("Number of members:".sizeof($members));
$pairingCount = Match::getNumberOfPairingsPerRound($leagueId);
@ -155,29 +159,36 @@ class Match extends Model
$slot = 1;
}
$pairings[$idx][$slot] = $userId;
error_log($idx.",".$slot." => ".$userId);
//error_log($idx.",".$slot." => ".$userId);
}
//error_log("Pairings for RoundNr ".$currentRoundNr.":");
$strPairings="";
//foreach($pairings as $pairing) {
//error_log(">".$pairing[0].":".$pairing[1]);
//$strPairings = $strPairings." ".$pairing[0].":".$pairing[1];
//}
//error_log($strPairings);
//error_log("-------");
// Matches die nur einen Teilnehmer haben entfernen. Passiert bei ungerader Teilnehmerzahl.
// Der nicht im Pairing befindliche Spieler hat einen spielfreien Tag.
$all[$currentRoundNr]=$pairings;
$pairings_clean=array();
foreach($pairings as $idx => $pairing) {
if ($pairing[0] == -1 || $pairing[1] == -1) {
//error_log("DONT ADD");
} else {
//error_log("adding...");
$pairings_clean[$idx] = $pairing;
}
}
$all[$currentRoundNr]=$pairings_clean;
//$all[$currentRoundNr]=$pairings;
}
//foreach ($all as $roundNr => $pairings) {
// foreach ($pairings as $pairing)
//error_log("round_".$roundNr.":user_".$pairing[0]."!:user_".$pairing[1]."!");
// foreach ($pairings as $slotIdx => $pairing) {
// error_log($pairing[0]." vs ".$pairing[1]);
// }
// error_log("");
//}
//return null;
return $all; // $all[$roundnr]= Array of Tuples ( UserId1, UserId2 )
//return null;
}
public static function getNumberOfPairingsPerRound($leagueId) {
@ -190,8 +201,11 @@ class Match extends Model
}
public static function getNumberOfNeededRounds($leagueId) {
$members = LeagueMember::getMembers($leagueId);
return sizeof($members)-1;
$members = LeagueMember::getMembers($leagueId);
$memberCount = sizeof($members);
if ($memberCount % 2 == 1) { return $memberCount; } // 1 Runde mehr wg. Freilos für 1 Spieler
return $memberCount-1;
}
public static function getMatchResults($leagueId, $maxRoundId=-1) {