Started working on cached ranking version (ranking2)
This commit is contained in:
parent
8c368524fe
commit
5b02895c86
5 changed files with 117 additions and 7 deletions
|
|
@ -150,7 +150,6 @@ class UsersController extends Controller
|
|||
|
||||
|
||||
foreach($games as $game) {
|
||||
if ($user->id==1) {Log::info("game-id=".$game->id.", user-id=".$user->id);}
|
||||
$tipp = Tipp::where([['game_id','=',$game->id],['user_id','=',$user->id]])->first();
|
||||
if ($tipp) {
|
||||
$score = Tipp::getDayScoreLocal($game->score1,$game->score2,$tipp->score1,$tipp->score2,$tipp->joker);
|
||||
|
|
@ -245,4 +244,102 @@ class UsersController extends Controller
|
|||
return ($user1->totalScore < $user2->totalScore);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public function ranking2($max_round_id) {
|
||||
$currentSeason = Season::getCurrent();
|
||||
|
||||
// Hier werden _alle_ Tipps der aktuellen Saison ausgerechnet, die $round_id Begrenzung wird erst später ausgewertet.
|
||||
$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, ";
|
||||
$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 . "order by rounds.id, games.id, users.id;";
|
||||
|
||||
$result=DB::select($sql);
|
||||
|
||||
$roundtipps = array();
|
||||
$user_ids=array();
|
||||
$round_ids=array();
|
||||
|
||||
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]['user_name'] = $entry->user_name;
|
||||
$roundtipps[$key]['user_id'] = $entry->user_id;
|
||||
|
||||
$roundtipps[$key]['rankscore']=Tipp::getScoreLocal($entry->game_score1,$entry->game_score2,$entry->tipp_score1,$entry->tipp_score2,$entry->joker);
|
||||
$roundtipps[$key]['dayscore']=Tipp::getDayScoreLocal($entry->game_score1,$entry->game_score2,$entry->tipp_score1,$entry->tipp_score2,$entry->joker);
|
||||
}
|
||||
|
||||
array_push($roundtipps[$key]['tipps'], $entry->tipp_score1, $entry->tipp_score2, $entry->joker);
|
||||
array_push($roundtipps[$key]['results'], $entry->game_score1, $entry->game_score2);
|
||||
}
|
||||
|
||||
//dd($roundtipps);
|
||||
//dd($user_ids);
|
||||
//dd($round_ids);
|
||||
|
||||
//Log::info($user_ids);
|
||||
//Log::info($round_ids);
|
||||
|
||||
// Aufbau der Rankingliste in rankingDisplay, sowie aufaddieren der jeweiligen Punkte.
|
||||
$rankingDisplay=array();
|
||||
foreach ($user_ids as $user_id) {
|
||||
$ranking_sum = 0;
|
||||
$payout_sum = 0;
|
||||
foreach($round_ids as $round_id) {
|
||||
$key = $round_id . "_" . $user_id;
|
||||
if (!array_key_exists($user_id, $rankingDisplay)) {
|
||||
$rankingDisplay[$user_id] = array();
|
||||
$rankingDisplay[$user_id]["rankscore"] = 0;
|
||||
$rankingDisplay[$user_id]["dayscore"] = 0;
|
||||
$rankingDisplay[$user_id]["user_name"] = $roundtipps[$key]["user_name"];
|
||||
}
|
||||
if (!array_key_exists("tipp_score1", $rankingDisplay[$user_id])) {
|
||||
$rankingDisplay[$user_id]["tipp_score1"] = $roundtipps[$key]["tipps"][0];
|
||||
$rankingDisplay[$user_id]["tipp_score2"] = $roundtipps[$key]["tipps"][1];
|
||||
// Determine coloration for Game1
|
||||
} elseif (!array_key_exists("tipp_score3", $rankingDisplay[$user_id])) {
|
||||
$rankingDisplay[$user_id]["tipp_score3"] = $roundtipps[$key]["tipps"][2];
|
||||
$rankingDisplay[$user_id]["tipp_score4"] = $roundtipps[$key]["tipps"][3];
|
||||
// Determine coloration for Game2
|
||||
} elseif (!array_key_exists("tipp_score5", $rankingDisplay[$user_id])) {
|
||||
$rankingDisplay[$user_id]["tipp_score5"] = $roundtipps[$key]["tipps"][4];
|
||||
$rankingDisplay[$user_id]["tipp_score6"] = $roundtipps[$key]["tipps"][5];
|
||||
// Determine coloration for Game3
|
||||
} elseif (!array_key_exists("tipp_score7", $rankingDisplay[$user_id])) {
|
||||
$rankingDisplay[$user_id]["tipp_score7"] = $roundtipps[$key]["tipps"][6];
|
||||
$rankingDisplay[$user_id]["tipp_score8"] = $roundtipps[$key]["tipps"][7];
|
||||
// Determine coloration for Game4
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue