removed precalculation
This commit is contained in:
1 parent
f6f5dd0c7c
commit
838d6419f4
11 files changed
+214
-680
No files matched your search
@@ -1,22 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Console\Commands;
|
|
||||||
|
|
||||||
use App\Traits\UpdateHelper;
|
|
||||||
use Illuminate\Console\Command;
|
|
||||||
|
|
||||||
class PreCalcPlayer extends Command
|
|
||||||
{
|
|
||||||
use UpdateHelper;
|
|
||||||
|
|
||||||
protected $signature = 'grp:ply {--d}';
|
|
||||||
|
|
||||||
protected $description = 'player pre calculations';
|
|
||||||
|
|
||||||
public function handleUpdate(int $playerCount): void
|
|
||||||
{
|
|
||||||
// Have fun running imports here
|
|
||||||
// Examples can be found in the ImportHelper trait
|
|
||||||
$this->updatePlayers($playerCount);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-16
@@ -7,7 +7,6 @@ use App\Models\StatistikoImport;
|
|||||||
use Filament\Actions\Action;
|
use Filament\Actions\Action;
|
||||||
use Filament\Actions\CreateAction;
|
use Filament\Actions\CreateAction;
|
||||||
use Filament\Resources\Pages\ListRecords;
|
use Filament\Resources\Pages\ListRecords;
|
||||||
use Illuminate\Support\Facades\Artisan;
|
|
||||||
use Illuminate\Support\Facades\File;
|
use Illuminate\Support\Facades\File;
|
||||||
|
|
||||||
class ListStatistikoImports extends ListRecords
|
class ListStatistikoImports extends ListRecords
|
||||||
@@ -17,21 +16,6 @@ class ListStatistikoImports extends ListRecords
|
|||||||
protected function getHeaderActions(): array
|
protected function getHeaderActions(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
Action::make('precalculation')->color('success')
|
|
||||||
->icon('phosphor-gear')
|
|
||||||
->requiresConfirmation() // Optional: Asks user before running
|
|
||||||
->modalClickThrough()
|
|
||||||
->action(function (Action $action) {
|
|
||||||
// Wir registrieren einen Shutdown-Terminating-Job,
|
|
||||||
// damit Filament die HTTP-Antwort an den Browser senden kann,
|
|
||||||
// BEVOR der speicherhungrige Befehl startet.
|
|
||||||
app()->terminating(function () {
|
|
||||||
Artisan::call('grp:ply');
|
|
||||||
});
|
|
||||||
|
|
||||||
// Schließt das Modal SOFORT im Browser
|
|
||||||
$action->close();
|
|
||||||
}),
|
|
||||||
CreateAction::make('upload_file')
|
CreateAction::make('upload_file')
|
||||||
->modalIcon('phosphor-upload')
|
->modalIcon('phosphor-upload')
|
||||||
->modalHeading('Upload Statistiko Files')
|
->modalHeading('Upload Statistiko Files')
|
||||||
|
|||||||
@@ -3,8 +3,7 @@
|
|||||||
namespace App\Filament\Pages\Selections;
|
namespace App\Filament\Pages\Selections;
|
||||||
|
|
||||||
use App\Filament\Pages\Selections\Helper\GetSeason;
|
use App\Filament\Pages\Selections\Helper\GetSeason;
|
||||||
use App\Models\SofaScorePlayerPerSeason;
|
use App\Filament\Widgets\Boxes\LoadPlayerAverages;
|
||||||
use App\Models\StatistikoDetail;
|
|
||||||
use App\Models\StatistikoEvent;
|
use App\Models\StatistikoEvent;
|
||||||
|
|
||||||
class LoadPlayerSelection
|
class LoadPlayerSelection
|
||||||
@@ -12,13 +11,6 @@ class LoadPlayerSelection
|
|||||||
public static function load(?int $team_id, ?string $team_position, ?int $sofascore_category_id, ?array $season, ?string $seasonmode)
|
public static function load(?int $team_id, ?string $team_position, ?int $sofascore_category_id, ?array $season, ?string $seasonmode)
|
||||||
{
|
{
|
||||||
$season = GetSeason::load($season, $seasonmode);
|
$season = GetSeason::load($season, $seasonmode);
|
||||||
|
|
||||||
// $hash = hash('crc32', $team_id.$team_position.$sofascore_category_id.serialize($season));
|
|
||||||
// $cached_players = SofaScorePlayerCache::where('hash', $hash)->value('players');
|
|
||||||
// if ($cached_players) {
|
|
||||||
// return $cached_players;
|
|
||||||
// }
|
|
||||||
|
|
||||||
$matches = StatistikoEvent::whereIn('season', $season)
|
$matches = StatistikoEvent::whereIn('season', $season)
|
||||||
->where(function ($query) use ($team_id, $team_position) {
|
->where(function ($query) use ($team_id, $team_position) {
|
||||||
switch ($team_position) {
|
switch ($team_position) {
|
||||||
@@ -36,29 +28,24 @@ class LoadPlayerSelection
|
|||||||
|
|
||||||
$positions_map = LoadPositions::load();
|
$positions_map = LoadPositions::load();
|
||||||
|
|
||||||
$team_player_ids = StatistikoDetail::where('ss_team_id', $team_id)->pluck('ss_player_id')->toArray();
|
$players = LoadPlayerAverages::load($team_id, $season);
|
||||||
|
|
||||||
$players = SofaScorePlayerPerSeason::with('details')->where('season', $season)->whereIn('ss_player_id', $team_player_ids)->get();
|
|
||||||
|
|
||||||
$arr = [];
|
$arr = [];
|
||||||
foreach ($players as $val) {
|
foreach ($players as $ss_player_id => $val) {
|
||||||
if ($val->details) {
|
if (! isset($arr[$ss_player_id])) {
|
||||||
$player_id = $val->ss_player_id;
|
$arr[$ss_player_id]['player_name'] = $val['player_name'];
|
||||||
if (! isset($arr[$player_id])) {
|
$arr[$ss_player_id]['events_played_home'] = $val['events_played_home'];
|
||||||
$arr[$player_id]['player_name'] = $val->details->player_name;
|
$arr[$ss_player_id]['events_played_away'] = $val['events_played_away'];
|
||||||
$arr[$player_id]['events_played_home'] = $val->events_played_home;
|
$arr[$ss_player_id]['minutes_played_home'] = $val['minutes_played_home'];
|
||||||
$arr[$player_id]['events_played_away'] = $val->events_played_away;
|
$arr[$ss_player_id]['minutes_played_away'] = $val['minutes_played_away'];
|
||||||
$arr[$player_id]['minutes_played_home'] = $val->minutes_played_home;
|
$arr[$ss_player_id]['preferred_foot'] = $val['preferred_foot'] ?? '';
|
||||||
$arr[$player_id]['minutes_played_away'] = $val->minutes_played_away;
|
$arr[$ss_player_id]['player_position'] = $val['position'] ?? '';
|
||||||
$arr[$player_id]['preferred_foot'] = $val->details->preferred_foot ?? '';
|
$arr[$ss_player_id]['color_level'] = round($matches_count / 3);
|
||||||
$arr[$player_id]['player_position'] = $val->details->position ?? '';
|
} else {
|
||||||
$arr[$player_id]['color_level'] = round($matches_count / 3);
|
$arr[$ss_player_id]['events_played_home'] += $val['events_played_home'];
|
||||||
} else {
|
$arr[$ss_player_id]['events_played_away'] += $val['events_played_away'];
|
||||||
$arr[$player_id]['events_played_home'] += $val->events_played_home;
|
$arr[$ss_player_id]['minutes_played_home'] += $val['minutes_played_home'];
|
||||||
$arr[$player_id]['events_played_away'] += $val->events_played_away;
|
$arr[$ss_player_id]['minutes_played_away'] += $val['minutes_played_away'];
|
||||||
$arr[$player_id]['minutes_played_home'] += $val->minutes_played_home;
|
|
||||||
$arr[$player_id]['minutes_played_away'] += $val->minutes_played_away;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -146,7 +146,6 @@ class Statistic extends BaseDashboard
|
|||||||
Actions::make([
|
Actions::make([
|
||||||
Action::make('esc')
|
Action::make('esc')
|
||||||
->hiddenLabel()
|
->hiddenLabel()
|
||||||
->hidden(fn (Get $get) => $get('similar_past_matches') != 'none')
|
|
||||||
->tooltip('Clear All (esc)')
|
->tooltip('Clear All (esc)')
|
||||||
->icon('phosphor-x')
|
->icon('phosphor-x')
|
||||||
->color('gray')
|
->color('gray')
|
||||||
|
|||||||
@@ -3,93 +3,104 @@
|
|||||||
namespace App\Filament\Widgets\Boxes;
|
namespace App\Filament\Widgets\Boxes;
|
||||||
|
|
||||||
use App\Models\StatistikoDetail;
|
use App\Models\StatistikoDetail;
|
||||||
|
use App\Models\StatistikoEvent;
|
||||||
use App\Models\StatistikoPlayer;
|
use App\Models\StatistikoPlayer;
|
||||||
|
|
||||||
class LoadPlayerAverages
|
class LoadPlayerAverages
|
||||||
{
|
{
|
||||||
public static function load(int &$team_id, string $season)
|
public static function load(int &$team_id, string|array $season)
|
||||||
{
|
{
|
||||||
|
|
||||||
$players = StatistikoDetail::where('ss_team_id', $team_id)->get();
|
$players = StatistikoDetail::where('ss_team_id', $team_id)->get();
|
||||||
|
|
||||||
|
$player_ids = [];
|
||||||
|
foreach ($players as $player) {
|
||||||
|
$player_ids[] = $player->ss_player_id;
|
||||||
|
}
|
||||||
|
|
||||||
$arr = [];
|
$arr = [];
|
||||||
|
|
||||||
foreach ($players as $val) {
|
if (is_array($season)) {
|
||||||
|
$matches_for_season = StatistikoEvent::whereIn('season', $season)->pluck('match_id')->toArray();
|
||||||
|
$res = StatistikoPlayer::with('details')->whereIn('match_id', $matches_for_season)->whereIn('ss_player_id', $player_ids)->get();
|
||||||
|
} else {
|
||||||
|
$res = StatistikoPlayer::with('details')->whereIn('ss_player_id', $player_ids)->get();
|
||||||
|
}
|
||||||
|
|
||||||
$res = StatistikoPlayer::whereIn('ss_player_id', $val->ss_player_id)->get();
|
foreach ($res as $val) {
|
||||||
|
|
||||||
foreach ($res as $val) {
|
$ss_player_id = (int) $val->ss_player_id;
|
||||||
|
$activeteam_id = (int) $val->activeteam_id;
|
||||||
|
$minutes_played = (int) $val->minutes_played;
|
||||||
|
$home_id = (int) $val->event->home_id;
|
||||||
|
$away_id = (int) $val->event->away_id;
|
||||||
|
$startime = $val->event->starttime;
|
||||||
|
|
||||||
$ss_player_id = (int) $val->ss_player_id;
|
if ($startime->greaterThan(now()->subDays(180))) {
|
||||||
$activeteam_id = (int) $val->activeteam_id;
|
$last_180_days = true;
|
||||||
$minutes_played = (int) $val->minutes_played;
|
} else {
|
||||||
$season = $val->event->season;
|
$last_180_days = false;
|
||||||
$home_id = (int) $val->event->home_id;
|
}
|
||||||
$away_id = (int) $val->event->away_id;
|
|
||||||
$startime = $val->event->starttime;
|
|
||||||
|
|
||||||
if ($startime->greaterThan(now()->subDays(180))) {
|
if (! isset($arr[$ss_player_id])) {
|
||||||
$last_180_days = true;
|
self::array_template($arr, $ss_player_id);
|
||||||
} else {
|
}
|
||||||
$last_180_days = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (! isset($arr[$ss_player_id])) {
|
if ($activeteam_id == $home_id) {
|
||||||
self::array_template($arr, $ss_player_id);
|
$arr[$ss_player_id]['events_played_home'] += 1;
|
||||||
}
|
$arr[$ss_player_id]['minutes_played_home'] += $minutes_played;
|
||||||
|
$arr[$ss_player_id]['events_played_home'] += 1;
|
||||||
if ($activeteam_id == $home_id) {
|
$arr[$ss_player_id]['minutes_played_home'] += $minutes_played;
|
||||||
|
if ($last_180_days) {
|
||||||
$arr[$ss_player_id]['events_played_home'] += 1;
|
$arr[$ss_player_id]['events_played_home'] += 1;
|
||||||
$arr[$ss_player_id]['minutes_played_home'] += $minutes_played;
|
$arr[$ss_player_id]['minutes_played_home'] += $minutes_played;
|
||||||
$arr[$ss_player_id]['events_played_home'] += 1;
|
}
|
||||||
$arr[$ss_player_id]['minutes_played_home'] += $minutes_played;
|
} elseif ($activeteam_id == $away_id) {
|
||||||
if ($last_180_days) {
|
$arr[$ss_player_id]['events_played_away'] += 1;
|
||||||
$arr[$ss_player_id]['events_played_home'] += 1;
|
$arr[$ss_player_id]['minutes_played_away'] += $minutes_played;
|
||||||
$arr[$ss_player_id]['minutes_played_home'] += $minutes_played;
|
$arr[$ss_player_id]['events_played_away'] += 1;
|
||||||
}
|
$arr[$ss_player_id]['minutes_played_away'] += $minutes_played;
|
||||||
} elseif ($activeteam_id == $away_id) {
|
if ($last_180_days) {
|
||||||
$arr[$ss_player_id]['events_played_away'] += 1;
|
$arr[$ss_player_id]['events_played_away'] += 1;
|
||||||
$arr[$ss_player_id]['minutes_played_away'] += $minutes_played;
|
$arr[$ss_player_id]['minutes_played_away'] += $minutes_played;
|
||||||
$arr[$ss_player_id]['events_played_away'] += 1;
|
}
|
||||||
$arr[$ss_player_id]['minutes_played_away'] += $minutes_played;
|
|
||||||
if ($last_180_days) {
|
|
||||||
$arr[$ss_player_id]['events_played_away'] += 1;
|
|
||||||
$arr[$ss_player_id]['minutes_played_away'] += $minutes_played;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
$cards = $val->card_yellow + $val->card_yellowred;
|
$cards = $val->card_yellow + $val->card_yellowred;
|
||||||
|
|
||||||
if ($season == 'last180days' && $last_180_days) {
|
if ($season == 'last180days' && $last_180_days) {
|
||||||
$arr[$ss_player_id]['ss_player_id'] = $ss_player_id;
|
$arr[$ss_player_id]['ss_player_id'] = $ss_player_id;
|
||||||
$arr[$ss_player_id]['season'] = 'last180days';
|
$arr[$ss_player_id]['total_events']++;
|
||||||
$arr[$ss_player_id]['total_events']++;
|
$arr[$ss_player_id]['total_min'] += $minutes_played;
|
||||||
$arr[$ss_player_id]['total_min'] += $minutes_played;
|
$arr[$ss_player_id]['average_min'] = round($arr[$ss_player_id]['total_min'] / $arr[$ss_player_id]['total_events']);
|
||||||
$arr[$ss_player_id]['average_min'] = round($arr[$ss_player_id]['total_min'] / $arr[$ss_player_id]['total_events']);
|
$arr[$ss_player_id]['goals'] += $val->goals;
|
||||||
$arr[$ss_player_id]['goals'] += $val->goals;
|
$arr[$ss_player_id]['fouls'] += $val->fouls;
|
||||||
$arr[$ss_player_id]['fouls'] += $val->fouls;
|
$arr[$ss_player_id]['cards'] += $cards;
|
||||||
$arr[$ss_player_id]['cards'] += $cards;
|
$arr[$ss_player_id]['offsides'] += $val->offsides;
|
||||||
$arr[$ss_player_id]['offsides'] += $val->offsides;
|
$arr[$ss_player_id]['shots_on_target'] += $val->shots_on_target;
|
||||||
$arr[$ss_player_id]['shots_on_target'] += $val->shots_on_target;
|
$arr[$ss_player_id]['shots_off_target'] += $val->shots_off_target;
|
||||||
$arr[$ss_player_id]['shots_off_target'] += $val->shots_off_target;
|
$arr[$ss_player_id]['shots_blocked'] += $val->shots_blocked;
|
||||||
$arr[$ss_player_id]['shots_blocked'] += $val->shots_blocked;
|
$arr[$ss_player_id]['total_shots'] += $val->shots_on_target + $val->shots_off_target + $val->shots_blocked;
|
||||||
$arr[$ss_player_id]['total_shots'] += $val->shots_on_target + $val->shots_off_target + $val->shots_blocked;
|
}
|
||||||
}
|
if ($season != 'last180days') {
|
||||||
if ($season != 'last180days') {
|
$arr[$ss_player_id]['ss_player_id'] = $ss_player_id;
|
||||||
$arr[$ss_player_id]['ss_player_id'] = $ss_player_id;
|
$arr[$ss_player_id]['total_events']++;
|
||||||
$arr[$ss_player_id]['season'] = $season;
|
$arr[$ss_player_id]['total_min'] += $minutes_played;
|
||||||
$arr[$ss_player_id]['total_events']++;
|
$arr[$ss_player_id]['average_min'] = round($arr[$ss_player_id]['total_min'] / $arr[$ss_player_id]['total_events']);
|
||||||
$arr[$ss_player_id]['total_min'] += $minutes_played;
|
$arr[$ss_player_id]['goals'] += $val->goals;
|
||||||
$arr[$ss_player_id]['average_min'] = round($arr[$ss_player_id]['total_min'] / $arr[$ss_player_id]['total_events']);
|
$arr[$ss_player_id]['fouls'] += $val->fouls;
|
||||||
$arr[$ss_player_id]['goals'] += $val->goals;
|
$arr[$ss_player_id]['cards'] += $cards;
|
||||||
$arr[$ss_player_id]['fouls'] += $val->fouls;
|
$arr[$ss_player_id]['offsides'] += $val->offsides;
|
||||||
$arr[$ss_player_id]['cards'] += $cards;
|
$arr[$ss_player_id]['shots_on_target'] += $val->shots_on_target;
|
||||||
$arr[$ss_player_id]['offsides'] += $val->offsides;
|
$arr[$ss_player_id]['shots_off_target'] += $val->shots_off_target;
|
||||||
$arr[$ss_player_id]['shots_on_target'] += $val->shots_on_target;
|
$arr[$ss_player_id]['shots_blocked'] += $val->shots_blocked;
|
||||||
$arr[$ss_player_id]['shots_off_target'] += $val->shots_off_target;
|
$arr[$ss_player_id]['total_shots'] += $val->shots_on_target + $val->shots_off_target + $val->shots_blocked;
|
||||||
$arr[$ss_player_id]['shots_blocked'] += $val->shots_blocked;
|
}
|
||||||
$arr[$ss_player_id]['total_shots'] += $val->shots_on_target + $val->shots_off_target + $val->shots_blocked;
|
}
|
||||||
}
|
|
||||||
|
foreach ($players as $value) {
|
||||||
|
if (isset($arr[$value->ss_player_id])) {
|
||||||
|
$arr[$value->ss_player_id]['position'] = $value->position;
|
||||||
|
$arr[$value->ss_player_id]['player_name'] = $value->player_name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,7 +110,6 @@ class LoadPlayerAverages
|
|||||||
public static function array_template(array &$arr, int $ss_player_id)
|
public static function array_template(array &$arr, int $ss_player_id)
|
||||||
{
|
{
|
||||||
$arr[$ss_player_id]['ss_player_id'] = 0;
|
$arr[$ss_player_id]['ss_player_id'] = 0;
|
||||||
$arr[$ss_player_id]['season'] = '';
|
|
||||||
$arr[$ss_player_id]['total_events'] = 0;
|
$arr[$ss_player_id]['total_events'] = 0;
|
||||||
$arr[$ss_player_id]['total_min'] = 0;
|
$arr[$ss_player_id]['total_min'] = 0;
|
||||||
$arr[$ss_player_id]['average_min'] = 0;
|
$arr[$ss_player_id]['average_min'] = 0;
|
||||||
|
|||||||
@@ -9,12 +9,10 @@ use App\Filament\Widgets\PlayerProps\LineUpMap;
|
|||||||
use App\Filament\Widgets\PlayerProps\PositionHirarchie;
|
use App\Filament\Widgets\PlayerProps\PositionHirarchie;
|
||||||
use App\Livewire\PlayerCalculator;
|
use App\Livewire\PlayerCalculator;
|
||||||
use App\Models\ExpectedMinimumPosition;
|
use App\Models\ExpectedMinimumPosition;
|
||||||
use App\Models\SofaScorePlayerPerSeason;
|
|
||||||
use App\Models\SofaScorePlayerPosition;
|
use App\Models\SofaScorePlayerPosition;
|
||||||
use App\Models\SofaScoreRosa;
|
use App\Models\SofaScoreRosa;
|
||||||
use App\Models\SsLineupMemory;
|
use App\Models\SsLineupMemory;
|
||||||
use App\Models\StatisticFixtures;
|
use App\Models\StatisticFixtures;
|
||||||
use App\Models\StatistikoDetail;
|
|
||||||
use Filament\Notifications\Notification;
|
use Filament\Notifications\Notification;
|
||||||
use Filament\Widgets\Widget;
|
use Filament\Widgets\Widget;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
@@ -392,24 +390,19 @@ class PlayerPropsDrop extends Widget
|
|||||||
$team_home_away = 'away';
|
$team_home_away = 'away';
|
||||||
}
|
}
|
||||||
|
|
||||||
// $player_totals = LoadPlayerAverages::load($team_id, 'total');
|
$players = LoadPlayerAverages::load($team_id, 'total');
|
||||||
|
|
||||||
$team_player_ids = StatistikoDetail::where('ss_team_id', $team_id)->pluck('ss_player_id')->toArray();
|
|
||||||
$player_totals = SofaScorePlayerPerSeason::with('details')->where('season', 'total')->whereIn('ss_player_id', $team_player_ids)->get();
|
|
||||||
|
|
||||||
$count_player = 0;
|
$count_player = 0;
|
||||||
$tmp = [];
|
foreach ($players as $ss_player_id => $value) {
|
||||||
foreach ($player_totals as $ss_player_id => $value) {
|
if ($value['position'] != 'GK') {
|
||||||
$tmp[] = $ss_player_id;
|
|
||||||
if ($value->details != null && $value->details->position != 'GK' && (int) $value->details->is_active) {
|
|
||||||
$count_player++;
|
$count_player++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$results = [];
|
$results = [];
|
||||||
|
|
||||||
foreach ($player_totals as $val) {
|
foreach ($players as $val) {
|
||||||
if ($val->details != null && $val->details->position != 'GK' && (int) $val->details->is_active) {
|
if ($val['position'] != 'GK') {
|
||||||
|
|
||||||
/***
|
/***
|
||||||
"goals" => 0
|
"goals" => 0
|
||||||
@@ -421,12 +414,12 @@ class PlayerPropsDrop extends Widget
|
|||||||
"total_shots" => 4
|
"total_shots" => 4
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$ss_player_id = $val->ss_player_id;
|
$ss_player_id = $val['ss_player_id'];
|
||||||
$position = $val->details->position;
|
$position = $val['position'];
|
||||||
|
|
||||||
$tmp = [];
|
$tmp = [];
|
||||||
$tmp['id'] = $ss_player_id;
|
$tmp['id'] = $ss_player_id;
|
||||||
$tmp['name'] = $val->details->player_name;
|
$tmp['name'] = $val['player_name'];
|
||||||
|
|
||||||
$tmp['id_team'] = $team_id;
|
$tmp['id_team'] = $team_id;
|
||||||
$tmp['asp_team'] = $asp_team;
|
$tmp['asp_team'] = $asp_team;
|
||||||
@@ -446,10 +439,10 @@ class PlayerPropsDrop extends Widget
|
|||||||
// Il valore Y dovrebbe essere configurabile in una interfaccia. Il valore iniziale lo fissiamo a Y = 180
|
// Il valore Y dovrebbe essere configurabile in una interfaccia. Il valore iniziale lo fissiamo a Y = 180
|
||||||
|
|
||||||
// Somma Minuti Giocati da Player (SMG) nel DB
|
// Somma Minuti Giocati da Player (SMG) nel DB
|
||||||
$tmp['somma_minuti'] = $val->total_min;
|
$tmp['somma_minuti'] = $val['total_min'];
|
||||||
$tmp['shots_on_target'] = $val->shots_on_target;
|
$tmp['shots_on_target'] = $val['shots_on_target'];
|
||||||
$tmp['shots_off_target'] = $val->shots_off_target;
|
$tmp['shots_off_target'] = $val['shots_off_target'];
|
||||||
$tmp['shots_blocked'] = $val->shots_blocked;
|
$tmp['shots_blocked'] = $val['shots_blocked'];
|
||||||
|
|
||||||
// il valore corrispondente al ruolo del Player (esempio un giocatore in Details ha ruolo = RW
|
// il valore corrispondente al ruolo del Player (esempio un giocatore in Details ha ruolo = RW
|
||||||
// quindi Aspettativa Statistica (AS) per RW = 0.219)
|
// quindi Aspettativa Statistica (AS) per RW = 0.219)
|
||||||
@@ -479,8 +472,8 @@ class PlayerPropsDrop extends Widget
|
|||||||
|
|
||||||
switch ($bettype) {
|
switch ($bettype) {
|
||||||
case 'goals':
|
case 'goals':
|
||||||
$asp_gioco = $val->goals / $val->total_min * 90;
|
$asp_gioco = $val['goals'] / $val['total_min'] * 90;
|
||||||
if ($asp_gioco == 0 || $val->total_min < $this->y_value) {
|
if ($asp_gioco == 0 || $val['total_min'] < $this->y_value) {
|
||||||
$tmp['asp_gioco_'.$bettype] = 0;
|
$tmp['asp_gioco_'.$bettype] = 0;
|
||||||
$tmp['asp_teorica_'.$bettype] = $asp_statistica;
|
$tmp['asp_teorica_'.$bettype] = $asp_statistica;
|
||||||
} else {
|
} else {
|
||||||
@@ -489,8 +482,8 @@ class PlayerPropsDrop extends Widget
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'cards':
|
case 'cards':
|
||||||
$asp_gioco = $val->cards / $val->total_min * 90;
|
$asp_gioco = $val['cards'] / $val['total_min'] * 90;
|
||||||
if ($asp_gioco == 0 || $val->total_min < $this->y_value) {
|
if ($asp_gioco == 0 || $val['total_min'] < $this->y_value) {
|
||||||
$tmp['asp_gioco_'.$bettype] = 0;
|
$tmp['asp_gioco_'.$bettype] = 0;
|
||||||
$tmp['asp_teorica_'.$bettype] = $asp_statistica;
|
$tmp['asp_teorica_'.$bettype] = $asp_statistica;
|
||||||
} else {
|
} else {
|
||||||
@@ -499,8 +492,8 @@ class PlayerPropsDrop extends Widget
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'fouls':
|
case 'fouls':
|
||||||
$asp_gioco = $val->fouls / $val->total_min * 90;
|
$asp_gioco = $val['fouls'] / $val['total_min'] * 90;
|
||||||
if ($asp_gioco == 0 || $val->total_min < $this->y_value) {
|
if ($asp_gioco == 0 || $val['total_min'] < $this->y_value) {
|
||||||
$tmp['asp_gioco_'.$bettype] = 0;
|
$tmp['asp_gioco_'.$bettype] = 0;
|
||||||
$tmp['asp_teorica_'.$bettype] = $asp_statistica;
|
$tmp['asp_teorica_'.$bettype] = $asp_statistica;
|
||||||
} else {
|
} else {
|
||||||
@@ -509,8 +502,8 @@ class PlayerPropsDrop extends Widget
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'offsides':
|
case 'offsides':
|
||||||
$asp_gioco = $val->offsides / $val->total_min * 90;
|
$asp_gioco = $val['offsides'] / $val['total_min'] * 90;
|
||||||
if ($asp_gioco == 0 || $val->total_min < $this->y_value) {
|
if ($asp_gioco == 0 || $val['total_min'] < $this->y_value) {
|
||||||
$tmp['asp_gioco_'.$bettype] = 0;
|
$tmp['asp_gioco_'.$bettype] = 0;
|
||||||
$tmp['asp_teorica_'.$bettype] = $asp_statistica;
|
$tmp['asp_teorica_'.$bettype] = $asp_statistica;
|
||||||
} else {
|
} else {
|
||||||
@@ -519,8 +512,8 @@ class PlayerPropsDrop extends Widget
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'total_shots':
|
case 'total_shots':
|
||||||
$asp_gioco = $val->total_shots / $val->total_min * 90;
|
$asp_gioco = $val['total_shots'] / $val['total_min'] * 90;
|
||||||
if ($asp_gioco == 0 || $val->total_min < $this->y_value) {
|
if ($asp_gioco == 0 || $val['total_min'] < $this->y_value) {
|
||||||
$tmp['asp_gioco_'.$bettype] = 0;
|
$tmp['asp_gioco_'.$bettype] = 0;
|
||||||
$tmp['asp_teorica_'.$bettype] = $asp_statistica;
|
$tmp['asp_teorica_'.$bettype] = $asp_statistica;
|
||||||
} else {
|
} else {
|
||||||
@@ -529,8 +522,8 @@ class PlayerPropsDrop extends Widget
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'shots_on_target':
|
case 'shots_on_target':
|
||||||
$asp_gioco = $val->shots_on_target / $val->total_min * 90;
|
$asp_gioco = $val['shots_on_target'] / $val['total_min'] * 90;
|
||||||
if ($asp_gioco == 0 || $val->total_min < $this->y_value) {
|
if ($asp_gioco == 0 || $val['total_min'] < $this->y_value) {
|
||||||
$tmp['asp_gioco_'.$bettype] = 0;
|
$tmp['asp_gioco_'.$bettype] = 0;
|
||||||
$tmp['asp_teorica_'.$bettype] = $asp_statistica;
|
$tmp['asp_teorica_'.$bettype] = $asp_statistica;
|
||||||
} else {
|
} else {
|
||||||
@@ -629,41 +622,43 @@ class PlayerPropsDrop extends Widget
|
|||||||
$pos = $this->players[$k]['pos_ori'];
|
$pos = $this->players[$k]['pos_ori'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$tamx = number_format($map[$pos]['gls'], 3);
|
if ($pos != 'GK') {
|
||||||
$final = number_format($result['asp_player_goals'], 3);
|
$tamx = number_format($map[$pos]['gls'], 3);
|
||||||
$results[$key]['finale_tamx_gls'] = $tamx;
|
$final = number_format($result['asp_player_goals'], 3);
|
||||||
$results[$key]['finale_calc_gls'] = $final;
|
$results[$key]['finale_tamx_gls'] = $tamx;
|
||||||
$this->players[$k]['gls'] = (float) $final > (float) $tamx ? $final : $tamx;
|
$results[$key]['finale_calc_gls'] = $final;
|
||||||
|
$this->players[$k]['gls'] = (float) $final > (float) $tamx ? $final : $tamx;
|
||||||
|
|
||||||
$tamx = number_format($map[$pos]['crd'], 3);
|
$tamx = number_format($map[$pos]['crd'], 3);
|
||||||
$final = number_format($result['asp_player_cards'], 3);
|
$final = number_format($result['asp_player_cards'], 3);
|
||||||
$results[$key]['finale_tamx_crd'] = $tamx;
|
$results[$key]['finale_tamx_crd'] = $tamx;
|
||||||
$results[$key]['finale_calc_crd'] = $final;
|
$results[$key]['finale_calc_crd'] = $final;
|
||||||
$this->players[$k]['crd'] = (float) $final > (float) $tamx ? $final : $tamx;
|
$this->players[$k]['crd'] = (float) $final > (float) $tamx ? $final : $tamx;
|
||||||
|
|
||||||
$tamx = number_format($map[$pos]['fls'], 3);
|
$tamx = number_format($map[$pos]['fls'], 3);
|
||||||
$final = number_format($result['asp_player_fouls'], 3);
|
$final = number_format($result['asp_player_fouls'], 3);
|
||||||
$results[$key]['finale_tamx_fls'] = $tamx;
|
$results[$key]['finale_tamx_fls'] = $tamx;
|
||||||
$results[$key]['finale_calc_fls'] = $final;
|
$results[$key]['finale_calc_fls'] = $final;
|
||||||
$this->players[$k]['fls'] = (float) $final > (float) $tamx ? $final : $tamx;
|
$this->players[$k]['fls'] = (float) $final > (float) $tamx ? $final : $tamx;
|
||||||
|
|
||||||
$tamx = number_format($map[$pos]['ofs'], 3);
|
$tamx = number_format($map[$pos]['ofs'], 3);
|
||||||
$final = number_format($result['asp_player_offsides'], 3);
|
$final = number_format($result['asp_player_offsides'], 3);
|
||||||
$results[$key]['finale_tamx_ofs'] = $tamx;
|
$results[$key]['finale_tamx_ofs'] = $tamx;
|
||||||
$results[$key]['finale_calc_ofs'] = $final;
|
$results[$key]['finale_calc_ofs'] = $final;
|
||||||
$this->players[$k]['ofs'] = (float) $final > (float) $tamx ? $final : $tamx;
|
$this->players[$k]['ofs'] = (float) $final > (float) $tamx ? $final : $tamx;
|
||||||
|
|
||||||
$tamx = number_format($map[$pos]['tsh'], 3);
|
$tamx = number_format($map[$pos]['tsh'], 3);
|
||||||
$final = number_format($result['asp_player_total_shots'], 3);
|
$final = number_format($result['asp_player_total_shots'], 3);
|
||||||
$results[$key]['finale_tamx_tsh'] = $tamx;
|
$results[$key]['finale_tamx_tsh'] = $tamx;
|
||||||
$results[$key]['finale_calc_tsh'] = $final;
|
$results[$key]['finale_calc_tsh'] = $final;
|
||||||
$this->players[$k]['tsh'] = (float) $final > (float) $tamx ? $final : $tamx;
|
$this->players[$k]['tsh'] = (float) $final > (float) $tamx ? $final : $tamx;
|
||||||
|
|
||||||
$tamx = number_format($map[$pos]['snt'], 3);
|
$tamx = number_format($map[$pos]['snt'], 3);
|
||||||
$final = number_format($result['asp_player_shots_on_target'], 3);
|
$final = number_format($result['asp_player_shots_on_target'], 3);
|
||||||
$results[$key]['finale_tamx_snt'] = $tamx;
|
$results[$key]['finale_tamx_snt'] = $tamx;
|
||||||
$results[$key]['finale_calc_snt'] = $final;
|
$results[$key]['finale_calc_snt'] = $final;
|
||||||
$this->players[$k]['snt'] = (float) $final > (float) $tamx ? $final : $tamx;
|
$this->players[$k]['snt'] = (float) $final > (float) $tamx ? $final : $tamx;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -687,18 +682,16 @@ class PlayerPropsDrop extends Widget
|
|||||||
|
|
||||||
public function prepareLineUp()
|
public function prepareLineUp()
|
||||||
{
|
{
|
||||||
$team_player_ids = StatistikoDetail::where('ss_team_id', $this->team_id)->pluck('ss_player_id')->toArray();
|
$players = LoadPlayerAverages::load($this->team_id, 'last180days');
|
||||||
|
|
||||||
$players = SofaScorePlayerPerSeason::with('details')->where('season', 'last_180_days')->whereIn('ss_player_id', $team_player_ids)->get();
|
|
||||||
|
|
||||||
$arr = collect();
|
$arr = collect();
|
||||||
foreach ($players as $value) {
|
foreach ($players as $value) {
|
||||||
if ($value?->details->position ?? 0) {
|
if ($value['position'] != '') {
|
||||||
$arr->push([
|
$arr->push([
|
||||||
'id' => $value->ss_player_id,
|
'id' => $value['ss_player_id'],
|
||||||
'min' => $value->average_min,
|
'min' => $value['average_min'],
|
||||||
'pos' => $value->details->position,
|
'pos' => $value['position'],
|
||||||
'name' => $value->details->player_name,
|
'name' => $value['player_name'],
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,8 +3,7 @@
|
|||||||
namespace App\Livewire;
|
namespace App\Livewire;
|
||||||
|
|
||||||
use App\Filament\Pages\Selections\LoadPositions;
|
use App\Filament\Pages\Selections\LoadPositions;
|
||||||
use App\Models\SofaScorePlayerPerSeason;
|
use App\Filament\Widgets\Boxes\LoadPlayerAverages;
|
||||||
use App\Models\StatistikoDetail;
|
|
||||||
use Livewire\Component;
|
use Livewire\Component;
|
||||||
|
|
||||||
class PlayerCalculator extends Component
|
class PlayerCalculator extends Component
|
||||||
@@ -13,86 +12,76 @@ class PlayerCalculator extends Component
|
|||||||
{
|
{
|
||||||
$positions_map = LoadPositions::load();
|
$positions_map = LoadPositions::load();
|
||||||
|
|
||||||
$team_player_ids = StatistikoDetail::where('ss_team_id', $team_id)->pluck('ss_player_id')->toArray();
|
$players = LoadPlayerAverages::load($team_id, 'total');
|
||||||
|
|
||||||
$players = SofaScorePlayerPerSeason::with('details')->where('season', 'total')->whereIn('ss_player_id', $team_player_ids)->get();
|
|
||||||
|
|
||||||
$result = [];
|
$result = [];
|
||||||
foreach ($players as $val) {
|
foreach ($players as $val) {
|
||||||
if ($val->details != null && $val->details->is_active) {
|
|
||||||
|
|
||||||
$tmp = [];
|
$tmp = [];
|
||||||
$tmp['id'] = $val->ss_player_id;
|
$tmp['id'] = $val['ss_player_id'];
|
||||||
if (! isset($val->details)) {
|
if (! isset($val->details)) {
|
||||||
$tmp['name'] = $val->ss_player_id;
|
$tmp['name'] = $val['ss_player_id'];
|
||||||
$tmp['pos_ori'] = 'GK';
|
$tmp['pos_ori'] = 'GK';
|
||||||
$tmp['foot'] = 'Both';
|
$tmp['foot'] = 'Both';
|
||||||
|
} else {
|
||||||
|
$tmp['name'] = $val['player_name'];
|
||||||
|
$tmp['pos_ori'] = $val['position'];
|
||||||
|
$tmp['foot'] = $val['preferred_foot'];
|
||||||
|
}
|
||||||
|
$tmp['pos'] = '';
|
||||||
|
$tmp['active'] = 0;
|
||||||
|
$tmp['tot_evt'] = $val['total_events'];
|
||||||
|
$tmp['tot_min'] = $val['total_min'];
|
||||||
|
$tmp['ave_min'] = $val['average_min'];
|
||||||
|
$tmp['gls'] = $val['goals'];
|
||||||
|
$tmp['fls'] = $val['fouls'];
|
||||||
|
$tmp['ofs'] = $val['offsides'];
|
||||||
|
$tmp['crd'] = $val['cards'];
|
||||||
|
$tmp['snt'] = $val['shots_on_target'];
|
||||||
|
$tmp['tsh'] = $val['shots_off_target'];
|
||||||
|
|
||||||
|
$level = round($val['total_events'] / 3);
|
||||||
|
if ($val['total_events']) {
|
||||||
|
if ($level > 1 && $val['total_events'] < $level) {
|
||||||
|
$tmp['color_evt'] = 'danger';
|
||||||
|
} elseif ($val['total_events'] < $level * 2) {
|
||||||
|
$tmp['color_evt'] = 'info';
|
||||||
} else {
|
} else {
|
||||||
$tmp['name'] = $val->details->player_name;
|
$tmp['color_evt'] = 'success';
|
||||||
$tmp['pos_ori'] = $val->details->position;
|
|
||||||
$tmp['foot'] = $val->details->preferred_foot;
|
|
||||||
}
|
}
|
||||||
$tmp['pos'] = '';
|
}
|
||||||
$tmp['active'] = 0;
|
|
||||||
$tmp['tot_evt'] = $val->total_events;
|
|
||||||
$tmp['tot_min'] = $val->total_min;
|
|
||||||
$tmp['ave_min'] = $val->average_min;
|
|
||||||
$tmp['gls'] = $val->goals;
|
|
||||||
$tmp['fls'] = $val->fouls;
|
|
||||||
$tmp['ofs'] = $val->offsides;
|
|
||||||
$tmp['crd'] = $val->cards;
|
|
||||||
$tmp['snt'] = $val->shots_on_target;
|
|
||||||
$tmp['tsh'] = $val->shots_off_target;
|
|
||||||
|
|
||||||
$level = round($val->total_events / 3);
|
if (! isset($val->details)) {
|
||||||
if ($val->total_events) {
|
$tmp['area'] = 'goalkeeper';
|
||||||
if ($level > 1 && $val->total_events < $level) {
|
$tmp['color_pos'] = 'gray';
|
||||||
$tmp['color_evt'] = 'danger';
|
$tmp['order'] = 5;
|
||||||
} elseif ($val->total_events < $level * 2) {
|
} else {
|
||||||
$tmp['color_evt'] = 'info';
|
if (in_array($val['position'], $positions_map['MIDFIELD'])) {
|
||||||
} else {
|
$tmp['area'] = 'midfield';
|
||||||
$tmp['color_evt'] = 'success';
|
$tmp['color_pos'] = 'info';
|
||||||
}
|
$tmp['order'] = 2;
|
||||||
}
|
} elseif (in_array($val['position'], $positions_map['DEFENCE'])) {
|
||||||
|
$tmp['area'] = 'defence';
|
||||||
if (! isset($val->details)) {
|
$tmp['color_pos'] = 'success';
|
||||||
|
$tmp['order'] = 1;
|
||||||
|
} elseif (in_array($val['position'], $positions_map['ATTACK'])) {
|
||||||
|
$tmp['area'] = 'attack';
|
||||||
|
$tmp['color_pos'] = 'warning';
|
||||||
|
$tmp['order'] = 3;
|
||||||
|
} elseif (in_array($val['position'], $positions_map['GOALKEEPER'])) {
|
||||||
$tmp['area'] = 'goalkeeper';
|
$tmp['area'] = 'goalkeeper';
|
||||||
$tmp['color_pos'] = 'gray';
|
$tmp['color_pos'] = 'gray';
|
||||||
$tmp['order'] = 5;
|
$tmp['order'] = 4;
|
||||||
} else {
|
} else {
|
||||||
if (in_array($val->details->position, $positions_map['MIDFIELD'])) {
|
$tmp['area'] = 'defence';
|
||||||
$tmp['area'] = 'midfield';
|
$tmp['color_pos'] = 'success';
|
||||||
$tmp['color_pos'] = 'info';
|
$tmp['order'] = 5;
|
||||||
$tmp['order'] = 2;
|
|
||||||
} elseif (in_array($val->details->position, $positions_map['DEFENCE'])) {
|
|
||||||
$tmp['area'] = 'defence';
|
|
||||||
$tmp['color_pos'] = 'success';
|
|
||||||
$tmp['order'] = 1;
|
|
||||||
} elseif (in_array($val->details->position, $positions_map['ATTACK'])) {
|
|
||||||
$tmp['area'] = 'attack';
|
|
||||||
$tmp['color_pos'] = 'warning';
|
|
||||||
$tmp['order'] = 3;
|
|
||||||
} elseif (in_array($val->details->position, $positions_map['GOALKEEPER'])) {
|
|
||||||
$tmp['area'] = 'goalkeeper';
|
|
||||||
$tmp['color_pos'] = 'gray';
|
|
||||||
$tmp['order'] = 4;
|
|
||||||
} else {
|
|
||||||
$tmp['area'] = 'defence';
|
|
||||||
$tmp['color_pos'] = 'success';
|
|
||||||
$tmp['order'] = 5;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$result[] = $tmp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$result[] = $tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
// dd($result);
|
|
||||||
|
|
||||||
// $pos = array_column($result, 'pos');
|
|
||||||
// $area = array_column($result, 'area');
|
|
||||||
// array_multisort($area, SORT_ASC, $pos, SORT_ASC, $result);
|
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Models;
|
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
|
||||||
|
|
||||||
class SofaScorePlayerPerSeason extends Model
|
|
||||||
{
|
|
||||||
protected $table = 'ss_player_seasons';
|
|
||||||
|
|
||||||
protected $fillable = [
|
|
||||||
'ss_player_id',
|
|
||||||
'ss_team_id',
|
|
||||||
'season',
|
|
||||||
'total_events',
|
|
||||||
'total_min',
|
|
||||||
'average_min',
|
|
||||||
'events_played_home',
|
|
||||||
'events_played_away',
|
|
||||||
'minutes_played_home',
|
|
||||||
'minutes_played_away',
|
|
||||||
'goals',
|
|
||||||
'fouls',
|
|
||||||
'cards',
|
|
||||||
'offsides',
|
|
||||||
'shots_on_target',
|
|
||||||
'shots_off_target',
|
|
||||||
'shots_blocked',
|
|
||||||
'total_shots',
|
|
||||||
];
|
|
||||||
|
|
||||||
public function details()
|
|
||||||
{
|
|
||||||
return $this->belongsTo(StatistikoDetail::class, 'ss_player_id', 'ss_player_id');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -32,11 +32,6 @@ class StatistikoDetail extends Model
|
|||||||
'last_update' => 'datetime',
|
'last_update' => 'datetime',
|
||||||
];
|
];
|
||||||
|
|
||||||
// public function season()
|
|
||||||
// {
|
|
||||||
// return $this->hasMany(SofaScorePlayerPerSeason::class, 'ss_player_id', 'ss_player_id');
|
|
||||||
// }
|
|
||||||
|
|
||||||
public function team(): BelongsTo
|
public function team(): BelongsTo
|
||||||
{
|
{
|
||||||
return $this->belongsTo(SofaScoreRosa::class, 'ss_team_id', 'ss_team_id');
|
return $this->belongsTo(SofaScoreRosa::class, 'ss_team_id', 'ss_team_id');
|
||||||
|
|||||||
@@ -1,319 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Traits;
|
|
||||||
|
|
||||||
use App\Mail\SimpleMail;
|
|
||||||
use App\Models\SofaScorePlayerPerSeason;
|
|
||||||
use App\Models\StatistikoDetail;
|
|
||||||
use App\Models\StatistikoPlayer;
|
|
||||||
use App\Utilities\Notice;
|
|
||||||
use Illuminate\Support\Facades\DB;
|
|
||||||
use Illuminate\Support\Facades\Mail;
|
|
||||||
use Illuminate\Support\Str;
|
|
||||||
|
|
||||||
use function Laravel\Prompts\select;
|
|
||||||
|
|
||||||
trait UpdateHelper
|
|
||||||
{
|
|
||||||
protected float $benchmarkStartTime;
|
|
||||||
|
|
||||||
protected int $benchmarkStartMemory;
|
|
||||||
|
|
||||||
protected int $startRowCount;
|
|
||||||
|
|
||||||
protected int $startQueries;
|
|
||||||
|
|
||||||
protected int $debug;
|
|
||||||
|
|
||||||
public function handle(): void
|
|
||||||
{
|
|
||||||
error_reporting(E_ALL);
|
|
||||||
ini_set('memory_limit', '2048M');
|
|
||||||
ini_set('display_errors', 1);
|
|
||||||
/**
|
|
||||||
* ps aux | grep artisan
|
|
||||||
* kill -9 12345
|
|
||||||
*/
|
|
||||||
$tmp = $this->options();
|
|
||||||
$this->debug = $tmp['d'] ?? 0;
|
|
||||||
|
|
||||||
if ($this->debug) {
|
|
||||||
Notice::note('Update Player Season', 'g');
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->debug) {
|
|
||||||
$playerCount = $this->selectPlayer();
|
|
||||||
} else {
|
|
||||||
$playerCount = 1000000;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->debug) {
|
|
||||||
$this->startBenchmark();
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
$this->updatePlayers($playerCount);
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
$this->error(get_class($e).' '.Str::of($e->getMessage())->limit(100)->value());
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->debug) {
|
|
||||||
$this->endBenchmark();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Flight::upsert([
|
|
||||||
// ['departure' => 'Oakland', 'destination' => 'San Diego', 'price' => 99],
|
|
||||||
// ['departure' => 'Chicago', 'destination' => 'New York', 'price' => 150]
|
|
||||||
// ], uniqueBy: ['departure', 'destination'], update: ['price']);
|
|
||||||
|
|
||||||
protected function selectPlayer(): string
|
|
||||||
{
|
|
||||||
$file = select(
|
|
||||||
label: 'How many players to update?',
|
|
||||||
options: ['100 Player', '1k Player', '10k Player', '100k Player', '1m Player']
|
|
||||||
);
|
|
||||||
|
|
||||||
return match ($file) {
|
|
||||||
'100 Player' => 100,
|
|
||||||
'1k Player' => 1000,
|
|
||||||
'10k Player' => 10000,
|
|
||||||
'100k Player' => 100000,
|
|
||||||
'1m Player' => 1000000,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function startBenchmark(string $table = 'ss_player_seasons'): void
|
|
||||||
{
|
|
||||||
$this->startRowCount = DB::table($table)->count();
|
|
||||||
$this->benchmarkStartTime = microtime(true);
|
|
||||||
$this->benchmarkStartMemory = memory_get_usage();
|
|
||||||
DB::enableQueryLog();
|
|
||||||
$this->startQueries = DB::select("SHOW SESSION STATUS LIKE 'Questions'")[0]->Value;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function endBenchmark(string $table = 'ss_player_seasons'): void
|
|
||||||
{
|
|
||||||
$executionTime = microtime(true) - $this->benchmarkStartTime;
|
|
||||||
$memoryUsage = round((memory_get_usage() - $this->benchmarkStartMemory) / 1024 / 1024, 2);
|
|
||||||
$queriesCount = DB::select("SHOW SESSION STATUS LIKE 'Questions'")[0]->Value - $this->startQueries - 1; // Subtract the Questions query itself
|
|
||||||
|
|
||||||
// Get row count after we've stopped tracking queries
|
|
||||||
$rowDiff = DB::table($table)->count() - $this->startRowCount;
|
|
||||||
|
|
||||||
$formattedTime = match (true) {
|
|
||||||
$executionTime >= 60 => sprintf('%dm %ds', floor($executionTime / 60), $executionTime % 60),
|
|
||||||
$executionTime >= 1 => round($executionTime, 2).'s',
|
|
||||||
default => round($executionTime * 1000).'ms',
|
|
||||||
};
|
|
||||||
|
|
||||||
$this->newLine();
|
|
||||||
$this->line(sprintf(
|
|
||||||
'⚡ <bg=bright-cyan;fg=black> TIME: %s </> <bg=bright-green;fg=black> MEM: %sMB </> <bg=bright-yellow;fg=black> SQL: %s </> <bg=bright-magenta;fg=black> ROWS: %s </>',
|
|
||||||
$formattedTime,
|
|
||||||
$memoryUsage,
|
|
||||||
number_format($queriesCount),
|
|
||||||
number_format($rowDiff)
|
|
||||||
));
|
|
||||||
$this->newLine();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function updatePlayers(int $playerCount)
|
|
||||||
{
|
|
||||||
$res_player = StatistikoDetail::query()->where('is_active', 1)->limit($playerCount)->pluck('ss_player_id')->toArray();
|
|
||||||
|
|
||||||
$chunks = array_chunk($res_player, 500);
|
|
||||||
|
|
||||||
foreach ($chunks as $chunk) {
|
|
||||||
|
|
||||||
if ($this->debug) {
|
|
||||||
echo '#';
|
|
||||||
}
|
|
||||||
|
|
||||||
$res = StatistikoPlayer::with('event')->with('details')->whereIn('ss_player_id', $chunk)->orderBy('ss_player_id')->get();
|
|
||||||
|
|
||||||
$collection = [];
|
|
||||||
foreach ($res as $val) {
|
|
||||||
|
|
||||||
if (isset($val->event) && $val->ss_player_id != 0) {
|
|
||||||
|
|
||||||
$ss_player_id = (int) $val->ss_player_id;
|
|
||||||
$activeteam_id = (int) $val->activeteam_id;
|
|
||||||
$minutes_played = (int) $val->minutes_played;
|
|
||||||
$season = $val->event->season;
|
|
||||||
$home_id = (int) $val->event->home_id;
|
|
||||||
$away_id = (int) $val->event->away_id;
|
|
||||||
$startime = $val->event->starttime;
|
|
||||||
|
|
||||||
if ($startime->greaterThan(now()->subDays(180))) {
|
|
||||||
$last_180_days = true;
|
|
||||||
} else {
|
|
||||||
$last_180_days = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (! isset($collection[$season][$ss_player_id])) {
|
|
||||||
$this->array_template($collection, $ss_player_id, $season);
|
|
||||||
}
|
|
||||||
if (! isset($collection['total'][$ss_player_id])) {
|
|
||||||
$this->array_template($collection, $ss_player_id, 'total');
|
|
||||||
}
|
|
||||||
if (! isset($collection['last_180_days'][$ss_player_id])) {
|
|
||||||
$this->array_template($collection, $ss_player_id, 'last_180_days');
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($minutes_played > 0) {
|
|
||||||
if ($activeteam_id == $home_id) {
|
|
||||||
$collection[$season][$ss_player_id]['events_played_home'] += 1;
|
|
||||||
$collection[$season][$ss_player_id]['minutes_played_home'] += $minutes_played;
|
|
||||||
$collection['total'][$ss_player_id]['events_played_home'] += 1;
|
|
||||||
$collection['total'][$ss_player_id]['minutes_played_home'] += $minutes_played;
|
|
||||||
if ($last_180_days) {
|
|
||||||
$collection['last_180_days'][$ss_player_id]['events_played_home'] += 1;
|
|
||||||
$collection['last_180_days'][$ss_player_id]['minutes_played_home'] += $minutes_played;
|
|
||||||
}
|
|
||||||
} elseif ($activeteam_id == $away_id) {
|
|
||||||
$collection[$season][$ss_player_id]['events_played_away'] += 1;
|
|
||||||
$collection[$season][$ss_player_id]['minutes_played_away'] += $minutes_played;
|
|
||||||
$collection['total'][$ss_player_id]['events_played_away'] += 1;
|
|
||||||
$collection['total'][$ss_player_id]['minutes_played_away'] += $minutes_played;
|
|
||||||
if ($last_180_days) {
|
|
||||||
$collection['last_180_days'][$ss_player_id]['events_played_away'] += 1;
|
|
||||||
$collection['last_180_days'][$ss_player_id]['minutes_played_away'] += $minutes_played;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
// ubaldo 18. Sep 26 intanto vado avanti, appena trovo qwuaqlcosa ti scrivo, tu togli i red cards dal conteggio
|
|
||||||
$cards = $val->card_yellow + $val->card_yellowred;
|
|
||||||
|
|
||||||
$collection[$season][$ss_player_id]['ss_player_id'] = $ss_player_id;
|
|
||||||
$collection[$season][$ss_player_id]['season'] = $season;
|
|
||||||
$collection[$season][$ss_player_id]['total_events']++;
|
|
||||||
$collection[$season][$ss_player_id]['total_min'] += $minutes_played;
|
|
||||||
$collection[$season][$ss_player_id]['average_min'] = round($collection[$season][$ss_player_id]['total_min'] / $collection[$season][$ss_player_id]['total_events']);
|
|
||||||
$collection[$season][$ss_player_id]['goals'] += $val->goals;
|
|
||||||
$collection[$season][$ss_player_id]['fouls'] += $val->fouls;
|
|
||||||
$collection[$season][$ss_player_id]['cards'] += $cards;
|
|
||||||
$collection[$season][$ss_player_id]['offsides'] += $val->offsides;
|
|
||||||
$collection[$season][$ss_player_id]['shots_on_target'] += $val->shots_on_target;
|
|
||||||
$collection[$season][$ss_player_id]['shots_off_target'] += $val->shots_off_target;
|
|
||||||
$collection[$season][$ss_player_id]['shots_blocked'] += $val->shots_blocked;
|
|
||||||
$collection[$season][$ss_player_id]['total_shots'] += $val->shots_on_target + $val->shots_off_target + $val->shots_blocked;
|
|
||||||
|
|
||||||
$collection['total'][$ss_player_id]['ss_player_id'] = $ss_player_id;
|
|
||||||
$collection['total'][$ss_player_id]['season'] = 'total';
|
|
||||||
$collection['total'][$ss_player_id]['total_events']++;
|
|
||||||
$collection['total'][$ss_player_id]['total_min'] += $minutes_played;
|
|
||||||
$collection['total'][$ss_player_id]['average_min'] = round($collection['total'][$ss_player_id]['total_min'] / $collection['total'][$ss_player_id]['total_events']);
|
|
||||||
$collection['total'][$ss_player_id]['goals'] += $val->goals;
|
|
||||||
$collection['total'][$ss_player_id]['fouls'] += $val->fouls;
|
|
||||||
$collection['total'][$ss_player_id]['cards'] += $cards;
|
|
||||||
$collection['total'][$ss_player_id]['offsides'] += $val->offsides;
|
|
||||||
$collection['total'][$ss_player_id]['shots_on_target'] += $val->shots_on_target;
|
|
||||||
$collection['total'][$ss_player_id]['shots_off_target'] += $val->shots_off_target;
|
|
||||||
$collection['total'][$ss_player_id]['shots_blocked'] += $val->shots_blocked;
|
|
||||||
$collection['total'][$ss_player_id]['total_shots'] += $val->shots_on_target + $val->shots_off_target + $val->shots_blocked;
|
|
||||||
|
|
||||||
if ($last_180_days) {
|
|
||||||
$collection['last_180_days'][$ss_player_id]['ss_player_id'] = $ss_player_id;
|
|
||||||
$collection['last_180_days'][$ss_player_id]['season'] = 'last_180_days';
|
|
||||||
$collection['last_180_days'][$ss_player_id]['total_events']++;
|
|
||||||
$collection['last_180_days'][$ss_player_id]['total_min'] += $minutes_played;
|
|
||||||
$collection['last_180_days'][$ss_player_id]['average_min'] = round($collection['last_180_days'][$ss_player_id]['total_min'] / $collection['last_180_days'][$ss_player_id]['total_events']);
|
|
||||||
$collection['last_180_days'][$ss_player_id]['goals'] += $val->goals;
|
|
||||||
$collection['last_180_days'][$ss_player_id]['fouls'] += $val->fouls;
|
|
||||||
$collection['last_180_days'][$ss_player_id]['cards'] += $cards;
|
|
||||||
$collection['last_180_days'][$ss_player_id]['offsides'] += $val->offsides;
|
|
||||||
$collection['last_180_days'][$ss_player_id]['shots_on_target'] += $val->shots_on_target;
|
|
||||||
$collection['last_180_days'][$ss_player_id]['shots_off_target'] += $val->shots_off_target;
|
|
||||||
$collection['last_180_days'][$ss_player_id]['shots_blocked'] += $val->shots_blocked;
|
|
||||||
$collection['last_180_days'][$ss_player_id]['total_shots'] += $val->shots_on_target + $val->shots_off_target + $val->shots_blocked;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$collection_1d = [];
|
|
||||||
foreach ($collection as $arr) {
|
|
||||||
foreach ($arr as $row) {
|
|
||||||
$collection_1d[] = $row;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ALTER TABLE ss_player_seasons ADD UNIQUE KEY eindeutiger_index (ss_player_id, season);
|
|
||||||
|
|
||||||
SofaScorePlayerPerSeason::upsert(
|
|
||||||
$collection_1d,
|
|
||||||
uniqueBy: [
|
|
||||||
'ss_player_id',
|
|
||||||
'season',
|
|
||||||
],
|
|
||||||
update: [
|
|
||||||
'total_events',
|
|
||||||
'total_min',
|
|
||||||
'average_min',
|
|
||||||
'events_played_home',
|
|
||||||
'events_played_away',
|
|
||||||
'minutes_played_home',
|
|
||||||
'minutes_played_away',
|
|
||||||
'goals',
|
|
||||||
'fouls',
|
|
||||||
'offsides',
|
|
||||||
'shots_on_target',
|
|
||||||
'shots_off_target',
|
|
||||||
'shots_blocked',
|
|
||||||
'total_shots',
|
|
||||||
'cards',
|
|
||||||
]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 1. Finde alle Kombinationen, die mehrfach existieren
|
|
||||||
$duplicates = DB::table('ss_player_seasons')
|
|
||||||
->select('season', 'ss_player_id', DB::raw('COUNT(*) as count'))
|
|
||||||
->groupBy('season', 'ss_player_id')
|
|
||||||
->having('count', '>', 1)
|
|
||||||
->get();
|
|
||||||
|
|
||||||
// 2. Schleife durch die Duplikate und lösche die überschüssigen
|
|
||||||
foreach ($duplicates as $duplicate) {
|
|
||||||
// Hol dir alle IDs für diese spezifische Kombination, sortiert nach ID
|
|
||||||
$ids = SofaScorePlayerPerSeason::where('season', $duplicate->season)
|
|
||||||
->where('ss_player_id', $duplicate->ss_player_id)
|
|
||||||
->orderBy('id', 'asc')
|
|
||||||
->pluck('id');
|
|
||||||
|
|
||||||
// Behalte die erste ID (Index 0) und hole alle anderen
|
|
||||||
$idsToDelete = $ids->slice(1);
|
|
||||||
|
|
||||||
// Lösche die überflüssigen IDs aus der Datenbank
|
|
||||||
SofaScorePlayerPerSeason::whereIn('id', $idsToDelete)->delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
SofaScorePlayerPerSeason::where('ss_player_id', 0)->delete();
|
|
||||||
SofaScorePlayerPerSeason::where('season', null)->delete();
|
|
||||||
|
|
||||||
// Mail::to('hermann.telser@gmail.com')->send(new SimpleMail('STATISTIKO', 'Pre Calculation Completed'));
|
|
||||||
Mail::to(['hermann.telser@gmail.com', 'ubaldo.perrucci@gmail.com'])->send(new SimpleMail('STATISTIKO', 'Pre Calculation Completed'));
|
|
||||||
}
|
|
||||||
|
|
||||||
private function array_template(array &$collection, int $ss_player_id, string $season)
|
|
||||||
{
|
|
||||||
$collection[$season][$ss_player_id]['ss_player_id'] = 0;
|
|
||||||
$collection[$season][$ss_player_id]['season'] = '';
|
|
||||||
$collection[$season][$ss_player_id]['total_events'] = 0;
|
|
||||||
$collection[$season][$ss_player_id]['total_min'] = 0;
|
|
||||||
$collection[$season][$ss_player_id]['average_min'] = 0;
|
|
||||||
$collection[$season][$ss_player_id]['events_played_home'] = 0;
|
|
||||||
$collection[$season][$ss_player_id]['events_played_away'] = 0;
|
|
||||||
$collection[$season][$ss_player_id]['minutes_played_home'] = 0;
|
|
||||||
$collection[$season][$ss_player_id]['minutes_played_away'] = 0;
|
|
||||||
$collection[$season][$ss_player_id]['goals'] = 0;
|
|
||||||
$collection[$season][$ss_player_id]['fouls'] = 0;
|
|
||||||
$collection[$season][$ss_player_id]['offsides'] = 0;
|
|
||||||
$collection[$season][$ss_player_id]['shots_on_target'] = 0;
|
|
||||||
$collection[$season][$ss_player_id]['shots_off_target'] = 0;
|
|
||||||
$collection[$season][$ss_player_id]['shots_blocked'] = 0;
|
|
||||||
$collection[$season][$ss_player_id]['total_shots'] = 0;
|
|
||||||
$collection[$season][$ss_player_id]['cards'] = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use Illuminate\Database\Migrations\Migration;
|
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
|
||||||
use Illuminate\Support\Facades\Schema;
|
|
||||||
|
|
||||||
return new class extends Migration
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Run the migrations.
|
|
||||||
*/
|
|
||||||
public function up(): void
|
|
||||||
{
|
|
||||||
Schema::create('ss_player_seasons', function (Blueprint $table) {
|
|
||||||
$table->id();
|
|
||||||
$table->integer('ss_player_id')->index()->default(0);
|
|
||||||
$table->integer('ss_team_id')->index()->default(0);
|
|
||||||
$table->string('season')->index()->default('');
|
|
||||||
$table->integer('total_events')->default(0)->nullable();
|
|
||||||
$table->integer('total_min')->default(0)->nullable();
|
|
||||||
$table->integer('average_min')->default(0)->nullable();
|
|
||||||
$table->integer('events_played_home')->default(0)->nullable();
|
|
||||||
$table->integer('events_played_away')->default(0)->nullable();
|
|
||||||
$table->integer('minutes_played_home')->default(0)->nullable();
|
|
||||||
$table->integer('minutes_played_away')->default(0)->nullable();
|
|
||||||
$table->integer('goals')->default(0)->nullable();
|
|
||||||
$table->integer('fouls')->default(0)->nullable();
|
|
||||||
$table->integer('cards')->default(0)->nullable();
|
|
||||||
$table->integer('offsides')->default(0)->nullable();
|
|
||||||
$table->integer('shots_on_target')->default(0)->nullable();
|
|
||||||
$table->integer('shots_off_target')->default(0)->nullable();
|
|
||||||
$table->integer('shots_blocked')->default(0)->nullable();
|
|
||||||
$table->integer('total_shots')->default(0)->nullable();
|
|
||||||
$table->unique(['ss_player_id', 'season']);
|
|
||||||
$table->timestamps();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reverse the migrations.
|
|
||||||
*/
|
|
||||||
public function down(): void
|
|
||||||
{
|
|
||||||
Schema::dropIfExists('ss_player_seasons');
|
|
||||||
}
|
|
||||||
};
|
|
||||||
Reference in new issue
Block a user