171 lines
4.8 KiB
PHP
171 lines
4.8 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Widgets\Data;
|
|
|
|
use App\Models\StatistikoEvent;
|
|
|
|
class LoadPlayer
|
|
{
|
|
public static $last_query = [];
|
|
|
|
public static function load($filter)
|
|
{
|
|
// dd($filter);
|
|
|
|
if (self::$last_query) {
|
|
return self::$last_query;
|
|
}
|
|
|
|
$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;
|
|
|
|
$start = $filter['start_date'] ?? 0;
|
|
|
|
$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 [];
|
|
}
|
|
if (! $team_id) {
|
|
return [];
|
|
}
|
|
if (! $tm_player_id) {
|
|
return [];
|
|
}
|
|
|
|
if ($statistic_type == 'none') {
|
|
$statistic_type = 'gls';
|
|
}
|
|
|
|
/**
|
|
* 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];
|
|
}
|
|
|
|
$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,
|
|
'tension' => 0.5,
|
|
'borderColor' => '#36A2EB',
|
|
],
|
|
],
|
|
'labels' => $labels,
|
|
];
|
|
|
|
self::$last_query = $data;
|
|
|
|
return $data;
|
|
}
|
|
}
|