wip
This commit is contained in:
1 parent
eea1a8de4e
commit
eb8bf5f3f0
6 files changed
+282
-159
No files matched your search
@@ -2,7 +2,9 @@
|
||||
|
||||
namespace App\Filament\Widgets\Data;
|
||||
|
||||
use App\Models\StatistikoEvent;
|
||||
use App\Models\StatistikoDetail;
|
||||
use App\Models\StatistikoPlayer;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
class LoadPlayer
|
||||
{
|
||||
@@ -18,8 +20,6 @@ class LoadPlayer
|
||||
|
||||
$league_id = (int) $filter['league_id'] ?? 0;
|
||||
|
||||
$match_id = (int) $filter['match_id'] ?? 0;
|
||||
|
||||
$team_id = (int) $filter['team_id'] ?? 0;
|
||||
|
||||
$tm_player_id = (int) $filter['tm_player_id'] ?? 0;
|
||||
@@ -28,16 +28,8 @@ class LoadPlayer
|
||||
|
||||
$end = $filter['end_date'] ?? 0;
|
||||
|
||||
$statistic_type = $filter['statistic_type'];
|
||||
|
||||
$team_position = $filter['team_position'];
|
||||
|
||||
$player_on_field = $filter['player_on_field'];
|
||||
|
||||
$accuracy = (float) $filter['accuracy'];
|
||||
|
||||
$similar_past_matches = $filter['similar_past_matches'];
|
||||
|
||||
if (! $league_id) {
|
||||
return [];
|
||||
}
|
||||
@@ -48,119 +40,105 @@ class LoadPlayer
|
||||
return [];
|
||||
}
|
||||
|
||||
if ($statistic_type == 'none') {
|
||||
$statistic_type = 'gls';
|
||||
}
|
||||
$player_name = StatistikoDetail::where('tm_player_id', (int) $tm_player_id)->value('name');
|
||||
|
||||
/**
|
||||
* IF WITH SIMILAR_PAST_MATCHES
|
||||
*
|
||||
* 'none' => 'None',
|
||||
* 'league' => 'League',
|
||||
* 'all' => 'All Database',
|
||||
*/
|
||||
// $handicap_range = 0;
|
||||
// $total_range = 0;
|
||||
// if ($similar_past_matches != 'none') {
|
||||
// $res = StatisticFixtures::where('id', (int) $match_id)->first();
|
||||
|
||||
// $exp_handicap = $res->exp_away - $res->exp_home;
|
||||
|
||||
// $exp_total = $res->exp_away + $res->exp_home;
|
||||
|
||||
// $handicap_range = [$exp_handicap - $accuracy, $exp_handicap + $accuracy];
|
||||
|
||||
// $total_range = [$exp_total - $accuracy, $exp_total + $accuracy];
|
||||
// }
|
||||
|
||||
/**
|
||||
* STATTISTIC DATA
|
||||
*/
|
||||
$res = StatistikoEvent::where('league_id', $league_id)
|
||||
->where(function ($query) use ($team_id, $team_position) {
|
||||
switch ($team_position) {
|
||||
case 'home':
|
||||
return $query->where('home_id', '=', $team_id);
|
||||
case 'away':
|
||||
return $query->where('away_id', '=', $team_id);
|
||||
default:
|
||||
return $query->where('home_id', '=', $team_id)
|
||||
->orWhere('away_id', '=', $team_id);
|
||||
}
|
||||
// })
|
||||
// ->when($matches_played, function ($query) use ($matches_played) {
|
||||
// return $query->whereIn('match_id', $matches_played);
|
||||
})->when($start, function ($query) use ($start) {
|
||||
return $query->where('starttime', '>=', $start);
|
||||
})->when($end, function ($query) use ($end) {
|
||||
return $query->where('starttime', '<=', $end);
|
||||
})->first();
|
||||
|
||||
if ($res == null) {
|
||||
|
||||
$handicap_range = 0;
|
||||
|
||||
$total_range = 0;
|
||||
|
||||
} else {
|
||||
|
||||
$exp_handicap = $res['exp_away'] - $res['exp_home'];
|
||||
|
||||
$exp_total = $res['exp_away'] + $res['exp_home'];
|
||||
|
||||
$handicap_range = [$exp_handicap - $accuracy, $exp_handicap + $accuracy];
|
||||
|
||||
$total_range = [$exp_total - $accuracy, $exp_total + $accuracy];
|
||||
}
|
||||
$res = StatistikoPlayer::with('event.home')->with('event.away')->where('tm_player_id', (int) $tm_player_id)->get();
|
||||
|
||||
$labels = [];
|
||||
$datasets = [];
|
||||
foreach ($res as $key => $value) {
|
||||
|
||||
$val = 0;
|
||||
$playing_date = [];
|
||||
$events = [];
|
||||
$datasets_goals = [];
|
||||
$datasets_fouls = [];
|
||||
$datasets_offside = [];
|
||||
$datasets_card = [];
|
||||
$datasets_shots_on = [];
|
||||
$datasets_shots_off = [];
|
||||
foreach ($res as $value) {
|
||||
|
||||
if (isset($value->event->starttime)) {
|
||||
|
||||
$labels[] = $value->event->starttime->format('d.M.y');
|
||||
$labels[] = round($value->event->starttime->diffInDays(Carbon::now()));
|
||||
|
||||
$events[] = $value->event->home->name.' vs '.$value->event->away->name;
|
||||
|
||||
$playing_date[] = $value->event->starttime->format('d. F Y H:i');
|
||||
|
||||
$datasets_goals[] = (int) $value->goals;
|
||||
|
||||
$datasets_fouls[] = (int) $value->fouls;
|
||||
|
||||
$datasets_offside[] = (int) $value->offsides;
|
||||
|
||||
$datasets_card[] = (int) $value->card_yellow + $value->card_red + $value->card_yellowred;
|
||||
|
||||
$datasets_shots_on[] = (int) $value->shots_on_target;
|
||||
|
||||
$datasets_shots_off[] = (int) $value->shots_off_target;
|
||||
|
||||
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,
|
||||
'label' => 'Goals',
|
||||
'data' => $datasets_goals,
|
||||
'dates' => $playing_date,
|
||||
'events' => $events,
|
||||
'tension' => 0.5,
|
||||
'borderColor' => '#36A2EB',
|
||||
'borderColor' => '#fb2c36',
|
||||
'backgroundColor' => '#fb2c36',
|
||||
],
|
||||
[
|
||||
'label' => 'Fouls Commited',
|
||||
'data' => $datasets_fouls,
|
||||
'dates' => $playing_date,
|
||||
'events' => $events,
|
||||
'tension' => 0.5,
|
||||
'borderColor' => '#f0b100',
|
||||
'backgroundColor' => '#f0b100',
|
||||
'dates' => $playing_date,
|
||||
'events' => $events,
|
||||
],
|
||||
[
|
||||
'label' => 'Offside',
|
||||
'data' => $datasets_offside,
|
||||
'dates' => $playing_date,
|
||||
'events' => $events,
|
||||
'tension' => 0.5,
|
||||
'borderColor' => '#7ccf00',
|
||||
'backgroundColor' => '#7ccf00',
|
||||
],
|
||||
[
|
||||
'label' => 'Cards',
|
||||
'data' => $datasets_card,
|
||||
'dates' => $playing_date,
|
||||
'events' => $events,
|
||||
'tension' => 0.5,
|
||||
'borderColor' => '#00b8db',
|
||||
'backgroundColor' => '#00b8db',
|
||||
],
|
||||
[
|
||||
'label' => 'Shots On Target',
|
||||
'data' => $datasets_shots_on,
|
||||
'dates' => $playing_date,
|
||||
'events' => $events,
|
||||
'tension' => 0.5,
|
||||
'borderColor' => '#615fff',
|
||||
'backgroundColor' => '#615fff',
|
||||
],
|
||||
[
|
||||
'label' => 'Shots Off Target',
|
||||
'data' => $datasets_shots_off,
|
||||
'dates' => $playing_date,
|
||||
'events' => $events,
|
||||
'tension' => 0.5,
|
||||
'borderColor' => '#e12afb',
|
||||
'backgroundColor' => '#e12afb',
|
||||
],
|
||||
],
|
||||
'labels' => $labels,
|
||||
'player_name' => $player_name,
|
||||
];
|
||||
|
||||
self::$last_query = $data;
|
||||
|
||||
Reference in new issue
Block a user