Auslagerung roundTipps nach Tipp, um Wiederverwendung und Caching zu ermöglichen
This commit is contained in:
parent
b9e4fcca7f
commit
054a8d6f63
8 changed files with 5871 additions and 213 deletions
5619
d0274241_2017-08-29_1525.sql
Normal file
5619
d0274241_2017-08-29_1525.sql
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -180,6 +180,8 @@ class UsersController extends Controller
|
|||
|
||||
|
||||
public function ranking($max_round_id) {
|
||||
$startTime = microtime(true);
|
||||
|
||||
$currentSeason = Season::getCurrent();
|
||||
|
||||
// Check ob mindestens eine Runde der Saison gelockt ist angezeigt werden kann
|
||||
|
|
@ -204,201 +206,11 @@ class UsersController extends Controller
|
|||
return view('users.no_payment');
|
||||
}
|
||||
|
||||
// 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.
|
||||
$sql = "select users.id as user_id, users.name as user_name, ";
|
||||
$sql = $sql . "rounds.id as round_id, rounds.name as round_name, ";
|
||||
$sql = $sql . "games.id as game_id, games.team1, games.team2, games.score1 as game_score1, games.score2 as game_score2, games.kickoff as game_kickoff, ";
|
||||
$sql = $sql . "tipps.id as tipp_id, tipps.score1 as tipp_score1, tipps.score2 as tipp_score2, tipps.joker ";
|
||||
$sql = $sql . "from users,rounds,games,tipps,payments ";
|
||||
$sql = $sql . "where rounds.season_id=".$currentSeason->id." ";
|
||||
$sql = $sql . "and games.round_id=rounds.id and tipps.game_id=games.id and users.id = tipps.user_id ";
|
||||
$sql = $sql . "and payments.season_id=".$currentSeason->id." and payments.user_id = users.id ";
|
||||
$sql = $sql . "and payments.paid_date is not null ";
|
||||
$sql = $sql . "and users.deleted is null ";
|
||||
$sql = $sql . "order by rounds.id, games.id, users.id;";
|
||||
|
||||
$result=DB::select($sql);
|
||||
|
||||
$roundtipps = array();
|
||||
$user_ids=array();
|
||||
$round_ids=array();
|
||||
|
||||
// Write sql result to roundtipps (score per round & user)
|
||||
if ($max_round_id==-1) { $max_round_id=Round::getLastLockedRoundId(); }
|
||||
foreach ($result as $entry) {
|
||||
$round_id = $entry->round_id;
|
||||
if ($max_round_id >-1 && $round_id>$max_round_id) break;
|
||||
|
||||
if (!in_array($entry->user_id,$user_ids)) { array_push($user_ids,$entry->user_id); }
|
||||
if (!in_array($entry->round_id,$round_ids)) { array_push($round_ids,$entry->round_id); }
|
||||
|
||||
$user_id = $entry->user_id;
|
||||
|
||||
$key = $round_id."_".$user_id;
|
||||
if (!array_key_exists($key,$roundtipps)) {
|
||||
$roundtipps[$key]=array();
|
||||
$roundtipps[$key]['tipps']=array();
|
||||
$roundtipps[$key]['results']=array();
|
||||
$roundtipps[$key]['joker']=array();
|
||||
$roundtipps[$key]['round_completed']=true; // Um ggfs.
|
||||
$roundtipps[$key]['user_name'] = $entry->user_name;
|
||||
$roundtipps[$key]['user_id'] = $entry->user_id;
|
||||
$roundtipps[$key]['rankscore']=0;
|
||||
$roundtipps[$key]['payout']=0;
|
||||
$roundtipps[$key]['earliest_kickoff']=$entry->game_kickoff;
|
||||
$roundtipps[$key]['hits']=0; // Wenigstens Tendenz getroffen. Wenn 4, dann 2 Punkte Bonus auf rankscore
|
||||
$roundtipps[$key]['is_dayscorewinner']=0; // Wenigstens Tendenz getroffen. Wenn 4, dann 2 Punkte Bonus auf rankscore
|
||||
}
|
||||
$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
|
||||
|
||||
if ($entry->game_score1==-1 || $entry->game_score2==-1) { $roundtipps[$key]['round_completed'] = false; }
|
||||
|
||||
array_push($roundtipps[$key]['tipps'],$entry->tipp_score1);
|
||||
array_push($roundtipps[$key]['tipps'],$entry->tipp_score2);
|
||||
array_push($roundtipps[$key]['results'],$entry->game_score1);
|
||||
array_push($roundtipps[$key]['results'],$entry->game_score2);
|
||||
array_push($roundtipps[$key]['joker'],$entry->joker);
|
||||
|
||||
if ( $entry->game_kickoff < $roundtipps[$key]['earliest_kickoff'] ) { $roundtipps[$key]['earliest_kickoff'] = $entry->game_kickoff; }
|
||||
}
|
||||
// NOW ALL KEYS FOR ROUNDTIPPS (ROUND & USER) EXIST
|
||||
|
||||
|
||||
// CALCULATION OF SCORES, RANKS, ETC.
|
||||
|
||||
// FIRST LOOP: COMPUTE AGGREGATED VALUES
|
||||
$highestDayscores=array();
|
||||
foreach($user_ids as $user_id) {
|
||||
$totalRankScore=0;
|
||||
foreach($round_ids as $round_id) {
|
||||
|
||||
|
||||
$key=$round_id."_".$user_id;
|
||||
|
||||
// Compute Dayscore values
|
||||
$dayScore1WithRankScore = Tipp::getDayScoreLocal($roundtipps[$key]['results'][0],$roundtipps[$key]['results'][1],$roundtipps[$key]['tipps'][0],$roundtipps[$key]['tipps'][1],$roundtipps[$key]['joker'][0],$roundtipps[$key]['rankscore']);
|
||||
$dayScore2WithRankScore = Tipp::getDayScoreLocal($roundtipps[$key]['results'][2],$roundtipps[$key]['results'][3],$roundtipps[$key]['tipps'][2],$roundtipps[$key]['tipps'][3],$roundtipps[$key]['joker'][1],$roundtipps[$key]['rankscore']);
|
||||
$dayScore3WithRankScore = Tipp::getDayScoreLocal($roundtipps[$key]['results'][4],$roundtipps[$key]['results'][5],$roundtipps[$key]['tipps'][4],$roundtipps[$key]['tipps'][5],$roundtipps[$key]['joker'][2],$roundtipps[$key]['rankscore']);
|
||||
$dayScore4WithRankScore = Tipp::getDayScoreLocal($roundtipps[$key]['results'][6],$roundtipps[$key]['results'][7],$roundtipps[$key]['tipps'][6],$roundtipps[$key]['tipps'][7],$roundtipps[$key]['joker'][3],$roundtipps[$key]['rankscore']);
|
||||
|
||||
$totalDayScoreWithRankScore = Tipp::addDayScoreValues($dayScore1WithRankScore,$dayScore2WithRankScore);
|
||||
$totalDayScoreWithRankScore = Tipp::addDayScoreValues($totalDayScoreWithRankScore,$dayScore3WithRankScore);
|
||||
$totalDayScoreWithRankScore = Tipp::addDayScoreValues($totalDayScoreWithRankScore,$dayScore4WithRankScore);
|
||||
|
||||
$roundtipps[$key]['dayScoreWithRankScore'] = $totalDayScoreWithRankScore;
|
||||
$roundtipps[$key]['dayscore'] = Tipp::getDayScoreWithoutRankScore($totalDayScoreWithRankScore);
|
||||
if (!array_key_exists($round_id,$highestDayscores)) { $highestDayscores[$round_id] = 0;}
|
||||
if ($highestDayscores[$round_id] < $roundtipps[$key]['dayscore'] ) { $highestDayscores[$round_id]=$roundtipps[$key]['dayscore'];}
|
||||
|
||||
$totalRankScore += $roundtipps[$key]["rankscore"];
|
||||
$roundtipps[$key]['totalRankScore'] = $totalRankScore;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
// Sortier-Array nach Rang (nur für max_round_id)
|
||||
$userRankings = array();
|
||||
foreach ($user_ids as $user_id) {
|
||||
$key = $max_round_id."_".$user_id;
|
||||
array_push($userRankings, [$user_id , $roundtipps[$key]['totalRankScore']]);
|
||||
|
||||
}
|
||||
usort($userRankings,array($this, 'cmpRank'));
|
||||
|
||||
// Ranknr identifizieren, inkl, geteilter Rankplatzierungen nur für max_round_id notwendig, da der Rest ja gar nicht angezeigt wird
|
||||
$lastScore=-1;
|
||||
$lastrank=0;
|
||||
$current_list_position=0;
|
||||
foreach($userRankings as $userRank) {
|
||||
$user_id=$userRank[0];
|
||||
$totalRankScore=$userRank[1];
|
||||
|
||||
$key=$max_round_id."_".$user_id;
|
||||
$current_list_position+=1;
|
||||
if ($roundtipps[$key]["totalRankScore"]==$lastScore) {
|
||||
$roundtipps[$key]["rank"] = $lastrank;
|
||||
} else {
|
||||
$lastrank = $current_list_position;
|
||||
$roundtipps[$key]["rank"] = $current_list_position;
|
||||
$lastScore = $totalRankScore;
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////
|
||||
// START OF HURTFUL 6 PLACE RESTRICTION IF DAYSCORE WIN (exception: completely even scores)
|
||||
// If more than 6 DayScoreWinners: Restrict by dayscore (rank)
|
||||
// Compute highest dayscore
|
||||
|
||||
// Addition: no dayscorewinner && round_completed: Payout goes to next round
|
||||
$payouts = Quota::getPayouts($currentSeason->id);
|
||||
$totalDayWinPayout = 0;
|
||||
|
||||
foreach ($round_ids as $round_id) {
|
||||
$totalDayWinPayout += $payouts["tagessieg"];
|
||||
|
||||
$highestDayScore = $highestDayscores[$round_id];
|
||||
$usersWithHighestDayScore = array();
|
||||
$round_completed=false;
|
||||
|
||||
foreach ($user_ids as $user_id) {
|
||||
$round_completed = $roundtipps[$key]['round_completed']; // TODO: Separaten info array roundData erzeugen, der Rundenspezifische, SPielerübergreifende Infos enthält, so wie round_completed.
|
||||
$key = $round_id . "_" . $user_id;
|
||||
if ($roundtipps[$key]['dayscore'] == $highestDayScore && $roundtipps[$key]['round_completed'] && $highestDayScore>0 ) {
|
||||
array_push($usersWithHighestDayScore, [$user_id, $roundtipps[$key]['dayScoreWithRankScore']]);
|
||||
}
|
||||
}
|
||||
if (sizeof($usersWithHighestDayScore) > 6) {
|
||||
usort($usersWithHighestDayScore, array($this, 'cmpDayWin'));
|
||||
}
|
||||
$count = 0;
|
||||
$cutOffScore = 0;
|
||||
$dayScoreWinnersIds = array();
|
||||
foreach ($usersWithHighestDayScore as $user) { // Feld0: user_id, dayScoreWithRankScore
|
||||
$count += 1;
|
||||
if ($count > 6) {
|
||||
if ($user[1] < $cutOffScore) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
array_push($dayScoreWinnersIds, $user[0]);
|
||||
$key = $round_id . "_" . $user[0];
|
||||
$roundtipps[$key]['is_dayscorewinner'] = true;
|
||||
Log::info("Dayscorewinner Round " . $round_id . " = " . $roundtipps[$key]["user_name"]);
|
||||
$cutOffScore = $user[1];
|
||||
}
|
||||
|
||||
// Compute Dayscorewin payout (Tagessieg)
|
||||
$winnerCount = sizeof($dayScoreWinnersIds);
|
||||
$single_payout=0;
|
||||
if ($winnerCount > 0) {
|
||||
$single_payout = $totalDayWinPayout / $winnerCount;
|
||||
$single_payout = number_format((float)$single_payout, 2, '.', '');
|
||||
$single_payout = str_replace(".", ",", $single_payout);
|
||||
$totalDayWinPayout=0;
|
||||
}
|
||||
|
||||
foreach ($user_ids as $user_id) {
|
||||
$key = $round_id . "_" . $user_id;
|
||||
if ($roundtipps[$key]['is_dayscorewinner']) {
|
||||
$roundtipps[$key]['payout'] = $single_payout;
|
||||
|
||||
} else {
|
||||
$roundtipps[$key]['payout'] = '';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
//////////////////// END OF ROUNDTIPPS CREATION ///////////////////
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
$response = Tipp::getRoundTipps($max_round_id);
|
||||
$roundtipps = $response['roundtipps'];
|
||||
$roundData = $response['roundData'];
|
||||
$user_ids = $response['user_ids'];
|
||||
$round_ids = $response['round_ids'];
|
||||
|
||||
|
||||
|
||||
|
|
@ -429,10 +241,9 @@ class UsersController extends Controller
|
|||
$rankingDisplay[$user_id]["is_dayscorewinner"] = $roundtipps[$key]["is_dayscorewinner"];
|
||||
|
||||
if ($round_id==4 && $roundtipps[$key]["is_dayscorewinner"]) {
|
||||
Log::info("Dayscorewinner: ".$roundtipps[$key]["user_name"]);
|
||||
//Log::info("Dayscorewinner: ".$roundtipps[$key]["user_name"]);
|
||||
}
|
||||
|
||||
if ($user_id==1) { Log::info("rankscore after user init for display round_id ".$round_id." = ".$roundtipps[$key]["rankscore"]);}
|
||||
$rankingDisplay[$user_id]["rankscore"] = $roundtipps[$key]["rankscore"]; // Summe Rangwertung alle 4 Spiele/Tipps der letzten durchlaufenen Runde, NICHT in init stellen !!
|
||||
$rankingDisplay[$user_id]["dayscore"] = $roundtipps[$key]["dayscore"]; // Dayscore der letzten durchlaufenen Runde, NICHT in init stellen !!
|
||||
$rankingDisplay[$user_id]["dayScoreWithRankScore"] = $roundtipps[$key]["dayScoreWithRankScore"]; // Dayscore der letzten durchlaufenen Runde, NICHT in init stellen !!
|
||||
|
|
@ -505,9 +316,10 @@ class UsersController extends Controller
|
|||
// von Rankingdisplay abgespeichert sind.
|
||||
|
||||
$game_results=array(); // 4 Spielergebnisse der angezeigten Runde
|
||||
$a=$rankingDisplay[0];
|
||||
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'));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -32,11 +32,11 @@ class Quota extends Model
|
|||
$euro_platzierung = intval ( $euro_pott * (($quotas["Platzierung"] / 100)));
|
||||
$tagessieg_rest = $euro_tagessieg_sum - ($euro_tagessieg * $quotas['Runden']);
|
||||
|
||||
Log::info("Tagessieg Rest=".$tagessieg_rest." €");
|
||||
//Log::info("Tagessieg Rest=".$tagessieg_rest." €");
|
||||
$euro_platzierung += $tagessieg_rest;
|
||||
|
||||
$euro_platz1 = Quota::get6Divisor(intval( $euro_platzierung * (( $quotas["Platz 1"] / 100))));
|
||||
Log::info("Platz 1=".$euro_platz1);
|
||||
//Log::info("Platz 1=".$euro_platz1);
|
||||
$euro_platz2 = Quota::get6Divisor(intval( $euro_platzierung * (( $quotas["Platz 2"] / 100))));
|
||||
$euro_platz3 = Quota::get6Divisor(intval( $euro_platzierung * (( $quotas["Platz 3"] / 100))));
|
||||
$euro_platz4 = Quota::get6Divisor(intval( $euro_platzierung * (( $quotas["Platz 4"] / 100))));
|
||||
|
|
@ -58,7 +58,7 @@ class Quota extends Model
|
|||
+ $euro_liga_platz1 + $euro_liga_platz2 + $euro_liga_platz3);
|
||||
|
||||
$euro_platz1 = $euro_platz1 + $finaler_rest;
|
||||
Log::info("PLatz 1 mit Rest(".$finaler_rest.") = ".$euro_platz1);
|
||||
//Log::info("PLatz 1 mit Rest(".$finaler_rest.") = ".$euro_platz1);
|
||||
|
||||
$payouts=array();
|
||||
$payouts['tagessieg'] = $euro_tagessieg;
|
||||
|
|
|
|||
|
|
@ -240,4 +240,227 @@ class Tipp extends Model
|
|||
if ($gameVal==0) return 0;
|
||||
return $gameVal * 1000 + $jokerVal * 100;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// TODO: Implement partial caching
|
||||
public static function getRoundTipps($max_round_id) {
|
||||
$startTime = microtime(true);
|
||||
|
||||
$currentSeason = Season::getCurrent();
|
||||
|
||||
// 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.
|
||||
$sql = "select users.id as user_id, users.name as user_name, ";
|
||||
$sql = $sql . "rounds.id as round_id, rounds.name as round_name, ";
|
||||
$sql = $sql . "games.id as game_id, games.team1, games.team2, games.score1 as game_score1, games.score2 as game_score2, games.kickoff as game_kickoff, ";
|
||||
$sql = $sql . "tipps.id as tipp_id, tipps.score1 as tipp_score1, tipps.score2 as tipp_score2, tipps.joker ";
|
||||
$sql = $sql . "from users,rounds,games,tipps,payments ";
|
||||
$sql = $sql . "where rounds.season_id=".$currentSeason->id." ";
|
||||
$sql = $sql . "and games.round_id=rounds.id and tipps.game_id=games.id and users.id = tipps.user_id ";
|
||||
$sql = $sql . "and payments.season_id=".$currentSeason->id." and payments.user_id = users.id ";
|
||||
$sql = $sql . "and payments.paid_date is not null ";
|
||||
$sql = $sql . "and users.deleted is null ";
|
||||
$sql = $sql . "order by rounds.id, games.id, users.id;";
|
||||
|
||||
$result=DB::select($sql);
|
||||
|
||||
$roundtipps = array();
|
||||
$roundData = array();
|
||||
$user_ids=array();
|
||||
$round_ids=array();
|
||||
|
||||
// Write sql result to roundtipps (score per round & user)
|
||||
if ($max_round_id==-1) { $max_round_id=Round::getLastLockedRoundId(); }
|
||||
foreach ($result as $entry) {
|
||||
$round_id = $entry->round_id;
|
||||
if ($max_round_id >-1 && $round_id>$max_round_id) break;
|
||||
|
||||
if (!in_array($entry->user_id,$user_ids)) { array_push($user_ids,$entry->user_id); }
|
||||
if (!in_array($entry->round_id,$round_ids)) { array_push($round_ids,$entry->round_id); }
|
||||
if (!in_array($round_id,$roundData)) { $roundData[$round_id]=array(); }
|
||||
|
||||
$user_id = $entry->user_id;
|
||||
|
||||
$key = $round_id."_".$user_id;
|
||||
if (!array_key_exists($key,$roundtipps)) {
|
||||
$roundtipps[$key]=array();
|
||||
$roundtipps[$key]['tipps']=array();
|
||||
$roundtipps[$key]['results']=array();
|
||||
$roundtipps[$key]['joker']=array();
|
||||
$roundtipps[$key]['round_completed']=true;
|
||||
$roundtipps[$key]['user_name'] = $entry->user_name;
|
||||
$roundtipps[$key]['user_id'] = $entry->user_id;
|
||||
$roundtipps[$key]['rankscore']=0;
|
||||
$roundtipps[$key]['payout']=0;
|
||||
$roundtipps[$key]['earliest_kickoff']=$entry->game_kickoff;
|
||||
$roundtipps[$key]['hits']=0; // Wenigstens Tendenz getroffen. Wenn 4, dann 2 Punkte Bonus auf rankscore
|
||||
$roundtipps[$key]['is_dayscorewinner']=0;
|
||||
}
|
||||
if (!array_key_exists('is_completed',$roundData[$round_id])) {
|
||||
$roundData[$round_id]['is_completed'] = true;
|
||||
}
|
||||
|
||||
$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
|
||||
|
||||
if ($entry->game_score1==-1 || $entry->game_score2==-1) {
|
||||
$roundtipps[$key]['round_completed'] = false; // TODO: Remove it, its succeeded by roundData['is_completed']
|
||||
$rounds[$round_id]['is_completed'] = false;
|
||||
}
|
||||
|
||||
array_push($roundtipps[$key]['tipps'],$entry->tipp_score1);
|
||||
array_push($roundtipps[$key]['tipps'],$entry->tipp_score2);
|
||||
array_push($roundtipps[$key]['results'],$entry->game_score1);
|
||||
array_push($roundtipps[$key]['results'],$entry->game_score2);
|
||||
array_push($roundtipps[$key]['joker'],$entry->joker);
|
||||
|
||||
if ( $entry->game_kickoff < $roundtipps[$key]['earliest_kickoff'] ) { $roundtipps[$key]['earliest_kickoff'] = $entry->game_kickoff; }
|
||||
}
|
||||
// NOW ALL KEYS FOR ROUNDTIPPS (ROUND & USER) EXIST
|
||||
|
||||
// CALCULATION OF SCORES, RANKS, ETC. (COMPUTE AGGREGATED VALUES)
|
||||
|
||||
$highestDayscores=array();
|
||||
foreach($user_ids as $user_id) {
|
||||
$totalRankScore=0;
|
||||
foreach($round_ids as $round_id) {
|
||||
|
||||
|
||||
$key=$round_id."_".$user_id;
|
||||
|
||||
// Compute Dayscore values
|
||||
$dayScore1WithRankScore = Tipp::getDayScoreLocal($roundtipps[$key]['results'][0],$roundtipps[$key]['results'][1],$roundtipps[$key]['tipps'][0],$roundtipps[$key]['tipps'][1],$roundtipps[$key]['joker'][0],$roundtipps[$key]['rankscore']);
|
||||
$dayScore2WithRankScore = Tipp::getDayScoreLocal($roundtipps[$key]['results'][2],$roundtipps[$key]['results'][3],$roundtipps[$key]['tipps'][2],$roundtipps[$key]['tipps'][3],$roundtipps[$key]['joker'][1],$roundtipps[$key]['rankscore']);
|
||||
$dayScore3WithRankScore = Tipp::getDayScoreLocal($roundtipps[$key]['results'][4],$roundtipps[$key]['results'][5],$roundtipps[$key]['tipps'][4],$roundtipps[$key]['tipps'][5],$roundtipps[$key]['joker'][2],$roundtipps[$key]['rankscore']);
|
||||
$dayScore4WithRankScore = Tipp::getDayScoreLocal($roundtipps[$key]['results'][6],$roundtipps[$key]['results'][7],$roundtipps[$key]['tipps'][6],$roundtipps[$key]['tipps'][7],$roundtipps[$key]['joker'][3],$roundtipps[$key]['rankscore']);
|
||||
|
||||
$totalDayScoreWithRankScore = Tipp::addDayScoreValues($dayScore1WithRankScore,$dayScore2WithRankScore);
|
||||
$totalDayScoreWithRankScore = Tipp::addDayScoreValues($totalDayScoreWithRankScore,$dayScore3WithRankScore);
|
||||
$totalDayScoreWithRankScore = Tipp::addDayScoreValues($totalDayScoreWithRankScore,$dayScore4WithRankScore);
|
||||
|
||||
$roundtipps[$key]['dayScoreWithRankScore'] = $totalDayScoreWithRankScore;
|
||||
$roundtipps[$key]['dayscore'] = Tipp::getDayScoreWithoutRankScore($totalDayScoreWithRankScore);
|
||||
if (!array_key_exists($round_id,$highestDayscores)) { $highestDayscores[$round_id] = 0;}
|
||||
if ($highestDayscores[$round_id] < $roundtipps[$key]['dayscore'] ) { $highestDayscores[$round_id]=$roundtipps[$key]['dayscore'];}
|
||||
|
||||
$totalRankScore += $roundtipps[$key]["rankscore"];
|
||||
$roundtipps[$key]['totalRankScore'] = $totalRankScore;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
// Sortier-Array nach Rang (nur für max_round_id)
|
||||
$userRankings = array();
|
||||
foreach ($user_ids as $user_id) {
|
||||
$key = $max_round_id."_".$user_id;
|
||||
array_push($userRankings, [$user_id , $roundtipps[$key]['totalRankScore']]);
|
||||
|
||||
}
|
||||
usort($userRankings, array('App\Tipp','cmpRank'));
|
||||
|
||||
// Ranknr identifizieren, inkl, geteilter Rankplatzierungen nur für max_round_id notwendig, da der Rest ja gar nicht angezeigt wird
|
||||
$lastScore=-1;
|
||||
$lastrank=0;
|
||||
$current_list_position=0;
|
||||
foreach($userRankings as $userRank) {
|
||||
$user_id=$userRank[0];
|
||||
$totalRankScore=$userRank[1];
|
||||
|
||||
$key=$max_round_id."_".$user_id;
|
||||
$current_list_position+=1;
|
||||
if ($roundtipps[$key]["totalRankScore"]==$lastScore) {
|
||||
$roundtipps[$key]["rank"] = $lastrank;
|
||||
} else {
|
||||
$lastrank = $current_list_position;
|
||||
$roundtipps[$key]["rank"] = $current_list_position;
|
||||
$lastScore = $totalRankScore;
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////
|
||||
// START OF HURTFUL 6 PLACE RESTRICTION IF DAYSCORE WIN (exception: completely even scores)
|
||||
// If more than 6 DayScoreWinners: Restrict by dayscore (rank)
|
||||
// Compute highest dayscore
|
||||
|
||||
// Addition: no dayscorewinner && round_completed: Payout goes to next round
|
||||
$payouts = Quota::getPayouts($currentSeason->id);
|
||||
$totalDayWinPayout = 0;
|
||||
|
||||
foreach ($round_ids as $round_id) {
|
||||
$totalDayWinPayout += $payouts["tagessieg"];
|
||||
|
||||
$highestDayScore = $highestDayscores[$round_id];
|
||||
$usersWithHighestDayScore = array();
|
||||
$round_completed=false;
|
||||
|
||||
foreach ($user_ids as $user_id) {
|
||||
$round_completed = $roundtipps[$key]['round_completed']; // TODO: Separaten info array roundData erzeugen, der Rundenspezifische, SPielerübergreifende Infos enthält, so wie round_completed.
|
||||
$key = $round_id . "_" . $user_id;
|
||||
if ($roundtipps[$key]['dayscore'] == $highestDayScore && $roundtipps[$key]['round_completed'] && $highestDayScore>0 ) {
|
||||
array_push($usersWithHighestDayScore, [$user_id, $roundtipps[$key]['dayScoreWithRankScore']]);
|
||||
}
|
||||
}
|
||||
if (sizeof($usersWithHighestDayScore) > 6) {
|
||||
usort($usersWithHighestDayScore, 'cmpDayWin');
|
||||
}
|
||||
$count = 0;
|
||||
$cutOffScore = 0;
|
||||
$dayScoreWinnersIds = array();
|
||||
foreach ($usersWithHighestDayScore as $user) { // Feld0: user_id, dayScoreWithRankScore
|
||||
$count += 1;
|
||||
if ($count > 6) {
|
||||
if ($user[1] < $cutOffScore) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
array_push($dayScoreWinnersIds, $user[0]);
|
||||
$key = $round_id . "_" . $user[0];
|
||||
$roundtipps[$key]['is_dayscorewinner'] = true;
|
||||
//Log::info("Dayscorewinner Round " . $round_id . " = " . $roundtipps[$key]["user_name"]);
|
||||
$cutOffScore = $user[1];
|
||||
}
|
||||
|
||||
// Compute Dayscorewin payout (Tagessieg)
|
||||
$winnerCount = sizeof($dayScoreWinnersIds);
|
||||
$single_payout=0;
|
||||
if ($winnerCount > 0) {
|
||||
$single_payout = $totalDayWinPayout / $winnerCount;
|
||||
$single_payout = number_format((float)$single_payout, 2, '.', '');
|
||||
$single_payout = str_replace(".", ",", $single_payout);
|
||||
$totalDayWinPayout=0;
|
||||
}
|
||||
|
||||
foreach ($user_ids as $user_id) {
|
||||
$key = $round_id . "_" . $user_id;
|
||||
if ($roundtipps[$key]['is_dayscorewinner']) {
|
||||
$roundtipps[$key]['payout'] = $single_payout;
|
||||
|
||||
} else {
|
||||
$roundtipps[$key]['payout'] = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
//////////////////// END OF ROUNDTIPPS CREATION ///////////////////
|
||||
|
||||
$response = array();
|
||||
$response['roundtipps'] = $roundtipps;
|
||||
$response['roundData'] = $roundData;
|
||||
$response['user_ids'] = $user_ids;
|
||||
$response['round_ids'] = $round_ids;
|
||||
|
||||
Log::info("Tipp::getRoundTipps: ExecutionTime: " . number_format(( microtime(true) - $startTime), 4) . " Seconds\n");
|
||||
return $response;
|
||||
}
|
||||
|
||||
// Used by getRoundTipps method
|
||||
public static function cmpRank($rank1, $rank2) {
|
||||
return ($rank1[1] < $rank2[1]); //Feld0: user_id, Feld1: rank
|
||||
}
|
||||
// Used by getRoundTipps method
|
||||
public static function cmpDayWin($user1, $user2) {
|
||||
return ($user1[1] < $user2[1]); // Feld0: user_id, Feld1: dayScoreWithRankScore
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
@section('content')
|
||||
<section class="jumbotron text-center">
|
||||
@if(Auth::check())
|
||||
@if($hourDiffToLock<49)
|
||||
@if (strlen($message_text_tipps)>0)
|
||||
<div><p class="blink_text">{{ $message_text_tipps }}</p></div>
|
||||
|
|
@ -13,6 +14,7 @@
|
|||
<div><p class="blink_text">{{ $nextRoundName }} sperrt sich: {{ $nextRoundLockTime }} ( noch {{ $hourDiffToLock }} Stunden )</p></div>
|
||||
@endif
|
||||
@endif
|
||||
@endif
|
||||
<div class="container">
|
||||
<h1 class="jumbotron-heading">Hoschis Tippspiel</h1>
|
||||
<p class="lead text-muted">Eine Tippgemeinschaft unter Freunden.</p>
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
@if ($r->id == $round->id)
|
||||
<label>{{$r->name}}</label>
|
||||
@else
|
||||
<a href="/users/ranking/roundid_{{$r->id}}/playerid_{{Auth::user()->id}}">{{$r->name}}</a>
|
||||
<a href="/users/ranking/roundid_{{$r->id}}#playerid_{{Auth::user()->id}}">{{$r->name}}</a>
|
||||
@endif
|
||||
</div>
|
||||
@endif
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ $baseDir = dirname($vendorDir);
|
|||
|
||||
return array(
|
||||
'AddReminderfieldToUsers' => $baseDir . '/database/migrations/2017_08_28_110358_add_reminderfield_to_users.php',
|
||||
'AddRoundCountToSeasonsTable' => $baseDir . '/database/migrations/2017_08_30_102708_add_round_count_to_seasons_table.php',
|
||||
'App\\Console\\Kernel' => $baseDir . '/app/Console/Kernel.php',
|
||||
'App\\Exceptions\\Handler' => $baseDir . '/app/Exceptions/Handler.php',
|
||||
'App\\Game' => $baseDir . '/app/Game.php',
|
||||
|
|
|
|||
1
pfosten/vendor/composer/autoload_static.php
vendored
1
pfosten/vendor/composer/autoload_static.php
vendored
|
|
@ -279,6 +279,7 @@ class ComposerStaticInita19fb0695e1b61b4feeb3cc3fbdd2feb
|
|||
|
||||
public static $classMap = array (
|
||||
'AddReminderfieldToUsers' => __DIR__ . '/../..' . '/database/migrations/2017_08_28_110358_add_reminderfield_to_users.php',
|
||||
'AddRoundCountToSeasonsTable' => __DIR__ . '/../..' . '/database/migrations/2017_08_30_102708_add_round_count_to_seasons_table.php',
|
||||
'App\\Console\\Kernel' => __DIR__ . '/../..' . '/app/Console/Kernel.php',
|
||||
'App\\Exceptions\\Handler' => __DIR__ . '/../..' . '/app/Exceptions/Handler.php',
|
||||
'App\\Game' => __DIR__ . '/../..' . '/app/Game.php',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue