Skip to content
This repository has been archived by the owner on Jun 3, 2020. It is now read-only.

Commit

Permalink
Merge pull request #27 from clemh78/foot_ng
Browse files Browse the repository at this point in the history
1.0.7
  • Loading branch information
clemh78 authored Jun 27, 2018
2 parents cbf3e64 + 2b03ae3 commit 177d098
Show file tree
Hide file tree
Showing 9 changed files with 215 additions and 47 deletions.
54 changes: 43 additions & 11 deletions app/commands/liveScores.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,26 @@ public function __construct()
parent::__construct();
}

//ID compet et saison FIFA
private $ID_COMPETITION = 17;
private $ID_SEASON = 254645;

//Renvoi l'ID fifa pour un ID kupi
private function getStageId($idStage){
if($idStage == null)
return 275073;
else if($idStage == 5)
return 275099;
else if($idStage == 4)
return 275093;
else if($idStage == 3)
return 275095;
else if($idStage == 2)
return 275097;
else if($idStage == 1)
return 275101;
}

/**
* Execute the console command.
*
Expand All @@ -41,25 +61,37 @@ public function fire()
{
while(true){
$date = new DateTime();
$games = Game::whereRaw('date < ? && finished = 0', array(new DateTime()))->get();
$games = Game::whereRaw('date < ? && status != "completed"', array(new DateTime()))->get();
if(count($games) > 0){
foreach($games as $value){
$response = Unirest\Request::get("https://api.fifa.com/api/v1/live/football/17/254645/275073/".$value->fifa_match_id."");
$response = Unirest\Request::get("https://api.fifa.com/api/v1/live/football/".$this->ID_COMPETITION."/".$this->ID_SEASON."/".$this->getStageId($value->stage_id)."/".$value->fifa_match_id."");
$match = $response->body;

if($value->team1()->first()->code == $match->HomeTeam->IdCountry && $value->team2()->first()->code == $match->AwayTeam->IdCountry) {
//Dans tous les cas : MAJ du score
$value->team1_points = $match->HomeTeam->Score;
$value->team2_points = $match->AwayTeam->Score;
if($value->kick_at_goal == 1){
$value->team1_kick_at_goal = $match->HomeTeamPenaltyScore;
$value->team2_kick_at_goal = $match->AwayTeamPenaltyScore;
}
$value->minute = $match->MatchTime;
$this->info('[' . $date->format('Y-m-d H:i:s') . '] MAJ scores : ' . $value->team1()->first()->name . ' ' . $value->team1_points . '-' . $value->team2_points . ' ' . $value->team2()->first()->name . '.');


if ($match->MatchStatus == 10 || $match->MatchStatus == 0 || $match->MatchStatus == 3) {
$value->status = "in_progress";

//Dans tous les cas : MAJ du score
$value->team1_points = $match->HomeTeam->Score;
$value->team2_points = $match->AwayTeam->Score;
if ($value->kick_at_goal == 1) {
$value->team1_kick_at_goal = $match->HomeTeamPenaltyScore;
$value->team2_kick_at_goal = $match->AwayTeamPenaltyScore;
}

$value->time = $match->MatchTime;
if($match->Period == 4)
$value->time = "half-time";

$this->info('[' . $date->format('Y-m-d H:i:s') . '] MAJ scores : ' . $value->team1()->first()->name . ' ' . $value->team1_points . '-' . $value->team2_points . ' ' . $value->team2()->first()->name . ' ('.$value->time.').');
}

//Si match terminé, on fige les infos et on distribue les points
if ($match->MatchStatus == 10 || $match->MatchStatus == 0) {
$value->time = "full-time";

if ($value->team1_points > $value->team2_points) {
$value->setFinished(1);
$this->info('[' . $date->format('Y-m-d H:i:s') . '] Match fini : ' . $value->team1()->first()->name . ' gagnant.');
Expand Down
113 changes: 113 additions & 0 deletions app/commands/refreshGroupsStats.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<?php

use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;

class refreshGroupsStats extends Command {

/**
* The console command name.
*
* @var string
*/
protected $name = 'wc:refreshGroupsStats';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Permet de recalculer l\'ensemble des stats concernant les équipes.';

/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}

/**
* Execute the console command.
*
* @return mixed
*/
public function fire()
{
$teams = Team::get();

foreach($teams as $team){
$this->info('MAJ stats de l\'équipe '.$team->name);

$played = 0;
$wins = 0;
$draws = 0;
$losses = 0;

$goals_for = 0;
$goals_against = 0;
$goals_diff = 0;

$games = Game::whereRaw('(team1_id = ? OR team2_id = ?) AND stage_id IS NULL AND status = ?', array($team->id, $team->id, 'completed'))->get();

foreach($games as $game) {
$played++;

if($game->winner_id != null){
if($game->winner_id == $team->id)
$wins++;
else
$losses++;
}

if($game->winner_id == null)
$draws++;

if($game->team1_id == $team->id){
$goals_for = $goals_for + $game->team1_points;
$goals_against = $goals_against + $game->team2_points;
}else{
$goals_for = $goals_for + $game->team2_points;
$goals_against = $goals_against + $game->team1_points;
}
}

$points = ($wins * 3) + $draws;
$goals_diff = $goals_for - $goals_against;

$team->games_played = $played;
$team->wins = $wins;
$team->draws = $draws;
$team->losses = $losses;
$team->goals_for = $goals_for;
$team->goals_against = $goals_against;
$team->goals_diff = $goals_diff;
$team->points = $points;
$team->save();
}
}

