Preparing for beyond-season data: making ranking season-sensitive

This commit is contained in:
Torsten 2017-10-09 10:34:27 +02:00
parent 29e493e22d
commit 6309b2b7fa
7 changed files with 12556 additions and 32 deletions

12486
d0274241_2017-10-07_2039.sql Normal file

File diff suppressed because it is too large Load diff

View file

@ -305,6 +305,8 @@ class Tipp extends Model
$game_value=Tipp::getScoreLocal($entry->game_score1,$entry->game_score2,$entry->tipp_score1,$entry->tipp_score2,$entry->joker); // Für alle 4 Spiele
$roundtipps[$key]['rankscore']+=$game_value;
if($game_value>0) { $roundtipps[$key]['hits']+=1;}
if ($roundtipps[$key]['hits']==4) {$roundtipps[$key]['rankscore']+=2;} // Wenn alle 4 Spiele mind. Tendenz, dann 2 Punkte Bonus
@ -509,6 +511,7 @@ class Tipp extends Model
$response['round_ids'] = $round_ids;
Log::info("Tipp::getRoundTipps: ExecutionTime: " . number_format(( microtime(true) - $startTime), 4) . " Seconds\n");
return $response;
}

View file

@ -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) {

View file

@ -20,7 +20,7 @@
<a style="font-color: blue; font-size: 22px;" href="/tipps#{{\App\Round::getFirstTippableRound()->id}}">Tipps</a> &nbsp;
&nbsp;
<a style="font-color: blue; font-size: 22px;" href="/users/ranking/roundid_-1#playerid_{{Auth::user()->id}}" >Rangliste</a> &nbsp;
&nbsp;
<label class="dropdown" id="dropdown2">
<a href="#" id="btn_league" onclick="toggleSelect('dropdown_league'); return false;" style="font-weight:normal; font-color: blue; font-size: 22px;">Spieler-Liga</a>
<div id="dropdown_league" class="dropdown-content">
@ -28,6 +28,7 @@
<a style="font-weight:normal; font-color: blue; font-size: 22px;" href="/league/show/rank=4/max_round_id=-1">Tabellen</a> &nbsp;
</div>
</label>
&nbsp;
<label class="dropdown" id="dropdown3">
<a href="#" id="btn_info" onclick="toggleSelect('dropdown_info'); return false;" style="font-weight:normal; font-color: blue; font-size: 22px;">Info</a>

View file

@ -9,7 +9,7 @@
<!-- Start Runden-Loop-->
@foreach($matchesTotal as $round_id => $roundGroup)
<h2><a href="http://hoschis-tippspiel.de/users/ranking/roundid_{{$round_id}}#playerid_0">{{$roundNames[$round_id]}}</a></h2>
<h2><a href="/users/ranking/roundid_{{$round_id}}#playerid_-1">{{$roundNames[$round_id]}}</a></h2>
<!-- Start Liga-Loop-->
@foreach($matchesTotal[$round_id] as $league_id => $matchGroup)

View file

@ -48,6 +48,7 @@ return array(
'App\\Roundmail' => $baseDir . '/app/Roundmail.php',
'App\\Season' => $baseDir . '/app/Season.php',
'App\\Setting' => $baseDir . '/app/Setting.php',
'App\\Test' => $baseDir . '/app/Test.php',
'App\\Tipp' => $baseDir . '/app/Tipp.php',
'App\\User' => $baseDir . '/app/User.php',
'Carbon\\Carbon' => $vendorDir . '/nesbot/carbon/src/Carbon/Carbon.php',

View file

@ -320,6 +320,7 @@ class ComposerStaticInita19fb0695e1b61b4feeb3cc3fbdd2feb
'App\\Roundmail' => __DIR__ . '/../..' . '/app/Roundmail.php',
'App\\Season' => __DIR__ . '/../..' . '/app/Season.php',
'App\\Setting' => __DIR__ . '/../..' . '/app/Setting.php',
'App\\Test' => __DIR__ . '/../..' . '/app/Test.php',
'App\\Tipp' => __DIR__ . '/../..' . '/app/Tipp.php',
'App\\User' => __DIR__ . '/../..' . '/app/User.php',
'Carbon\\Carbon' => __DIR__ . '/..' . '/nesbot/carbon/src/Carbon/Carbon.php',