wip
This commit is contained in:
1 parent
919ad14a9d
commit
d947f40888
9 files changed
+520
-165
No files matched your search
@@ -6,17 +6,24 @@ use App\Models\SofaScorePlayerCache;
|
||||
use App\Models\SofaScorePlayerPerSeason;
|
||||
use App\Models\StatistikoDetail;
|
||||
use App\Models\StatistikoPlayer;
|
||||
use App\Utilities\Notice;
|
||||
|
||||
class PlayerPerSeason
|
||||
{
|
||||
public static function run()
|
||||
{
|
||||
// when data changes clear player chche
|
||||
$debug = 0;
|
||||
|
||||
// when data changes clear player cache
|
||||
SofaScorePlayerCache::truncate();
|
||||
|
||||
$res = StatistikoDetail::query()->where('is_active', 1)->select('ss_player_id', 'ss_team_id')->get();
|
||||
|
||||
foreach ($res as $val) {
|
||||
foreach ($res as $key => $val) {
|
||||
|
||||
if ($debug) {
|
||||
Notice::note($val->ss_player_id.' - '.$res->count().'/'.$key + 1, 'g');
|
||||
}
|
||||
|
||||
$collection = [];
|
||||
|
||||
@@ -25,29 +32,67 @@ class PlayerPerSeason
|
||||
foreach ($res2 as $val2) {
|
||||
|
||||
if (isset($val2->event->season)) {
|
||||
if (! isset($collection['total'])) {
|
||||
$collection['total']['events_played_home'] = 0;
|
||||
$collection['total']['events_played_away'] = 0;
|
||||
$collection['total']['minutes_played_home'] = 0;
|
||||
$collection['total']['minutes_played_away'] = 0;
|
||||
$collection['total']['goals'] = 0;
|
||||
$collection['total']['fouls'] = 0;
|
||||
$collection['total']['offsides'] = 0;
|
||||
$collection['total']['shots_on_target'] = 0;
|
||||
$collection['total']['shots_off_target'] = 0;
|
||||
$collection['total']['cards'] = 0;
|
||||
}
|
||||
if (! isset($collection[$val2->event->season])) {
|
||||
$collection[$val2->event->season]['events_played_home'] = 0;
|
||||
$collection[$val2->event->season]['events_played_away'] = 0;
|
||||
$collection[$val2->event->season]['minutes_played_home'] = 0;
|
||||
$collection[$val2->event->season]['minutes_played_away'] = 0;
|
||||
$collection[$val2->event->season]['goals'] = 0;
|
||||
$collection[$val2->event->season]['fouls'] = 0;
|
||||
$collection[$val2->event->season]['cards'] = 0;
|
||||
$collection[$val2->event->season]['offsides'] = 0;
|
||||
$collection[$val2->event->season]['shots_on_target'] = 0;
|
||||
$collection[$val2->event->season]['shots_off_target'] = 0;
|
||||
}
|
||||
|
||||
if ((int) $val2->minutes_played > 0) {
|
||||
if ($val2->activeteam_id == $val2->event->home_id) {
|
||||
|
||||
$collection[$val2->event->season]['events_played_home'] += 1;
|
||||
$collection[$val2->event->season]['minutes_played_home'] += $val2->minutes_played;
|
||||
$collection['total']['events_played_home'] += 1;
|
||||
$collection['total']['minutes_played_home'] += $val2->minutes_played;
|
||||
} elseif ($val2->activeteam_id == $val2->event->away_id) {
|
||||
|
||||
$collection[$val2->event->season]['events_played_away'] += 1;
|
||||
$collection[$val2->event->season]['minutes_played_away'] += $val2->minutes_played;
|
||||
$collection['total']['minutes_played_away'] += 1;
|
||||
$collection['total']['minutes_played_away'] += $val2->minutes_played;
|
||||
}
|
||||
|
||||
$cards = $val2->card_yellow + $val2->card_yellowred + $val2->card_red;
|
||||
|
||||
$collection[$val2->event->season]['goals'] += $val2->goals;
|
||||
$collection[$val2->event->season]['fouls'] += $val2->fouls;
|
||||
$collection[$val2->event->season]['cards'] += $cards;
|
||||
$collection[$val2->event->season]['offsides'] += $val2->offsides;
|
||||
$collection[$val2->event->season]['shots_on_target'] += $val2->shots_on_target;
|
||||
$collection[$val2->event->season]['shots_off_target'] += $val2->shots_off_target;
|
||||
|
||||
$collection['total']['goals'] += $val2->goals;
|
||||
$collection['total']['fouls'] += $val2->fouls;
|
||||
$collection['total']['cards'] += $cards;
|
||||
$collection['total']['offsides'] += $val2->offsides;
|
||||
$collection['total']['shots_on_target'] += $val2->shots_on_target;
|
||||
$collection['total']['shots_off_target'] += $val2->shots_off_target;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($collection as $season => $row) {
|
||||
if ($val->ss_team_id && $val->ss_player_id) {
|
||||
|
||||
SofaScorePlayerPerSeason::updateOrCreate(
|
||||
[
|
||||
'ss_player_id' => $val->ss_player_id,
|
||||
@@ -59,6 +104,12 @@ class PlayerPerSeason
|
||||
'events_played_away' => $row['events_played_away'],
|
||||
'minutes_played_home' => $row['minutes_played_home'],
|
||||
'minutes_played_away' => $row['minutes_played_away'],
|
||||
'goals' => $row['goals'],
|
||||
'fouls' => $row['fouls'],
|
||||
'cards' => $row['cards'],
|
||||
'offsides' => $row['offsides'],
|
||||
'shots_on_target' => $row['shots_on_target'],
|
||||
'shots_off_target' => $row['shots_off_target'],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user