/**
* Get the console command arguments.
*
* @return array
*/
protected function getArguments()
{
return array();
}

/**
* Get the console command options.
*
* @return array
*/
protected function getOptions()
{
return array();
}

}
2 changes: 1 addition & 1 deletion app/config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

'url' => 'https://kupi.fr',

'version' => '1.0.6',
'version' => '1.0.7',

/*
|--------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/BetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public function store()

$input['winner_id'] = ($input['winner_id'] != null)?$input['winner_id']:null;

if($game->kick_at_goal && $bet->winner_id == null)
if($game->kick_at_goal && $input['winner_id'] == null)
return Response::json(
array('success' => false,
'payload' => array(),
Expand Down Expand Up @@ -204,4 +204,4 @@ public function update($id)
));
}

}
}
47 changes: 47 additions & 0 deletions app/database/migrations/2018_06_27_190440_add_group_stats.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class AddGroupStats extends Migration {

/**
* Run the migrations.
*
* @return void
*/
public function up()
{
//Modification table group
Schema::table('team', function($table)
{
$table->integer('games_played')->default(0);
$table->integer('wins')->default(0);
$table->integer('draws')->default(0);
$table->integer('losses')->default(0);
$table->integer('goals_for')->default(0);
$table->integer('goals_against')->default(0);
$table->integer('goals_diff')->default(0);
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('team', function($table)
{
$table->dropColumn('games_played');
$table->dropColumn('wins');
$table->dropColumn('draws');
$table->dropColumn('losses');
$table->dropColumn('goals_for');
$table->dropColumn('goals_against');
$table->dropColumn('goals_diff');
});
}

}
30 changes: 0 additions & 30 deletions app/models/Game.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,36 +233,6 @@ public function setFinished($num_team){
}
}

//Si en phase de poule, alors on distribue des points aux équipes
if($this->stage_id == null){
//Distribution des points pour les équipes
if($num_team != null){
//Si l'équipe une a gagnée, on lui donne 3 points
if($num_team == 1){
$team1 = Team::whereRaw('id = ?', array($this->team1_id))->first();

$team1->points = $team1->points + 3;
$team1->save();

//Si l'équipe deux a gagnée, on lui donne 3 points
}else{
$team2 = Team::whereRaw('id = ?', array($this->team2_id))->first();

$team2->points = $team2->points + 3;
$team2->save();
}

//Si match nul, on donne 1 points aux deux
}else{
$team1 = Team::whereRaw('id = ?', array($this->team1_id))->first();
$team1->points = $team1->points + 1;
$team1->save();
$team2 = Team::whereRaw('id = ?', array($this->team2_id))->first();
$team2->points = $team2->points + 1;
$team2->save();
}
}

$this->save();
}

Expand Down
4 changes: 3 additions & 1 deletion app/start/artisan.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@
*/

Artisan::add(new live);
Artisan::add(new setWinnersOfGroup);
Artisan::add(new liveScores());
Artisan::add(new setWinnersOfGroup);
Artisan::add(new refreshGroupsStats);
2 changes: 1 addition & 1 deletion public/views/partials/gamesList.html
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ <h2>Pas de match pour le moment :(</h2>
<div class="col-md-3 col-sm-6 group" ng-repeat="group in groups" >
<h2 class="subheader" >@@ group.name @@</h2>
<ul>
<li ng-repeat="team in group.teams | orderBy : '-points'" >
<li ng-repeat="team in group.teams | orderBy : ['-points', '-goals_diff', '-goals_for', 'name']" >
<img src="images/flags/@@ team.code.toLowerCase() @@">
@@ team.name @@ <i ng-show="team.id == group.winner_id || team.id == group.runnerup_id" class="fa fa-check"></i>
<div class="points">@@ team.points @@</div>
Expand Down
6 changes: 5 additions & 1 deletion public/views/partials/help.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ <h2>Comment les points sont-ils distribués ?</h2>
<li>Vous avez le bon vainqueur (ex : 2-0 pronostiqué, 1-0 en réalité), alors dans ce cas vous recevrez <span class="label label-primary">10 points</span></li>
</ul>

S'ajoutent à cela, les paris bonus :
Pour les matchs à partir des 8ème de finales (match nul non autorisé), le score que vous renseignez correspond au score avant la séance de T.A.B (si pas de prolongation, alors correspond au score à la 90').

<br /><br />

S'ajoutent à cela, les paris bonus :
<ul>
<li>Pour une équipe en finale et à la bonne place : <span class="label label-primary">100 points</span></li>
<li>Pour une équipe en finale mais pas à la bonne place : <span class="label label-primary">50 points</span></li>
Expand Down

0 comments on commit 177d098

Please sign in to comment.