working on gshirt
This commit is contained in:
parent
86803fa23a
commit
0cef6e7747
1 changed files with 156 additions and 96 deletions
|
|
@ -245,7 +245,8 @@ class Tipp extends Model
|
|||
|
||||
|
||||
// TODO: Implement partial caching
|
||||
public static function getRoundTipps($max_round_id=-1, $seasonId=-1) {
|
||||
public static function getRoundTipps($max_round_id=-1, $seasonId=-1)
|
||||
{
|
||||
$currentSeason = null;
|
||||
if ($seasonId == null) {
|
||||
$currentSeason = Season::getCurrent();
|
||||
|
|
@ -256,7 +257,9 @@ class Tipp extends Model
|
|||
$startTime = microtime(true);
|
||||
|
||||
$currentSeason = Season::getCurrent();
|
||||
if ($seasonId!=-1) { $currentSeason=Season::where('id','=',$seasonId)->first(); };
|
||||
if ($seasonId != -1) {
|
||||
$currentSeason = Season::where('id', '=', $seasonId)->first();
|
||||
};
|
||||
|
||||
// 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.
|
||||
|
|
@ -279,14 +282,22 @@ class Tipp extends Model
|
|||
$round_ids = array();
|
||||
|
||||
// Write sql result to roundtipps (score per round & user)
|
||||
if ($max_round_id==-1) { $max_round_id=Round::getLastCompleteRoundId($currentSeason->id); }
|
||||
if ($max_round_id == -1) {
|
||||
$max_round_id = Round::getLastCompleteRoundId($currentSeason->id);
|
||||
}
|
||||
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(); }
|
||||
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;
|
||||
|
||||
|
|
@ -315,8 +326,12 @@ class Tipp extends Model
|
|||
$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 ($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']
|
||||
|
|
@ -329,14 +344,13 @@ class Tipp extends Model
|
|||
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; }
|
||||
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) EXCEPT GREENSHIRT, ARGH !!
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -358,8 +372,12 @@ class Tipp extends Model
|
|||
|
||||
$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'];}
|
||||
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;
|
||||
|
|
@ -372,7 +390,6 @@ class Tipp extends Model
|
|||
$userRankings = array();
|
||||
foreach ($user_ids as $user_id) {
|
||||
$key = $max_round_id . "_" . $user_id;
|
||||
//error_log("Pushing:". $user_id." => ".$key);
|
||||
array_push($userRankings, [$user_id, $roundtipps[$key]['totalRankScore']]);
|
||||
}
|
||||
usort($userRankings, array('App\Tipp', 'cmpRank'));
|
||||
|
|
@ -384,9 +401,7 @@ class Tipp extends Model
|
|||
foreach ($userRankings as $userRank) {
|
||||
$user_id = $userRank[0];
|
||||
$totalRankScore = $userRank[1];
|
||||
|
||||
foreach($round_ids as $round_id) {
|
||||
$key = $round_id . "_" . $user_id;
|
||||
$key = $max_round_id . "_" . $user_id;
|
||||
$current_list_position += 1;
|
||||
if ($roundtipps[$key]["totalRankScore"] == $lastScore) {
|
||||
$roundtipps[$key]["rank"] = $lastrank;
|
||||
|
|
@ -396,7 +411,42 @@ class Tipp extends Model
|
|||
$lastScore = $totalRankScore;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
// Sortier-Array für GShirt nach rankscore des Tages (für jede round_id)
|
||||
|
||||
foreach ($round_ids as $round_id) {
|
||||
$userRankings = array();
|
||||
foreach ($user_ids as $user_id) {
|
||||
$key = $round_id . "_" . $user_id;
|
||||
array_push($userRankings, [$user_id, $roundtipps[$key]['rankscore']]);
|
||||
}
|
||||
usort($userRankings, array('App\Tipp', 'cmpRank'));
|
||||
|
||||
// Ranknr identifizieren, inkl, geteilter Rankplatzierungen
|
||||
$lastScore = -1;
|
||||
$lastGrank = 0;
|
||||
$current_list_position = 0;
|
||||
foreach ($userRankings as $userRank) {
|
||||
$user_id = $userRank[0];
|
||||
$totalRankScore = $userRank[1];
|
||||
$key = $round_id . "_" . $user_id;
|
||||
$current_list_position += 1;
|
||||
if ($roundtipps[$key]["rankscore"] == $lastScore) {
|
||||
$roundtipps[$key]["grank"] = $lastGrank;
|
||||
} else {
|
||||
$lastGrank = $current_list_position;
|
||||
$roundtipps[$key]["grank"] = $current_list_position;
|
||||
$lastScore = $totalRankScore;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
// Greenshirt Score Determination
|
||||
|
|
@ -421,32 +471,38 @@ class Tipp extends Model
|
|||
foreach($user_ids as $user_id) {
|
||||
$key=$round_id."_".$user_id;
|
||||
|
||||
$rank=$roundtipps[$key]["rank"];
|
||||
if(!array_key_exists($rank, $members)) {
|
||||
$members[$rank]=0;
|
||||
$grank=$roundtipps[$key]["grank"];
|
||||
if(!array_key_exists($grank, $members)) {
|
||||
$members[$grank]=0;
|
||||
}
|
||||
$members[$rank]+=1;
|
||||
$members[$grank]+=1;
|
||||
}
|
||||
// A-2 compute gain
|
||||
$scoreGain=[0,10,5,3,2,1]; // Rank 0 existiert nicht
|
||||
|
||||
// Move gain out of empty ranks into the upper ones.
|
||||
foreach ([5,4,3,2,1] as $rank) {
|
||||
if (!array_key_exists($rank,$members)) {
|
||||
$scoreGain[$rank-1]+= $scoreGain[$rank];
|
||||
$scoreGain[$rank]=0; // Shouldnt be needed, but makes movement of gain explicit
|
||||
foreach ([5,4,3,2,1] as $grank) {
|
||||
if (!array_key_exists($grank,$members)) {
|
||||
$scoreGain[$grank-1]+= $scoreGain[$grank];
|
||||
$scoreGain[$grank]=0; // Shouldnt be needed, but makes movement of gain explicit
|
||||
}
|
||||
}
|
||||
|
||||
// Distribute gain
|
||||
foreach($user_ids as $user_id) {
|
||||
$key = $round_id . "_" . $user_id;
|
||||
$rank= $roundtipps[$key]["rank"];
|
||||
if ($rank<=5) {
|
||||
$roundtipps[$key]["gshirt_score"] = $scoreGain[$rank] / $members[$rank];
|
||||
$grank= $roundtipps[$key]["grank"];
|
||||
if ($grank<=5) {
|
||||
$gain = round($scoreGain[$grank] / $members[$grank], 2);
|
||||
$roundtipps[$key]["gshirt_score"] = $gain;
|
||||
} else {
|
||||
$roundtipps[$key]["gshirt_score"]=0;
|
||||
}
|
||||
|
||||
if ($user_id==11) {
|
||||
Log::info("round_id ".$round_id." grank=".$grank.", gshirt_score= ".$roundtipps[$key]["gshirt_score"]);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -455,7 +511,7 @@ class Tipp extends Model
|
|||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
foreach($user_ids as $user_id) {
|
||||
foreach($round_ids as $round_id) {
|
||||
$key=$round_id."_".$user_id;
|
||||
|
|
@ -463,14 +519,16 @@ foreach($user_ids as $user_id) {
|
|||
$roundtipps[$key]['gshirt_foulcount']=-1;
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
/* FIND BUG !
|
||||
*/
|
||||
foreach($user_ids as $user_id) {
|
||||
$foulCount=0;
|
||||
$totalScore=0;
|
||||
foreach ($round_ids as $round_id) {
|
||||
$key = $round_id . "_" . $user_id;
|
||||
|
||||
$score = $roundtipps[$key]['gshirt_score'];
|
||||
$isFoul = ( $roundtipps[$key]["rankscore"] == 0 );
|
||||
if ($isFoul) {
|
||||
|
|
@ -484,16 +542,18 @@ foreach($user_ids as $user_id) {
|
|||
$roundtipps[$key]['gshirt_totalscore']=$totalScore;
|
||||
$roundtipps[$key]['gshirt_foulcount']=$foulCount;
|
||||
|
||||
if ($user_id==14) {
|
||||
error_log("round_id=" . $round_id .",gshirt_score=".$roundtipps[$key]['gshirt_score'].", score=" . $score.", totalScore=".$totalScore);
|
||||
if ($user_id==11) {
|
||||
//error_log("round_id=" . $round_id .",gshirt_score=".$roundtipps[$key]['gshirt_score'].", score=" . $score.", totalScore=".$totalScore);
|
||||
Log::info("round_id=" . $round_id .",gshirt_score=".$roundtipps[$key]['gshirt_score'].", score=" . $score.", totalScore=".$totalScore);
|
||||
}
|
||||
|
||||
error_log("Test: key=".$key.", ".$roundtipps[$key]['gshirt_score']);
|
||||
//error_log("Test: key=".$key.", ".$roundtipps[$key]['gshirt_score']);
|
||||
//Log::info("Test: key=".$key.", ".$roundtipps[$key]['gshirt_score']);
|
||||
}
|
||||
}
|
||||
|
||||
//dd("stop");
|
||||
*/
|
||||
//dd("User 11 Round 1 gshirt_score =".$roundtipps['1_11']['gshirt_score'].", totalscore=".$roundtipps['1_11']['gshirt_totalscore']);
|
||||
|
||||
|
||||
//////////////////////////////
|
||||
// START OF HURTFUL 6 PLACE RESTRICTION IF DAYSCORE WIN (exception: completely even scores)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue