This repository has been archived by the owner on Jun 3, 2020. It is now read-only.
forked from fcote/worldcup
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from clemh78/foot_ng
1.0.7
- Loading branch information
Showing
9 changed files
with
215 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
app/database/migrations/2018_06_27_190440_add_group_stats.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters