Working on Qualification Pairings

This commit is contained in:
Torsten 2017-09-22 17:40:48 +02:00
parent 9c0f94758d
commit a66189ca00
19 changed files with 9005 additions and 237 deletions

View file

@ -13,24 +13,27 @@ use App\Season;
use App\Round;
use App\User;
use App\leagues\League;
use App\leagues\LeagueMember;
use App\Leagues\League;
use App\Leagues\LeagueMember;
use App\Leagues\Match;
use Log;
use DB;
class LeagueController extends Controller
class LeaguesController extends Controller
{
public function index($season_id) {
public function index() {
$season=Season::getCurrent();
if (Auth::guest()) { return redirect("/"); }
if (!Auth::user()->admin) { return redirect("/"); }
$season = Season::where('id','=',$season_id)->first();
$season = Season::where('id','=',$season->id)->first();
if (!$season) return redirect("/seasons");
$start_round_name="Einstellen";
$rounds = Round::where('season_id','=',$season_id)->orderBy('id')->get();
$rounds = Round::where('season_id','=',$season->id)->orderBy('id')->get();
if (!$rounds) return redirect("/seasons");
$round_count = 18;
@ -38,9 +41,9 @@ class LeagueController extends Controller
$start_round_id=$rounds[0]->id;
$league_mode="Einstellen";
$league = League::where('season_id','=',$season_id)->first();
$league = League::where('season_id','=',$season->id)->first();
if ($league) {
$startround = Round::where('season_id', '=', $season_id)->orderBy('id')->first();
$startround = Round::where('season_id', '=', $season->id)->orderBy('id')->first();
$start_round_id = $startround->id;
$startRound = Round::where('id','=',$league->start_round_id)->first();
@ -75,13 +78,13 @@ class LeagueController extends Controller
}
}
$active_member_count=sizeof(User::getActives());
Log::info("Aktive Spieler: ".$active_member_count);
$neededLeagues = League::neededLeagues($active_member_count, $round_count);
Log::info("Benötigte Quali-Gruppen: ".$neededLeagues);
$league_ids=array();
Log::info("League Mode:".$league_mode);
if ($league_mode=="Qualifikation") {
for ($league_nr=1; $league_nr<=$neededLeagues; $league_nr+=1) {
$league = League::create([
@ -101,6 +104,7 @@ class LeagueController extends Controller
$users = User::getActives();
shuffle($users);
$league_index=0;
Log::info("Distributing Members between groups");
while(sizeof($users)>0) {
$user = array_pop($users);
@ -115,7 +119,6 @@ class LeagueController extends Controller
}
} else {
// ToDo: Achtel-, Viertel-, Halb-, Finale require additional leagues; Same with Pokal, so createMissingLeagues method will be needed in the future
$league_size1= min(22,$active_member_count);
@ -134,8 +137,8 @@ class LeagueController extends Controller
if ($league_size2>0) {
$league2 = League::create([
'is_qualification' => false,
'name' => 'Spielerliga 1',
'rank' => '1',
'name' => 'Spielerliga 2',
'rank' => '2',
'subrank' => '1',
'round_count' => $round_count,
'season_id' => $currentSeason->id,
@ -163,6 +166,37 @@ class LeagueController extends Controller
}
}
Match::createMissingMatchups();
return redirect("/seasons");
}
public function showLeagueRounds($league_rank, $round_id) { // $round_id = $max_round_id
if (Auth::guest()) { return redirect("/"); }
$season=Season::getCurrent();
$roundNames = Round::getNames();
$leagueNames = League::getNames();
$leagues = League::where('season_id','=',$season->id)->where('rank','=', $league_rank)->get();
$matchesTotal = array();
foreach ($leagues as $league) {
$matches = Match::getLeagueMatches($league->id);
foreach ($matches as $match) {
if ($match->round_id <= $round_id) {
if (!key_exists($match->round_id, $matchesTotal)) {
$matchesTotal[$match->round_id]=array();
}
$lg = $matchesTotal[$match->round_id];
array_push($lg, $match);
$matchesTotal[$match->round_id] = $lg;
}
}
}
return view ('leagues.matches', compact('season', 'matchesTotal','leagues','leagueNames','roundNames'));
}
}

View file

@ -119,7 +119,7 @@ class TippsController extends Controller
// Joker gesetzt ? Dann Jokerflag für alle Tipps der selben Runde entfernen
if ($tipp->joker){
Log::info("Checking for joker strip");
//Log::info("Checking for joker strip");
$game=Game::where('id','=',$tipp->game_id)->first();
$round_id=$game->round_id;
@ -127,12 +127,13 @@ class TippsController extends Controller
foreach ($games as $game) {
$tipp = Tipp::where('user_id', $user->id)->where('game_id', $game->id)->first();
Log::info("Testing game_id " . $game->id);
//Log::info("Testing game_id " . $game->id);
if ($tipp->id != request('id')) {
Log::info("Resetting game_id " . $game->id);
//Log::info("Resetting game_id " . $game->id);
$tipp->joker = false;
$tipp->save();
}
}
}

View file

@ -221,8 +221,6 @@ class UsersController extends Controller
$user_ids = $response['user_ids'];
$round_ids = $response['round_ids'];
///////////////////////////// DISPLAY AUFBAU /////////////////////////////
///
@ -233,6 +231,8 @@ class UsersController extends Controller
$isFinalRound=false;
Log::info("Starting Display Loop");
foreach ($user_ids as $user_id) {
$rankscore_total= 0;
$payout_sum = 0;
@ -251,10 +251,12 @@ class UsersController extends Controller
$rankingDisplay[$user_id]["user_name"] = $roundtipps[$key]["user_name"];
$rankingDisplay[$user_id]["is_dayscorewinner"] = $roundtipps[$key]["is_dayscorewinner"];
if ($round_id==4 && $roundtipps[$key]["is_dayscorewinner"]) {
//Log::info("Dayscorewinner: ".$roundtipps[$key]["user_name"]);
}
if ($round_id=="13") {
Log::info('userid '.$user_id." [".$key."]");
Log::info($roundtipps[$key]["is_dayscorewinner"]);
Log::info($roundtipps[$key]["payout"]);
}
$rankingDisplay[$user_id]["ranking_payout"] = $roundtipps[$key]["ranking_payout"];
if ($roundtipps[$key]["ranking_payout"]>0) {
@ -309,8 +311,6 @@ class UsersController extends Controller
$rankingDisplay[$user_id]["trendCol4"] = Tipp::trendCol($roundtipps[$key]["results"][6],$roundtipps[$key]["results"][7],
$roundtipps[$key]["tipps"][6],$roundtipps[$key]["tipps"][7],
$roundtipps[$key]["joker"][3]);
}
$userids = array_keys($rankingDisplay);
@ -334,7 +334,6 @@ class UsersController extends Controller
$game_results=array(); // 4 Spielergebnisse der angezeigten Runde
array_push($game_results,$rankingDisplay[0]["result_score1"],$rankingDisplay[0]["result_score2"],$rankingDisplay[0]["result_score3"],$rankingDisplay[0]["result_score4"],$rankingDisplay[0]["result_score5"],$rankingDisplay[0]["result_score6"],$rankingDisplay[0]["result_score7"],$rankingDisplay[0]["result_score8"]);
Log::info("UserController::ranking: ExecutionTime: " . number_format(( microtime(true) - $startTime), 4) . " Seconds\n");
return view('users.ranking', compact('all_rounds','rankingDisplay','userids','round','games','game_results','isFinalRound'));
}
@ -475,6 +474,15 @@ class UsersController extends Controller
foreach($user_ids as $user_id) {
$key=$round_id."_".$user_id;
if ($key=='13_44') {
Log::info("Debat(44) Debug");
Log::info("is_dayscorewinner:");
Log::info($roundtipps[$key]['is_dayscorewinner']);
Log::info("payout:");
Log::info($roundtipps[$key]['payout']);
}
$payout = str_replace(",",".",$roundtipps[$key]['payout']);
if (strlen($payout)==0) { $payout=0; }