ranking2(cached): Fixed rankcounting bug
This commit is contained in:
parent
5b02895c86
commit
d62b312eb0
3 changed files with 316 additions and 27 deletions
|
|
@ -12,6 +12,7 @@ use App\Tipp;
|
|||
use DB;
|
||||
use Auth;
|
||||
use Log;
|
||||
use Carbon;
|
||||
|
||||
class UsersController extends Controller
|
||||
{
|
||||
|
|
@ -245,15 +246,31 @@ class UsersController extends Controller
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public function ranking2($max_round_id) {
|
||||
$currentSeason = Season::getCurrent();
|
||||
|
||||
|
||||
|
||||
// Check ob mindestens eine Runde der Saison gelockt ist angezeigt werden kann
|
||||
if($max_round_id==-1) {
|
||||
$max_round_id = Round::getLastLockedRoundId();
|
||||
if ($max_round_id==-1) {
|
||||
$sql="select DATE_FORMAT(date_sub(min(games.kickoff), interval 1 hour),'%d.%m.%Y %H:%i') as start_date from rounds,games where rounds.season_id=".$currentSeason->id." and games.round_id=rounds.id;";
|
||||
$date = DB::select($sql);
|
||||
|
||||
if (count($date)>0) {
|
||||
$start_date = $date[0]->start_date;
|
||||
return view('users.no_ranking', compact('start_date'));
|
||||
} else {
|
||||
return redirect("/");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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 . "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." ";
|
||||
|
|
@ -268,6 +285,8 @@ class UsersController extends Controller
|
|||
$user_ids=array();
|
||||
$round_ids=array();
|
||||
|
||||
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;
|
||||
|
|
@ -286,9 +305,14 @@ class UsersController extends Controller
|
|||
$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]['rankscore']=0;
|
||||
$roundtipps[$key]['dayscore']=Tipp::getDayScoreLocal($entry->game_score1,$entry->game_score2,$entry->tipp_score1,$entry->tipp_score2,$entry->joker);
|
||||
|
||||
$roundtipps[$key]['earliest_kickoff']=$entry->game_kickoff;
|
||||
}
|
||||
$roundtipps[$key]['rankscore']+=Tipp::getScoreLocal($entry->game_score1,$entry->game_score2,$entry->tipp_score1,$entry->tipp_score2,$entry->joker);
|
||||
|
||||
if ($entry->game_kickoff < $roundtipps[$key]['earliest_kickoff']) { $roundtipps[$key]['earliest_kickoff']=$entry->game_kickoff; }
|
||||
|
||||
array_push($roundtipps[$key]['tipps'], $entry->tipp_score1, $entry->tipp_score2, $entry->joker);
|
||||
array_push($roundtipps[$key]['results'], $entry->game_score1, $entry->game_score2);
|
||||
|
|
@ -301,43 +325,82 @@ class UsersController extends Controller
|
|||
//Log::info($user_ids);
|
||||
//Log::info($round_ids);
|
||||
|
||||
|
||||
Log::info("max_round_id=".$max_round_id);
|
||||
|
||||
// Aufbau der Rankingliste in rankingDisplay, sowie aufaddieren der jeweiligen Punkte.
|
||||
$rankingDisplay=array();
|
||||
foreach ($user_ids as $user_id) {
|
||||
$ranking_sum = 0;
|
||||
$rankscore_total= 0;
|
||||
$payout_sum = 0;
|
||||
|
||||
foreach($round_ids as $round_id) {
|
||||
$key = $round_id . "_" . $user_id;
|
||||
if ($user_id==1) { Log::info("Processing round: ".$round_id);}
|
||||
if (!array_key_exists($user_id, $rankingDisplay)) {
|
||||
$rankingDisplay[$user_id] = array();
|
||||
$rankingDisplay[$user_id]["rankscore"] = 0;
|
||||
|
||||
/*
|
||||
if ($user_id==1) {
|
||||
Log::info("round_id=".$round_id.", rankscore from var=".$roundtipps[$key]["rankscore"]. ", old_total=" .$rankscore_total);
|
||||
}
|
||||
*/
|
||||
|
||||
$rankingDisplay[$user_id]["dayscore"] = 0;
|
||||
$rankingDisplay[$user_id]["user_name"] = $roundtipps[$key]["user_name"];
|
||||
$rankingDisplay[$user_id]["is_dayscorewinner"] = 0;
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
$rankingDisplay[$user_id]["rankscore"] = $rankscore_total + $roundtipps[$key]["rankscore"]; $rankscore_total=$rankingDisplay[$user_id]["rankscore"];
|
||||
|
||||
$rankingDisplay[$user_id]["tipp_score1"] = $roundtipps[$key]["tipps"][0];
|
||||
$rankingDisplay[$user_id]["tipp_score2"] = $roundtipps[$key]["tipps"][1];
|
||||
$rankingDisplay[$user_id]["joker1"] = $roundtipps[$key]["tipps"][2];
|
||||
|
||||
$rankingDisplay[$user_id]["result_score1"] =
|
||||
$rankingDisplay[$user_id]["result_score2"] = $roundtipps[$key]["results"][1];
|
||||
|
||||
// Determine coloration for Game1
|
||||
$rankingDisplay[$user_id]["trendCol1"] = Tipp::trendCol($roundtipps[$key]["results"][0],$roundtipps[$key]["results"][1],
|
||||
$roundtipps[$key]["tipps"][0],$roundtipps[$key]["tipps"][1],
|
||||
$roundtipps[$key]["tipps"][2]);
|
||||
|
||||
|
||||
$rankingDisplay[$user_id]["tipp_score3"] = $roundtipps[$key]["tipps"][3];
|
||||
$rankingDisplay[$user_id]["tipp_score4"] = $roundtipps[$key]["tipps"][4];
|
||||
$rankingDisplay[$user_id]["joker2"] = $roundtipps[$key]["tipps"][5];
|
||||
// Determine coloration for Game2
|
||||
$rankingDisplay[$user_id]["trendCol2"] = Tipp::trendCol($roundtipps[$key]["results"][2],$roundtipps[$key]["results"][3],
|
||||
$roundtipps[$key]["tipps"][3],$roundtipps[$key]["tipps"][4],
|
||||
$roundtipps[$key]["tipps"][5]);
|
||||
|
||||
$rankingDisplay[$user_id]["tipp_score5"] = $roundtipps[$key]["tipps"][6];
|
||||
$rankingDisplay[$user_id]["tipp_score6"] = $roundtipps[$key]["tipps"][7];
|
||||
$rankingDisplay[$user_id]["joker3"] = $roundtipps[$key]["tipps"][8];
|
||||
// Determine coloration for Game3
|
||||
$rankingDisplay[$user_id]["trendCol3"] = Tipp::trendCol($roundtipps[$key]["results"][4],$roundtipps[$key]["results"][5],
|
||||
$roundtipps[$key]["tipps"][6],$roundtipps[$key]["tipps"][7],
|
||||
$roundtipps[$key]["tipps"][8]);
|
||||
|
||||
$rankingDisplay[$user_id]["tipp_score7"] = $roundtipps[$key]["tipps"][9];
|
||||
$rankingDisplay[$user_id]["tipp_score8"] = $roundtipps[$key]["tipps"][10];
|
||||
$rankingDisplay[$user_id]["joker4"] = $roundtipps[$key]["tipps"][11];
|
||||
// Determine coloration for Game4
|
||||
$rankingDisplay[$user_id]["trendCol4"] = Tipp::trendCol($roundtipps[$key]["results"][6],$roundtipps[$key]["results"][7],
|
||||
$roundtipps[$key]["tipps"][9],$roundtipps[$key]["tipps"][10],
|
||||
$roundtipps[$key]["tipps"][11]);
|
||||
|
||||
}
|
||||
|
||||
//TODO: Loop: Determine DayScoreWinner, Rank (multiple identical possible), Sort rankingDisplay array
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
$userids = array_keys($rankingDisplay);
|
||||
$round=Round::where('id','=',$max_round_id)->first();
|
||||
$games=Game::where('round_id','=',$max_round_id)->get();
|
||||
$all_rounds=Round::where('season_id','=',$currentSeason->id)->get();
|
||||
return view('users.ranking2', compact('all_rounds','rankingDisplay','userids','round','games'));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue