Performance improvement PayoutPerUserDetails, using cached Quota::getPayoutList
This commit is contained in:
parent
52aacdc76f
commit
45259cbd4a
3 changed files with 127 additions and 28 deletions
|
|
@ -255,6 +255,8 @@ class UsersController extends Controller
|
|||
|
||||
$isFinalRound=false;
|
||||
|
||||
$payoutList = Quota::getPayoutList($response);
|
||||
|
||||
Log::info("Starting Display Loop");
|
||||
|
||||
foreach ($user_ids as $user_id) {
|
||||
|
|
@ -281,10 +283,6 @@ class UsersController extends Controller
|
|||
$rankingDisplay[$user_id]["gshirt_foulcount"] = $roundtipps[$key]["gshirt_foulcount"];
|
||||
$rankingDisplay[$user_id]["gshirt_leader"] = $roundtipps[$key]["gshirt_leader"];
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
$rankingDisplay[$user_id]["ranking_payout"] = $roundtipps[$key]["ranking_payout"];
|
||||
if ($roundtipps[$key]["ranking_payout"]>0) {
|
||||
$isFinalRound=true;
|
||||
|
|
@ -338,8 +336,22 @@ 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]);
|
||||
|
||||
// Add GShirt payout
|
||||
if (Season::hasGreenShirtGame()) {
|
||||
$rankingDisplay[$user_id]['gshirt_payout']=0;
|
||||
$userPayouts = $payoutList[$user_id];
|
||||
|
||||
foreach ($userPayouts as $payoutItem) {
|
||||
if ($payoutItem['roundname']=="Grünes Trikot") {
|
||||
$rankingDisplay[$user_id]["gshirt_payout"] = $payoutItem['payout'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
$userids = array_keys($rankingDisplay);
|
||||
$round=Round::where('id','=',$max_round_id)->first();
|
||||
$games=Game::where('round_id','=',$max_round_id)->get();
|
||||
|
|
@ -357,11 +369,10 @@ class UsersController extends Controller
|
|||
|
||||
// Store game results as separate array. Wir nutzen aus, dass die Ergebnisse in jeder Zeile
|
||||
// von Rankingdisplay abgespeichert sind.
|
||||
|
||||
$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");
|
||||
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'));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -113,9 +113,6 @@ class Quota extends Model
|
|||
$payouts['liga_platz3_1'] = $euro_liga_platz3_1;
|
||||
$payouts['gshirt'] = $euro_gruenes_trikot;
|
||||
$payouts['pokal'] = $euro_pokal;
|
||||
|
||||
|
||||
|
||||
return $payouts;
|
||||
|
||||
}
|
||||
|
|
@ -329,12 +326,95 @@ class Quota extends Model
|
|||
return $number;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static function getPayoutPerUserDetails($userId) {
|
||||
$response = Tipp::getRoundTipps();
|
||||
// Beinhaltet Liste der Payouts für alle User.
|
||||
// User ohne Payout sind mit leerer Liste ebenfalls enthalten.
|
||||
public static function getPayoutList($response=null) {
|
||||
if (!$response) {
|
||||
$response = Tipp::getRoundTipps();
|
||||
}
|
||||
$roundtipps = $response['roundtipps'];
|
||||
$round_ids = $response['round_ids'];
|
||||
$round_ids = $response['round_ids'];
|
||||
$user_ids = $response['user_ids'];
|
||||
|
||||
$payouts = array();
|
||||
$cnt=0;
|
||||
foreach($round_ids as $round_id) {
|
||||
|
||||
foreach($user_ids as $userId) {
|
||||
$key = $round_id . "_" . $userId;
|
||||
$payout = $roundtipps[$key]['payout'];
|
||||
$payoutList[$userId]=array(); // Wird unten fuer ManualPayout+GreenShirt benötigt. Eine PayoutListe für jeden User
|
||||
|
||||
if (strlen($payout) > 0) {
|
||||
$round = Round::where('id', '=', $round_id)->first();
|
||||
|
||||
$item = array();
|
||||
$item['roundname'] = $round->name . " (Tagessieg)";
|
||||
$item['payout'] = $payout;
|
||||
array_push($payouts, $item);
|
||||
}
|
||||
|
||||
if ($roundtipps[$key]['ranking_payout'] > 0) {
|
||||
$item = array();
|
||||
$item['roundname'] = "Platzierungssieg Rang " . $roundtipps[$key]['rank'];
|
||||
$item['payout'] = $roundtipps[$key]['ranking_payout'];
|
||||
array_push($payouts, $item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Gshirt START
|
||||
if (Season::hasGreenShirtGame() ) {
|
||||
$gshirtTotalPayout = Quota::getPayouts()['gshirt'];
|
||||
$leaderCount = 0;
|
||||
$leaderIds = array();
|
||||
foreach ($user_ids as $uid) {
|
||||
|
||||
$key = Round::getLastRoundId() . "_" . $uid; // $key could be nonexistenen if we are not in the last round
|
||||
if (!array_key_exists($key, $roundtipps)) continue;
|
||||
if ($roundtipps[$key]['gshirt_leader'] == 1) {
|
||||
$leaderCount += 1;
|
||||
array_push($leaderIds,$uid);
|
||||
}
|
||||
}
|
||||
|
||||
if ($leaderCount) {
|
||||
$payoutPerLeader = round($gshirtTotalPayout / $leaderCount, 2);
|
||||
foreach ($leaderIds as $leaderId) {
|
||||
$item = array();
|
||||
$item['roundname'] = "Grünes Trikot";
|
||||
$item['payout'] = $payoutPerLeader;
|
||||
array_push($payoutList[$leaderId], $item);
|
||||
}
|
||||
}
|
||||
}
|
||||
// GSHirt End
|
||||
|
||||
|
||||
// Manuelle Payouts hinzufügen
|
||||
$names = ["pokal" => "Pokal", "liga_platz1"=>"Liga 1, Platz 1",
|
||||
"liga_platz2"=>"Liga 1, Platz 2 ", "liga_platz3" => "Liga 1, Platz 3",
|
||||
"liga_platz2_1" =>"Liga 2, Platz 1", "liga_platz3_1"=>"Liga 3, Platz 1"
|
||||
];
|
||||
$_payouts = Quota::getPayouts();
|
||||
$winners = ManualPayout::getWinners();
|
||||
foreach ($winners as $quota => $uId) {
|
||||
$item = array();
|
||||
$item['roundname']=$names[$quota];
|
||||
$item['payout']=$_payouts[$quota];
|
||||
array_push($payoutList,$item);
|
||||
}
|
||||
|
||||
return $payoutList;
|
||||
}
|
||||
|
||||
|
||||
public static function getPayoutPerUserDetails($userId, $response=null) {
|
||||
if (!$response) {
|
||||
$response = Tipp::getRoundTipps();
|
||||
}
|
||||
$roundtipps = $response['roundtipps'];
|
||||
$round_ids = $response['round_ids'];
|
||||
$user_ids = $response['user_ids'];
|
||||
|
||||
$payouts = array();
|
||||
|
|
@ -367,29 +447,30 @@ class Quota extends Model
|
|||
$leaderCount = 0;
|
||||
$leaderIds = array();
|
||||
foreach ($user_ids as $uid) {
|
||||
Log::info(Round::getLastRoundId());
|
||||
$key = Round::getLastRoundId() . "_" . $uid;
|
||||
Log::info("ok");
|
||||
|
||||
$key = Round::getLastRoundId() . "_" . $uid; // $key could be nonexistenen if we are not in the last round
|
||||
if (!array_key_exists($key, $roundtipps)) continue;
|
||||
if ($roundtipps[$key]['gshirt_leader'] == 1) {
|
||||
$leaderCount += 1;
|
||||
array_push($leaderIds,$uid);
|
||||
}
|
||||
}
|
||||
$payoutPerLeader = round($gshirtTotalPayout / $leaderCount, 2);
|
||||
foreach($leaderIds as $leaderId) {
|
||||
if ($userId == $leaderId) {
|
||||
$item = array();
|
||||
$item['roundname']="Grünes Trikot";
|
||||
$item['payout']=$payoutPerLeader;
|
||||
array_push($payouts,$item);
|
||||
|
||||
if ($leaderCount) {
|
||||
$payoutPerLeader = round($gshirtTotalPayout / $leaderCount, 2);
|
||||
foreach ($leaderIds as $leaderId) {
|
||||
if ($userId == $leaderId) {
|
||||
$item = array();
|
||||
$item['roundname'] = "Grünes Trikot";
|
||||
$item['payout'] = $payoutPerLeader;
|
||||
array_push($payouts, $item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// GSHirt End
|
||||
|
||||
|
||||
|
||||
|
||||
// Manuelle Payouts hinzufügen
|
||||
$names = ["pokal" => "Pokal", "liga_platz1"=>"Liga 1, Platz 1",
|
||||
"liga_platz2"=>"Liga 1, Platz 2 ", "liga_platz3" => "Liga 1, Platz 3",
|
||||
|
|
|
|||
|
|
@ -149,13 +149,18 @@
|
|||
<th> </th><!-- Spacer Column -->
|
||||
<th style="height:140px;white-space: nowrap;">
|
||||
<div style="transform:translate(10px, 51px) rotate(270deg);width:30px;">
|
||||
<span style="border-bottom: 1px solid #ccc; padding: 5px 10px;">Ausschüttung Tagessieg</span>
|
||||
<span style="border-bottom: 1px solid #ccc; padding: 5px 10px;">Preisgeld Tagessieg</span>
|
||||
</div>
|
||||
</th>
|
||||
@if($isFinalRound)
|
||||
<th style="height:140px;white-space: nowrap;">
|
||||
<div style="transform:translate(10px, 51px) rotate(270deg);width:30px;">
|
||||
<span style="border-bottom: 1px solid #ccc; padding: 5px 10px;">Aussch.Platzierung</span>
|
||||
<span style="border-bottom: 1px solid #ccc; padding: 5px 10px;">Preisgeld Platzierung</span>
|
||||
</div>
|
||||
</th>
|
||||
<th style="height:140px;white-space: nowrap;">
|
||||
<div style="transform:translate(10px, 51px) rotate(270deg);width:30px;">
|
||||
<span style="border-bottom: 1px solid #ccc; padding: 5px 10px;">Preisgeld grünes Trikot</span>
|
||||
</div>
|
||||
</th>
|
||||
@endif
|
||||
|
|
@ -186,6 +191,8 @@
|
|||
<td class="table-bordered" align="center" > {{ $entry["payout"] }} {{ $entry["payout"]>0 ? '€': '' }}</td>
|
||||
@if($isFinalRound)
|
||||
<td class="table-bordered" align="center" > {{ $entry["ranking_payout"]>0 ? $entry["ranking_payout"].'€': '' }} </td>
|
||||
<td class="table-bordered" align="center" > {{ $entry["gshirt_payout"]>0 ? $entry["gshirt_payout"].'€': '' }} </td>
|
||||
|
||||
@endif
|
||||
</tr>
|
||||
@endforeach
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue