Preparing for beyond-season data: making ranking season-sensitive
This commit is contained in:
parent
29e493e22d
commit
6309b2b7fa
7 changed files with 12556 additions and 32 deletions
|
|
@ -31,8 +31,12 @@ class Match extends Model
|
|||
$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 = Match::getPairings($league->id, $roundNr);
|
||||
$pairings = $allPairings[$roundNr];
|
||||
// Save pairings
|
||||
foreach($pairings as $pair) {
|
||||
Log::info("Saving match. ".$pair[0]." vs ".$pair[1]." roundid=".$round->id);
|
||||
|
|
@ -100,42 +104,70 @@ class Match extends Model
|
|||
}
|
||||
|
||||
|
||||
public static function getPairings($leagueId, $roundNr) {
|
||||
public static function getAllPairings($leagueId, $roundCount) {
|
||||
$members = LeagueMember::getMembers($leagueId);
|
||||
shuffle($members);
|
||||
Log::info("Number of members:".sizeof($members));
|
||||
//error_log("Number of members:".sizeof($members));
|
||||
$pairingCount = Match::getNumberOfPairingsPerRound($leagueId);
|
||||
|
||||
$roundRobin=array();
|
||||
foreach($members as $userId) {
|
||||
array_push($roundRobin, $userId);
|
||||
$all = array();
|
||||
|
||||
for ($currentRoundNr=1; $currentRoundNr<= $roundCount; $currentRoundNr++) {
|
||||
|
||||
$roundRobin = array();
|
||||
foreach ($members as $userId) {
|
||||
array_push($roundRobin, $userId);
|
||||
}
|
||||
|
||||
//error_log("RoundNr ".$currentRoundNr." Array start:");
|
||||
//error_log(implode(",",$roundRobin));
|
||||
|
||||
$_roundNr = $currentRoundNr;
|
||||
while ($_roundNr >= 1) {
|
||||
// Round-Robin shift: First element stays, rest rotates
|
||||
$first = array_shift($roundRobin); // Erstes Element sichern & entfernen
|
||||
$last = array_pop($roundRobin); // Letztes Element sichern & entfernen
|
||||
array_unshift($roundRobin, $last); // Vorne einfügen
|
||||
array_unshift($roundRobin, $first); // Vorne einfügen
|
||||
$_roundNr--;
|
||||
}
|
||||
|
||||
//error_log("RoundNr ".$currentRoundNr." Array end:");
|
||||
//error_log(implode(",",$roundRobin));
|
||||
|
||||
$idx = 0;
|
||||
$slot = 0;
|
||||
$pairings = array();
|
||||
foreach ($roundRobin as $index => $userId) {
|
||||
$idx = $index;
|
||||
if ($index >= $pairingCount) {
|
||||
$idx = 2 * $pairingCount - $index - 1;
|
||||
$slot = 1;
|
||||
}
|
||||
$pairings[$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("-------");
|
||||
|
||||
$all[$currentRoundNr]=$pairings;
|
||||
|
||||
}
|
||||
|
||||
while ($roundNr>1) {
|
||||
// Round-Robin shift: First element stays, rest rotates
|
||||
$first = array_shift($roundRobin); // Erstes Element sichern & entfernen
|
||||
$last = array_pop($roundRobin); // Letztes Element sichern & entfernen
|
||||
array_unshift($roundRobin, $last); // Vorne einfügen
|
||||
array_unshift($roundRobin, $first); // Vorne einfügen
|
||||
$roundNr--;
|
||||
}
|
||||
|
||||
error_log("Members: ".sizeof($roundRobin));
|
||||
foreach ($roundRobin as $index => $userId) {
|
||||
error_log($index." => ".$userId);
|
||||
}
|
||||
|
||||
$idx=0;
|
||||
$slot=0;
|
||||
$pairings=array();
|
||||
foreach ($roundRobin as $index => $userId) {
|
||||
$idx=$index;
|
||||
if ($index >= $pairingCount){ $idx -= $pairingCount; $slot=1;}
|
||||
$pairings[$idx][$slot]=$userId;
|
||||
error_log("pairings[".$idx."][".$slot."]=".$userId);
|
||||
}
|
||||
|
||||
return $pairings; // Array, der User1/User2 Tupel enthält
|
||||
//foreach ($all as $roundNr => $pairings) {
|
||||
// foreach ($pairings as $pairing)
|
||||
//error_log("round_".$roundNr.":user_".$pairing[0]."!:user_".$pairing[1]."!");
|
||||
//}
|
||||
//return null;
|
||||
return $all; // $all[$roundnr]= Array of Tuples ( UserId1, UserId2 )
|
||||
}
|
||||
|
||||
public static function getNumberOfPairingsPerRound($leagueId) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue