Performance improvement PayoutPerUserDetails, using cached Quota::getPayoutList

This commit is contained in:
Torsten 2018-02-04 08:20:40 +01:00
parent 52aacdc76f
commit 45259cbd4a
3 changed files with 127 additions and 28 deletions

View file

@ -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",