From 6c8fc5024068f13aae787692177315ccbb404125 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20H=C3=A9midy?= Date: Mon, 25 Jun 2018 22:49:52 +0200 Subject: [PATCH 1/4] new version of crawler with fifa --- app/commands/liveScores.php | 54 +++++++++++++++++++++++++++++-------- app/start/artisan.php | 1 + 2 files changed, 44 insertions(+), 11 deletions(-) diff --git a/app/commands/liveScores.php b/app/commands/liveScores.php index 9b99b3f..e4cb119 100644 --- a/app/commands/liveScores.php +++ b/app/commands/liveScores.php @@ -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. * @@ -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.'); diff --git a/app/start/artisan.php b/app/start/artisan.php index 11447e0..cad5eb6 100644 --- a/app/start/artisan.php +++ b/app/start/artisan.php @@ -12,4 +12,5 @@ */ Artisan::add(new live); +Artisan::add(new liveScores()); Artisan::add(new setWinnersOfGroup); \ No newline at end of file From 64a36b7ab033389445ad2c6bd5c1ee914d2bc355 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20H=C3=A9midy?= Date: Wed, 27 Jun 2018 20:01:03 +0200 Subject: [PATCH 2/4] add stats on team and change order of teams --- app/commands/refreshGroupsStats.php | 113 ++++++++++++++++++ app/controllers/BetController.php | 4 +- .../2018_06_27_190440_add_group_stats.php | 47 ++++++++ app/start/artisan.php | 3 +- public/views/partials/gamesList.html | 2 +- 5 files changed, 165 insertions(+), 4 deletions(-) create mode 100644 app/commands/refreshGroupsStats.php create mode 100644 app/database/migrations/2018_06_27_190440_add_group_stats.php diff --git a/app/commands/refreshGroupsStats.php b/app/commands/refreshGroupsStats.php new file mode 100644 index 0000000..b2e3bfb --- /dev/null +++ b/app/commands/refreshGroupsStats.php @@ -0,0 +1,113 @@ +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(); + } + +} diff --git a/app/controllers/BetController.php b/app/controllers/BetController.php index 6971199..7969a12 100644 --- a/app/controllers/BetController.php +++ b/app/controllers/BetController.php @@ -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(), @@ -204,4 +204,4 @@ public function update($id) )); } -} \ No newline at end of file +} diff --git a/app/database/migrations/2018_06_27_190440_add_group_stats.php b/app/database/migrations/2018_06_27_190440_add_group_stats.php new file mode 100644 index 0000000..e70d54f --- /dev/null +++ b/app/database/migrations/2018_06_27_190440_add_group_stats.php @@ -0,0 +1,47 @@ +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'); + }); + } + +} diff --git a/app/start/artisan.php b/app/start/artisan.php index cad5eb6..d5bb9d9 100644 --- a/app/start/artisan.php +++ b/app/start/artisan.php @@ -13,4 +13,5 @@ Artisan::add(new live); Artisan::add(new liveScores()); -Artisan::add(new setWinnersOfGroup); \ No newline at end of file +Artisan::add(new setWinnersOfGroup); +Artisan::add(new refreshGroupsStats); \ No newline at end of file diff --git a/public/views/partials/gamesList.html b/public/views/partials/gamesList.html index 36518c0..de1819b 100644 --- a/public/views/partials/gamesList.html +++ b/public/views/partials/gamesList.html @@ -104,7 +104,7 @@

Pas de match pour le moment :(

@@ group.name @@

    -
  • +
  • @@ team.name @@
    @@ team.points @@
    From d0b8d32febe7aacde8933ccac241c93e5cdccd77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20H=C3=A9midy?= Date: Wed, 27 Jun 2018 20:02:32 +0200 Subject: [PATCH 3/4] remove refresh points when match is finished --- app/models/Game.php | 30 ------------------------------ 1 file changed, 30 deletions(-) diff --git a/app/models/Game.php b/app/models/Game.php index 61ff733..3493265 100644 --- a/app/models/Game.php +++ b/app/models/Game.php @@ -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(); } From 2b03ae33c74d261a29601a922299a3f5dbd95b60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20H=C3=A9midy?= Date: Wed, 27 Jun 2018 20:12:27 +0200 Subject: [PATCH 4/4] change help page + 1.0.7 --- app/config/app.php | 2 +- public/views/partials/help.html | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/config/app.php b/app/config/app.php index affcf30..96656d3 100644 --- a/app/config/app.php +++ b/app/config/app.php @@ -28,7 +28,7 @@ 'url' => 'https://worldcup.hemidy.fr', - 'version' => '1.0.6', + 'version' => '1.0.7', /* |-------------------------------------------------------------------------- diff --git a/public/views/partials/help.html b/public/views/partials/help.html index cdf3239..6cbcc13 100644 --- a/public/views/partials/help.html +++ b/public/views/partials/help.html @@ -13,7 +13,11 @@

    Comment les points sont-ils distribués ?

  • Vous avez le bon vainqueur (ex : 2-0 pronostiqué, 1-0 en réalité), alors dans ce cas vous recevrez 10 points
- 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'). + +

+ + S'ajoutent à cela, les paris bonus :
  • Pour une équipe en finale et à la bonne place : 100 points
  • Pour une équipe en finale mais pas à la bonne place : 50 points