This commit is contained in:
salam committed 2026-08-12 13:54:04 +02:00
1 parent 704aa6650c
commit ddc0e03abd
4 files changed
+74

No files matched your search

+62
View File
@@ -0,0 +1,62 @@
<?php
namespace App\Actions;
use App\Models\SofaScorePlayerPerSeason;
use App\Models\StatistikoDetail;
use App\Models\StatistikoPlayer;
class PlayerPerSeason
{
public static function run()
{
$res = StatistikoDetail::query()->select('ss_player_id', 'ss_team_id')->get();
foreach ($res as $val) {
$collection = [];
$res2 = StatistikoPlayer::with('event')->where('ss_player_id', $val->ss_player_id)->get();
foreach ($res2 as $val2) {
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;
}
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;
} else if ($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;
}
}
}
foreach ($collection as $season => $row) {
if ($val->ss_team_id && $val->ss_player_id) {
SofaScorePlayerPerSeason::updateOrCreate(
[
'ss_player_id' => $val->ss_player_id,
'ss_team_id' => $val->ss_team_id,
'season' => $season
],
[
'events_played_home' => $row['events_played_home'],
'events_played_away' => $row['events_played_away'],
'minutes_played_home' => $row['minutes_played_home'],
'minutes_played_away' => $row['minutes_played_away'],
]
);
}
}
}
}
}
@@ -2,6 +2,7 @@
namespace App\Filament\Imports\Helper;
use App\Actions\PlayerPerSeason;
use App\Models\StatistikoDetail;
use Illuminate\Support\Carbon;
use Illuminate\Support\LazyCollection;
@@ -58,5 +59,8 @@ class ImportDetails
}
}
});
/**update statistic player tabel */
PlayerPerSeason::run();
}
}
@@ -2,6 +2,7 @@
namespace App\Filament\Imports\Helper;
use App\Actions\PlayerPerSeason;
use App\Models\StatistikoPlayer;
use Illuminate\Support\LazyCollection;
use Spatie\SimpleExcel\SimpleExcelReader;
@@ -111,5 +112,8 @@ class ImportPlayer
);
}
});
/**update statistic player tabel */
PlayerPerSeason::run();
}
}
@@ -37,6 +37,9 @@ class LoadPlayer
$matches_count = count($matches);
// dd($matches_count);
$positions_map = LoadPositions::load();
// needs to run daily for pre-calculaton
@@ -63,6 +66,7 @@ class LoadPlayer
$colorlevel = round($matches_count / 3);
$preferred_foot = $val->details->preferred_foot;
$player_position = ' (Role ' . $val->details->position . ')';
if (in_array($val->details->position, $positions_map['MIDFIELD'])) {