Fixing creation of new player league
This commit is contained in:
parent
9126d54dfb
commit
d6a51ea2c6
16 changed files with 154 additions and 507 deletions
|
|
@ -554,6 +554,8 @@ class UsersController extends Controller
|
|||
|
||||
usort($sortedPayout,array($this,'cmpPayment'));
|
||||
|
||||
//dd($sortedPayout);
|
||||
|
||||
return view ('users.payout_ranking_index',compact('sortedPayout'));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -48,10 +48,8 @@ class Round extends Model
|
|||
}
|
||||
|
||||
public static function getLastCompleteRoundId($seasonId=-1) {
|
||||
$season=null;
|
||||
if ($seasonId==-1) {
|
||||
$season = Season::getCurrent();
|
||||
} else {
|
||||
$season = Season::getCurrent();
|
||||
if ($seasonId!=-1) {
|
||||
$season=Season::where('id','=',$seasonId)->first();
|
||||
}
|
||||
if (!$season) return -1;
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ class Test extends Model
|
|||
$users = User::all();
|
||||
$cnt=0;
|
||||
foreach ($users as $user) {
|
||||
if (!$user->deleted)
|
||||
if (!$user->deleted && $user->id !=1)
|
||||
{ Payment::set_payment_date($user->id, $seasonId, '01.01.2017'); $cnt+=1;}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -247,13 +247,6 @@ class Tipp extends Model
|
|||
// TODO: Implement partial caching
|
||||
public static function getRoundTipps($max_round_id=-1, $seasonId=-1)
|
||||
{
|
||||
$currentSeason = null;
|
||||
if ($seasonId == null) {
|
||||
$currentSeason = Season::getCurrent();
|
||||
} else {
|
||||
$currentSeason = Season::where('id', '=', $seasonId)->first();
|
||||
}
|
||||
|
||||
$startTime = microtime(true);
|
||||
|
||||
$currentSeason = Season::getCurrent();
|
||||
|
|
@ -261,7 +254,10 @@ class Tipp extends Model
|
|||
$currentSeason = Season::where('id', '=', $seasonId)->first();
|
||||
};
|
||||
|
||||
if (Round::getLastLockedRoundId()==-1) return null;
|
||||
if (Round::getLastCompleteRoundId($seasonId)==-1) {
|
||||
error_log("Tipp::getRoundTipps returns null, because there is no completeRoundId");
|
||||
return null;
|
||||
}
|
||||
|
||||
// Hier werden _alle_ Tipps der aktuellen Saison ausgerechnet, die $round_id Begrenzung wird erst später ausgewertet.
|
||||
// TODO: Nur die Runden durchrechnen, die aktuell sind, oder round_incomplete, alle anderen Runden (bis zur ersten unvollständigen) sollen in eine Cachetabelle gespeichert werden.
|
||||
|
|
@ -500,6 +496,9 @@ class Tipp extends Model
|
|||
$grank= $roundtipps[$key]["grank"];
|
||||
if ($grank<=5) {
|
||||
$gain = round($scoreGain[$grank] / $members[$grank], 2);
|
||||
if ($gain>0) {
|
||||
$gain+=$roundtipps[$key]["rankscore"]; // Gemachte Punkte draufrechnen
|
||||
}
|
||||
$roundtipps[$key]["gshirt_score"] = $gain;
|
||||
} else {
|
||||
$roundtipps[$key]["gshirt_score"]=0;
|
||||
|
|
@ -518,7 +517,7 @@ class Tipp extends Model
|
|||
$score = $roundtipps[$key]['gshirt_score'];
|
||||
$isFoul = ( $roundtipps[$key]['rankscore'] == 0 && $totalScore > 0 );
|
||||
if ($isFoul) {
|
||||
Log::info("Foul => round_id _ user_id=".$key." / totalRankScore=".$roundtipps[$key]["totalRankScore"]);
|
||||
//Log::info("Foul => round_id _ user_id=".$key." / totalRankScore=".$roundtipps[$key]["totalRankScore"]);
|
||||
$foulCount+=1;
|
||||
if ($foulCount==3) {
|
||||
$foulCount=0;
|
||||
|
|
|
|||
|
|
@ -133,7 +133,7 @@ class User extends Authenticatable
|
|||
}
|
||||
|
||||
$dbDate=$year . "-" . $month . "-" . $day . " " . $hour . ":" . $minute . ":00";
|
||||
Log::info("deDate=".$deDate." converted to:".$dbDate);
|
||||
//Log::info("deDate=".$deDate." converted to:".$dbDate);
|
||||
|
||||
return $dbDate;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -162,9 +162,12 @@ class League extends Model
|
|||
foreach ($matches as $match) {
|
||||
if (Round::isCompleted($match->round_id)) {
|
||||
$memberScores[$match->user1_id][1] += $match->user1_league_score;
|
||||
error_log("+++ ".$match->user1_id." +".$match->user1_league_score);
|
||||
$memberScores[$match->user1_id][2] += $match->user1_rankscore; // goals
|
||||
$memberScores[$match->user1_id][3] += $match->user2_rankscore; // countergoals
|
||||
|
||||
$memberScores[$match->user2_id][1] += $match->user2_league_score;
|
||||
error_log("+++ ".$match->user2_id." +".$match->user2_league_score);
|
||||
$memberScores[$match->user2_id][2] += $match->user2_rankscore; // goals
|
||||
$memberScores[$match->user2_id][3] += $match->user1_rankscore; // countergoals
|
||||
}
|
||||
|
|
@ -173,11 +176,17 @@ class League extends Model
|
|||
|
||||
$leagueScores[$league->id]=$memberScores;
|
||||
|
||||
error_log("League::getRanking leagueid / userid / score");
|
||||
|
||||
foreach ($memberScores as $entry) {
|
||||
error_log($league->id." / ".$entry[0]." / ".$entry[1]);
|
||||
}
|
||||
error_log("---");
|
||||
|
||||
}
|
||||
return $leagueScores;
|
||||
}
|
||||
|
||||
|
||||
// Für Auf/Abstiegsberechnung - wird auf previous Season angewendet.
|
||||
// getUnifiedRanking bezieht sich (nur) auf Gruppen-Übergreifende Listung (also alle Untergruppen)
|
||||
// Rank = -1 bedeutet über alle Ranks (benötigt für Auf- und Abstieg über alle Ligen)
|
||||
|
|
@ -419,20 +428,21 @@ class League extends Model
|
|||
}
|
||||
}
|
||||
|
||||
Log::info("Creating unified List from previous season");
|
||||
Log::info("League::createLeagues Creating unified List from previous season");
|
||||
$unifiedList = League::getTotalRankingOverall($previousSeason->id); // WICHTIG !! getTotalRankingOverall implentiert Auf- und Abstieg !!
|
||||
|
||||
Log:info("Unified List:");
|
||||
Log:info("League::createLeagues Unified List:");
|
||||
$userNames = User::getNames();
|
||||
|
||||
$unifiedList2=array(); // We will only transfer users over to here that have paid the current season and are not deleted.
|
||||
$count=0;
|
||||
foreach($unifiedList as $listEntry) {
|
||||
$userId = $listEntry[0];
|
||||
$leagueScore=$listEntry[1];
|
||||
if (User::is_season_paid($userId) && !User::isDeleted($userId)) {
|
||||
$count+=1;
|
||||
array_push($unifiedList2, $listEntry);
|
||||
Log::info($count.".) [".$userId."] ".$userNames[$userId]);
|
||||
Log::info($count.".) [".$userId."] ".$userNames[$userId]." ".$leagueScore." Punkte");
|
||||
} else {
|
||||
Log::info($count.".) [".$userId."] ".$userNames[$userId]." [DELETED]");
|
||||
}
|
||||
|
|
@ -443,7 +453,7 @@ class League extends Model
|
|||
// Jetzt neue Spieler hinzufügen, die letzte Saison noch nicht dabei waren, und deshalb in getTotalRankingOverall nicht enthalten sind.
|
||||
|
||||
|
||||
Log::info("Adding new users not within previous season");
|
||||
Log::info("League::createLeagues Adding new users not within previous season");
|
||||
foreach( League::getNewUsers() as $entry) {
|
||||
array_push($unifiedList, $entry);
|
||||
$userId=$entry[0];
|
||||
|
|
@ -458,7 +468,7 @@ class League extends Model
|
|||
$subLeague=1; // for rank 3 leagues only
|
||||
$leagueCount=1;
|
||||
$leagueIndex=0;
|
||||
Log::info("unified list size= ".sizeof($unifiedList));
|
||||
Log::info("League::createLeagues unified list size= ".sizeof($unifiedList));
|
||||
|
||||
foreach($unifiedList as $entry) {
|
||||
|
||||
|
|
@ -471,7 +481,7 @@ class League extends Model
|
|||
$neededSize3+=1;
|
||||
}
|
||||
|
||||
Log::info("Needed min/switch size for rank 3 leagues: ".$neededSize3);
|
||||
Log::info("League::createLeagues Needed min/switch size for rank 3 leagues: ".$neededSize3);
|
||||
}
|
||||
if ($nr>45 && $leagueCount > $neededSize3) {
|
||||
$subLeague+=1;
|
||||
|
|
@ -479,7 +489,7 @@ class League extends Model
|
|||
$leagueIndex+=1;
|
||||
}
|
||||
|
||||
Log::info("#".$leagueCount." Liga ".$leagueNr."-".$subLeague.") ".$nr." ".$entry[0]." (".$userNames[$entry[0]].")");
|
||||
Log::info("League::createLeagues "."#".$leagueCount." Liga ".$leagueNr."-".$subLeague.") ".$nr." ".$entry[0]." (".$userNames[$entry[0]].")");
|
||||
|
||||
$league=$createdLeagues[$leagueIndex];
|
||||
$leagueMember = LeagueMember::create([
|
||||
|
|
|
|||
|
|
@ -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