Working on gshirt payout

This commit is contained in:
Torsten Schneider 2017-12-29 19:08:46 +01:00
parent 16231357b4
commit 9126d54dfb
10 changed files with 507 additions and 108 deletions

View file

@ -206,7 +206,9 @@ class UsersController extends Controller
$season = Season::getCurrent();
if ( $seasonId !=-1 ) {
$season=Season::where('id','=',$seasonId)->first();
$seasinId = $season->id;
$seasonId = $season->id;
} else {
$seasonId = $season->id;
}
// Check ob mindestens eine Runde der Saison gelockt ist angezeigt werden kann
@ -214,11 +216,11 @@ class UsersController extends Controller
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=".$seasonId." and games.round_id=rounds.id;";
$date = DB::select($sql);
$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=".$seasonId." and games.round_id=rounds.id order by rounds.id;";
$entries = DB::select($sql);
if (count($date)>0) {
$start_date = $date[0]->start_date;
if (count($entries)>0) {
$start_date = $entries[0]->start_date;
return view('users.no_ranking', compact('start_date'));
} else {
return redirect("/");
@ -490,13 +492,29 @@ class UsersController extends Controller
public function money_ranking() {
if (Auth::guest()) { return redirect("/"); }
$currentSeason = Season::getCurrent();
$currentSeason = Season::getCurrent();
if (!$currentSeason) {
return view('users.no_ranking', compact('start_date'));
}
// Payment made ?
if (! User::payment_date(Auth::user()->id, $currentSeason->id) && Auth::user()->name!="Torsten Schneider") {
return view('users.no_payment');
}
if (Round::getLastLockedRoundId()==-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 order by rounds.id;";
$entries = DB::select($sql);
if (count($entries)>0) {
$start_date = $entries[0]->start_date;
return view('users.no_ranking', compact('start_date'));
} else {
return redirect("/");
}
}
$response = Tipp::getRoundTipps();
$roundtipps = $response['roundtipps'];
$roundData = $response['roundData'];

View file

@ -145,19 +145,19 @@ class Quota extends Model
$quota = new Quota;
$quota->season_id = $season_id;
$quota->name = "Tagessieg";
$quota->prc = 50;
$quota->prc = 45;
$quota->save();
$quota = new Quota;
$quota->season_id = $season_id;
$quota->name = "Platzierung";
$quota->prc = 50;
$quota->prc = 45;
$quota->save();
$quota = new Quota;
$quota->season_id = $season_id;
$quota->name = "Gruenes Trikot";
$quota->prc = 0;
$quota->prc = 10;
$quota->save();
$quota = new Quota;
@ -246,6 +246,8 @@ class Quota extends Model
$quota->prc = 4;
$quota->save();
///////////////////////////////////
$quota = new Quota;
$quota->season_id = $season_id;
$quota->name = "Liga Platz 1";

View file

@ -9,8 +9,13 @@ class Test extends Model
{
// In order for testing seasons to work, we need a way to set all the users to 'paid'
// this method is used by fillSeason method
public static function paySeason($seasonId)
public static function paySeason($seasonId=-1)
{
if ($seasonId==-1) {
$season = Season::getCurrent();
$seasonId = $season->id;
}
$users = User::all();
$cnt=0;
foreach ($users as $user) {
@ -22,16 +27,19 @@ class Test extends Model
}
public static function fillSeason($seasonId=-1) {
if ($seasonId==-1) {
$season = Season::getCurrent();
$seasonId = $season->id;
}
error_log("creating all tipps started");
Tipp::createAllTips();
error_log("creating all tipps completed");
$users = User::all();
if ($seasonId==-1) {
$season = Season::getCurrent();
$seasonId = $season->id;
}
error_log("setting payment started");
Test::paySeason($seasonId);

View file

@ -261,6 +261,8 @@ class Tipp extends Model
$currentSeason = Season::where('id', '=', $seasonId)->first();
};
if (Round::getLastLockedRoundId()==-1) return null;
// 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.
$sql = "select users.id as user_id, users.name as user_name, ";
@ -357,7 +359,6 @@ class Tipp extends Model
$highestDayscores = array();
foreach ($user_ids as $user_id) {
$totalRankScore = 0;
$foulCount = 0; // Green Shirt Foul Counter
foreach ($round_ids as $round_id) {
$key = $round_id . "_" . $user_id;
// Compute Dayscore values
@ -507,27 +508,28 @@ class Tipp extends Model
}
// B) SET GSCORE TOTAL EVERY ROUND ( and take fouls into consideration )
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 );
$isFoul = ( $roundtipps[$key]['rankscore'] == 0 && $totalScore > 0 );
if ($isFoul) {
Log::info("Foul => round_id _ user_id=".$key." / totalRankScore=".$roundtipps[$key]["totalRankScore"]);
$foulCount+=1;
if ($foulCount==3) {
$foulCount=0;
$totalScore=0;
}
}
$lastTotalRankScore=
$totalScore += $score;
$roundtipps[$key]['gshirt_totalscore']=$totalScore;
$roundtipps[$key]['gshirt_foulcount']=$foulCount;
//error_log("Test: key=".$key.", ".$roundtipps[$key]['gshirt_score']);
//Log::info("Test: key=".$key.", ".$roundtipps[$key]['gshirt_score']);
}