Planning out gshirt score handling

This commit is contained in:
Torsten 2017-12-05 11:31:15 +01:00
parent 64c893c48f
commit 7a951320a6

View file

@ -336,16 +336,12 @@ class Tipp extends Model
/////////////////////////////////////////////////////////////////////
// CALCULATION OF SCORES, RANKS, ETC. (COMPUTE AGGREGATED VALUES)
// CALCULATION OF SCORES, RANKS, ETC. (COMPUTE AGGREGATED VALUES) EXCEPT GREENSHIRT, ARGH !!
/////////////////////////////////////////////////////////////////////
$highestDayscores=array();
foreach($user_ids as $user_id) {
$totalRankScore=0;
$totalGShirtScore=0; // Green Shirt Score Accumulator
$foulCount=0; // Green Shirt Foul Counter
foreach($round_ids as $round_id) {
$key=$round_id."_".$user_id;
@ -367,22 +363,13 @@ class Tipp extends Model
$totalRankScore += $roundtipps[$key]["rankscore"];
$roundtipps[$key]['totalRankScore'] = $totalRankScore;
//
// ADD-ON: Scores für GreenShirt(grünes Trikot)
// ADD-ON: Foul-Detection for GreenShirt(grünes Trikot)
//
$isFoul = ( $roundtipps[$key]["rankscore"] == 0 );
if ( $isFoul ) { $foulCount += 1; }
if ( $foulCount > 2 ) {
$totalGShirtScore = 0;
$foulCount = 0;
} else {
$totalGShirtScore += $roundtipps[$key]["rankscore"];
Log::info("!!!!> Adding score: ".$roundtipps[$key]["rankscore"]);
}
$roundtipps[$key]['gshirt_totalscore'] = $totalGShirtScore;
$roundtipps[$key]['gshirt_foulcount'] = $foulCount;
if ($foulCount==3) $foulCount=0;
}
}
@ -394,7 +381,6 @@ class Tipp extends Model
$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'));
@ -417,6 +403,37 @@ class Tipp extends Model
}
}
////////////////////////////////////////////////////////
// Greenshirt Score Determination
// Loop again over roundtipps, sort each round, give/write forth greenshirt score
$userList=array(); // Only to detect ranks 1-5; score results will get written to roundtipps[$key]['...']
// (A) SET GSCORE EVERY ROUND
// 1.) Loop over roundtipps and : a.) add user + rankscore + foulcount to $userList
// b.) Sort $userList by rankscore
// c.) Determine ranks 1-5 and number of points to distribute
// d.) Mark Rank1 as is_gshirt_owner
// e.) Distribute points, set roundtipps[$key]['gshirt_score'], every other to zero
// (B) SET TOTAL GSCORE EVERY ROUND
// 2.) Loop over roundtipps and: a.) add gshirt_score to gshirt_score_total --OR-- zero gshirt_score_total if foulCount==3
/*
* foreach($round_ids as $round_id) {
$users=array();
$gShirtScoreTotal=0;
foreach($user_ids as $user_id) {
// add gshirt_score to $roundtipps[$key]
}
}
*/
//////////////////////////////
// START OF HURTFUL 6 PLACE RESTRICTION IF DAYSCORE WIN (exception: completely even scores)
// If more than 6 DayScoreWinners: Restrict by dayscore (rank)
@ -563,8 +580,14 @@ class Tipp extends Model
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
}
// Used by getRoundTipps
public static function cmpGShirt($rank1, $rank2) {
return ($rank1[1] < $rank2[1]); //Feld0: user_id, Feld1: rank
}
}