ranking2(cached): Fixed rankcounting bug

This commit is contained in:
Torsten 2017-08-10 17:14:49 +02:00
parent 5b02895c86
commit d62b312eb0
3 changed files with 316 additions and 27 deletions

View file

@ -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'));
}

View file

@ -13,6 +13,32 @@ class Tipp extends Model
'id', 'user_id', 'game_id','score1','score2','joker'
];
public static function trendCol($score1, $score2, $tipp1, $tipp2, $joker) {
$tippTendenz = $tipp1 - $tipp2;
if ($tippTendenz > 0) {$tippTendenz=1;}
if ($tippTendenz < 0) {$tippTendenz=-1;}
$gameTendenz = $score1 - $score2;
if ($gameTendenz<0) {$gameTendenz=-1;}
if ($gameTendenz>0) {$gameTendenz=1;}
if ($tippTendenz!=$gameTendenz || $score1 ==-1 || $score2==-1 || $tipp1 == -1 || $tipp2==-1) {
return "";
}
$styling='background-color:grey;';
if ( ($tipp1 == $score1) && ($tipp2 == $score2) ) {
$styling='background-color:orange;';
if ($joker) {
$styling='background-color:red';
}
}
return $styling;
}
// get tendency Color
public static function getCol($user_id,$game_id) {
$tipp = Tipp::getTipp($user_id,$game_id);

View file

@ -0,0 +1,200 @@
@extends('layouts.layout')
@section('content')
<div style="float:left;left:10%">
@foreach($all_rounds as $r)
@if (App\Round::hasLockedGame($r->id) )
<div>
@if ($r->id == $round->id)
<label>{{$r->name}}</label>
@else
<a href="/users/ranking2/{{$r->id}}">{{$r->name}}</a>
@endif
</div>
@endif
@endforeach
</div>
<div style="float:left; position:relative;left:47%">
<div style="float:left; position:relative; left:-50%;">
<h3>Saison: {{ App\Season::getCurrent()->name }}</h3>
<h4>Runde: {{ $round->name }}</h4>
<h4>Rangliste und Tippübersicht</h4>
<table>
<tr>
<td style="width:50px;background-color:grey"></td>
<td style="width:250px;">=richtige Tendenz</td>
</tr>
<tr>
<td style="width:50px;background-color:orange"></td>
<td style="width:250px;">=richtiges Ergebnis</td>
</tr>
<tr>
<td style="width:50px;background-color:red"></td>
<td style="width:250px;">=richtiges Ergebnis mit Joker</td>
</tr>
</table>
<p>&nbsp;</p>
<table>
<th style="height:140px;white-space: nowrap;">
<div style="transform:translate(25px, 51px) rotate(315deg);width:30px;">
<span style="border-bottom: 1px solid #ccc; padding: 5px 10px;width:50px;">Rang</span>
</div>
</th>
<th style="height:140px;white-space: nowrap;">
<div style="transform:translate(25px, 51px) rotate(315deg);width:30px;">
<span style="border-bottom: 1px solid #ccc; padding: 5px 10px;width:50px;">Tagessieg</span>
</div>
</th>
<th style="height:140px;white-space: nowrap;">
<div style="transform:translate(25px, 51px) rotate(315deg);width:30px;">
<span style="border-bottom: 1px solid #ccc; padding: 5px 10px;width:150px;">Spieler</span>
</div>
</th>
<th style="height:140px;white-space: nowrap;">
<div style="transform:translate(25px, 51px) rotate(315deg);width:30px;">
<span style="border-bottom: 1px solid #ccc; padding: 5px 10px;">Punkte Gesamt</span>
</div>
</th>
<th style="height:140px;white-space: nowrap;">
<div style="transform:translate(25px, 51px) rotate(315deg);width:30px;">
<span style="border-bottom: 1px solid #ccc; padding: 5px 10px;">Punkte Tag</span>
</div>
</th>
<th style="height:140px;white-space: nowrap;">
<div style="transform:translate(25px, 51px) rotate(315deg);width:30px;">
<span style="border-bottom: 1px solid #ccc; padding: 5px 10px;">{{$games[0]->team1}}</span>
</div>
</th>
<th style="height:140px;white-space: nowrap;">
<div style="transform:translate(25px, 51px) rotate(315deg);width:30px;">
<span style="border-bottom: 1px solid #ccc; padding: 5px 10px;">{{$games[0]->team2}}</span>
</div>
</th>
<th style="height:140px;white-space: nowrap;">
<div style="transform:translate(25px, 51px) rotate(315deg);width:30px;">
<span style="border-bottom: 1px solid #ccc; padding: 5px 10px;">Joker</span>
</div>
</th>
<th style="height:140px;white-space: nowrap;">
<div style="transform:translate(25px, 51px) rotate(315deg);width:30px;">
<span style="border-bottom: 1px solid #ccc; padding: 5px 10px;">{{$games[1]->team1}}</span>
</div>
</th>
<th style="height:140px;white-space: nowrap;">
<div style="transform:translate(25px, 51px) rotate(315deg);width:30px;">
<span style="border-bottom: 1px solid #ccc; padding: 5px 10px;">{{$games[1]->team2}}</span>
</div>
</th>
<th style="height:140px;white-space: nowrap;">
<div style="transform:translate(25px, 51px) rotate(315deg);width:30px;">
<span style="border-bottom: 1px solid #ccc; padding: 5px 10px;">Joker</span>
</div>
</th>
<th style="height:140px;white-space: nowrap;">
<div style="transform:translate(25px, 51px) rotate(315deg);width:30px;">
<span style="border-bottom: 1px solid #ccc; padding: 5px 10px;">{{$games[2]->team1}}</span>
</div>
</th>
<th style="height:140px;white-space: nowrap;">
<div style="transform:translate(25px, 51px) rotate(315deg);width:30px;">
<span style="border-bottom: 1px solid #ccc; padding: 5px 10px;">{{$games[2]->team2}}</span>
</div>
</th>
<th style="height:140px;white-space: nowrap;">
<div style="transform:translate(25px, 51px) rotate(315deg);width:30px;">
<span style="border-bottom: 1px solid #ccc; padding: 5px 10px;">Joker</span>
</div>
</th>
<th style="height:140px;white-space: nowrap;">
<div style="transform:translate(25px, 51px) rotate(315deg);width:30px;">
<span style="border-bottom: 1px solid #ccc; padding: 5px 10px;">{{$games[3]->team1}}</span>
</div>
</th>
<th style="height:140px;white-space: nowrap;">
<div style="transform:translate(25px, 51px) rotate(315deg);width:30px;">
<span style="border-bottom: 1px solid #ccc; padding: 5px 10px;">{{$games[3]->team2}}</span>
</div>
</th>
<th style="height:140px;white-space: nowrap;">
<div style="transform:translate(25px, 51px) rotate(315deg);width:30px;">
<span style="border-bottom: 1px solid #ccc; padding: 5px 10px;">Joker</span>
</div>
</th>
@foreach($userids as $userid)
<tr>
<td class="table-bordered">&nbsp;<span class="text list-unstyled" href="#" >&nbsp;{{ $rankingDisplay[$userid]["rankscore"] }}&nbsp;</span></td>
<td class="table-bordered"><div style="margin: 0 auto; width: 32px;"><img src="/img/crown.png" style="{{ ($rankingDisplay[$userid]["is_dayscorewinner"] ? 'float:left;width:32px;height:32px' : 'display: none;') }}"></div></td>
<td class="table-bordered">&nbsp;<a class="text list-unstyled" href="#" style="vertical-align: middle;">{{ $rankingDisplay[$userid]["user_name"] }} &nbsp;</a></td>
<td class="table-bordered" align="center">&nbsp;{{ $rankingDisplay[$userid]["rankscore"] }}&nbsp;</td>
<td class="table-bordered" align="center">&nbsp;{{ $rankingDisplay[$userid]["dayscore"] }}&nbsp;</td>
<td class="table-bordered" align="center" style="{{$rankingDisplay[$userid]["trendCol1"]}}">&nbsp;{{ $rankingDisplay[$userid]["tipp_score1"] }}&nbsp;</td>
<td class="table-bordered" align="center" style="{{$rankingDisplay[$userid]["trendCol1"]}}">&nbsp;{{ $rankingDisplay[$userid]["tipp_score2"] }}&nbsp;</td>
<td class="table-bordered"><div style="margin: 0 auto; width: 32px;"><img src="/img/joker.png" style="{{ ($rankingDisplay[$userid]["joker1"] ? 'float:left;width:32px;height:32px' : 'display: none;') }}"></div></td>
<td class="table-bordered" align="center" style="{{$rankingDisplay[$userid]["trendCol2"]}}">&nbsp;{{$rankingDisplay[$userid]["tipp_score3"] }}&nbsp;</td>
<td class="table-bordered" align="center" style="{{$rankingDisplay[$userid]["trendCol2"]}}">&nbsp;{{$rankingDisplay[$userid]["tipp_score4"] }}&nbsp;</td>
<td class="table-bordered"><div style="margin: 0 auto; width: 32px;"><img src="/img/joker.png" style="{{ ($rankingDisplay[$userid]["joker2"]? 'float:left;width:32px;height:32px' : 'display: none;') }}"></div></td>
<td class="table-bordered" align="center" style="{{$rankingDisplay[$userid]["trendCol3"]}}">&nbsp;{{$rankingDisplay[$userid]["tipp_score5"] }}&nbsp;</td>
<td class="table-bordered" align="center" style="{{$rankingDisplay[$userid]["trendCol3"]}}">&nbsp;{{$rankingDisplay[$userid]["tipp_score6"] }}&nbsp;</td>
<td class="table-bordered"><div style="margin: 0 auto; width: 32px;"><img src="/img/joker.png" style="{{ ($rankingDisplay[$userid]["joker3"] ? 'float:left;width:32px;height:32px' : 'display: none;') }}"></div></td>
<td class="table-bordered" align="center" style="{{$rankingDisplay[$userid]["trendCol4"]}}">&nbsp;{{$rankingDisplay[$userid]["tipp_score7"] }}&nbsp;</td>
<td class="table-bordered" align="center" style="{{$rankingDisplay[$userid]["trendCol4"]}}">&nbsp;{{$rankingDisplay[$userid]["tipp_score8"] }}&nbsp;</td>
<td class="table-bordered"><div style="margin: 0 auto; width: 32px;"><img src="/img/joker.png" style="{{ ($rankingDisplay[$userid]["joker4"] ? 'float:left;width:32px;height:32px' : 'display: none;') }}"></div></td>
</tr>
@endforeach
<!-- Control Cell width -->
<tr>
<td> <div></div></td>
<td> <div></div></td>
<td style="width:50px;"> <div></div></td>
<td style="width:50px;"> <div></div></td>
<td style="width:50px;"> <div></div></td>
<td style="width:50px;"> <div></div></td>
<td style="width:50px;"> <div></div></td>
<td style="width:50px;"> <div></div></td>
<td style="width:50px;"> <div></div></td>
<td style="width:50px;"> <div></div></td>
<td style="width:50px;"> <div></div></td>
<td style="width:50px;"> <div></div></td>
<td style="width:50px;"> <div></div></td>
<td style="width:50px;"> <div></div></td>
<td style="width:50px;"> <div></div></td>
<td style="width:50px;"> <div></div></td>
</tr>
</table>
<p>&nbsp;</p>
</div>
</div>
@endsection