statistico players wip
This commit is contained in:
1 parent
314ab7885b
commit
5010e7ac02
12 files changed
+75
-54
No files matched your search
@@ -0,0 +1,138 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Widgets\Data;
|
||||
|
||||
use App\Models\StatistikoPlayer;
|
||||
|
||||
class PlayerLoad
|
||||
{
|
||||
public static function load($filter)
|
||||
{
|
||||
// dd($filter);
|
||||
|
||||
// "team_position" => "all"
|
||||
// "statistic_type" => "gls"
|
||||
// "similar_past_matches" => "none"
|
||||
// "accuracy" => "0.5"
|
||||
// "player_on_field" => "all"
|
||||
// "league_id" => "26"
|
||||
// "team_id" => "571991"
|
||||
// "start_date" => null
|
||||
// "end_date" => null
|
||||
// "tm_player_id" => null
|
||||
|
||||
// 'gls' => 'Goals', // goals
|
||||
// 'crn' => 'Corner',
|
||||
// 'fls' => 'Fouls commited', // fouls
|
||||
// 'ofs' => 'Offside', // offsides
|
||||
// 'crd' => 'Cards',
|
||||
// 'snt' => 'Shot on target', // shots_on_target
|
||||
// 'tsh' => 'Total shots', // shots_off_target
|
||||
|
||||
$league_id = (int) $filter['league_id'] ?? 0;
|
||||
|
||||
$team_id = (int) $filter['team_id'] ?? 0;
|
||||
|
||||
$tm_player_id = (int) $filter['tm_player_id'] ?? 0;
|
||||
|
||||
if (! $league_id) {
|
||||
return [];
|
||||
}
|
||||
if (! $team_id) {
|
||||
return [];
|
||||
}
|
||||
if (! $tm_player_id) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$team_position = $filter['team_position'];
|
||||
|
||||
$player_on_field = $filter['player_on_field'];
|
||||
|
||||
$res = StatistikoPlayer::with('event')->where('tm_player_id', $tm_player_id)
|
||||
->when($team_position, function ($query) use ($team_id, $team_position) {
|
||||
/**
|
||||
* TEAM HOME/AWAY
|
||||
*/
|
||||
switch ($team_position) {
|
||||
case 'home':
|
||||
return $query->where('activeteam_id', $team_id);
|
||||
break;
|
||||
|
||||
case 'away':
|
||||
return $query->where('activeteam_id', '!=', $team_id);
|
||||
break;
|
||||
}
|
||||
})->when($player_on_field, function ($query) use ($player_on_field) {
|
||||
/**
|
||||
* LINEUP
|
||||
*/
|
||||
switch ($player_on_field) {
|
||||
case 'lineup':
|
||||
return $query->where('lineup', 'T');
|
||||
break;
|
||||
case 'substituted':
|
||||
return $query->where('lineup', 'P');
|
||||
break;
|
||||
}
|
||||
|
||||
})->get();
|
||||
|
||||
$statistic_type = $filter['statistic_type'] ?? 0;
|
||||
|
||||
// $fields = 'goals,fouls,offsides,shots_on_target,shots_off_target, subtype_event_during_the_match';
|
||||
|
||||
$labels = [];
|
||||
$datasets = [];
|
||||
foreach ($res as $key => $value) {
|
||||
|
||||
$val = 0;
|
||||
|
||||
if (isset($value->event->starttime)) {
|
||||
|
||||
$labels[] = $value->event->starttime->format('d.M.y');
|
||||
|
||||
switch ($statistic_type) {
|
||||
case 'gls':
|
||||
$val = (int) $value['goals'];
|
||||
break;
|
||||
case 'crn':
|
||||
$val = (int) 0;
|
||||
break;
|
||||
case 'fls':
|
||||
$val = (int) $value['fouls'];
|
||||
break;
|
||||
case 'ofs':
|
||||
$val = (int) $value['offsides'];
|
||||
break;
|
||||
case 'crd':
|
||||
$val = (int) $value['card_yellow'] + $value['card_red'] + $value['card_yellowred'];
|
||||
break;
|
||||
case 'snt':
|
||||
$val = (int) $value['shots_on_target'];
|
||||
break;
|
||||
case 'tsh':
|
||||
$val = (int) $value['shots_off_target'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$datasets[] = $val;
|
||||
}
|
||||
|
||||
$data = [
|
||||
'datasets' => [
|
||||
[
|
||||
'label' => ucfirst($team_position),
|
||||
'data' => $datasets,
|
||||
'fill' => true,
|
||||
'tension' => 0.5,
|
||||
'borderColor' => '#36A2EB',
|
||||
],
|
||||
],
|
||||
'labels' => $labels,
|
||||
];
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user