This commit is contained in:
salam committed 2026-05-29 16:38:15 +02:00
1 parent eea1a8de4e
commit eb8bf5f3f0
6 files changed
+282 -159

No files matched your search

+2 -2
View File
@@ -263,8 +263,8 @@ class Statistic extends BaseDashboard
// Players
ChartPlayer::make(),
ChartPlayerMoAv::make(),
ChartPlayerPerf::make(),
ChartPlayerPerfMoAv::make(),
// ChartPlayerPerf::make(),
// ChartPlayerPerfMoAv::make(),
];
}
+45 -27
View File
@@ -2,8 +2,8 @@
namespace App\Filament\Widgets;
use App\Filament\Widgets\Data\HelperStatisticType;
use App\Filament\Widgets\Data\LoadPlayer;
use Filament\Support\RawJs;
use Filament\Widgets\ChartWidget;
use Filament\Widgets\Concerns\InteractsWithPageFilters;
@@ -17,36 +17,14 @@ class ChartPlayer extends ChartWidget
protected ?string $heading = 'Player';
protected ?array $options = [
'plugins' => [
'legend' => [
'display' => false,
],
],
'interaction' => [
'intersect' => false,
],
'callbacks' => [
'label' => 'function(context) {
return " Count: " + context.raw;
}',
],
];
protected function getData(): array
{
if ($this->filters['statistic_type'] == 'crn') {
return [];
}
$this->description = HelperStatisticType::get($this->filters);
if (isset($data['description'])) {
$this->description .= $data['description'];
}
$data = LoadPlayer::load($this->filters);
if ($data) {
$this->description = $data['player_name'];
}
return $data;
}
@@ -54,4 +32,44 @@ class ChartPlayer extends ChartWidget
{
return 'line';
}
// , ' '+context.dataset.playing_date[context.dataIndex], ' '+context.dataset.events[context.dataIndex]
protected function getOptions(): RawJs
{
return RawJs::make(<<<'JS'
{
interaction: {
intersect: false,
},
plugins: {
tooltip: {
callbacks: {
afterLabel: (context) => {
let event = context.dataset.events[context.dataIndex] || '';
let date = context.dataset.dates[context.dataIndex] || '';
return event+' '+ date;
},
}
}
},
scales: {
x: {
title: {
display: true,
text: 'Days since today'
}
},
y: {
beginAtZero:true,
ticks: {
callback: function(value, index, ticks) {
return value % 1 === 0 ? value : '';
}
}
},
},
}
JS);
}
}
+41 -23
View File
@@ -3,8 +3,8 @@
namespace App\Filament\Widgets;
use App\Filament\Widgets\Data\HelperMoveingAverage;
use App\Filament\Widgets\Data\HelperStatisticType;
use App\Filament\Widgets\Data\LoadPlayer;
use Filament\Support\RawJs;
use Filament\Widgets\ChartWidget;
use Filament\Widgets\Concerns\InteractsWithPageFilters;
@@ -18,33 +18,13 @@ class ChartPlayerMoAv extends ChartWidget
protected ?string $heading = 'Player';
protected ?array $options = [
'plugins' => [
'legend' => [
'display' => false,
],
],
'interaction' => [
'intersect' => false,
],
'scales' => [
'y' => [
'beginAtZero' => true,
],
],
];
protected function getData(): array
{
if ($this->filters['statistic_type'] == 'crn') {
return [];
}
$this->description = ucfirst(HelperStatisticType::get($this->filters)).' Moving Average';
$data = LoadPlayer::load($this->filters);
if ($data) {
$this->description = 'Moving Average '.$data['player_name'];
HelperMoveingAverage::get($data);
}
@@ -55,4 +35,42 @@ class ChartPlayerMoAv extends ChartWidget
{
return 'line';
}
protected function getOptions(): RawJs
{
return RawJs::make(<<<'JS'
{
interaction: {
intersect: false,
},
plugins: {
tooltip: {
callbacks: {
afterLabel: (context) => {
let event = context.dataset.events[context.dataIndex] || '';
let date = context.dataset.dates[context.dataIndex] || '';
return event+' '+ date;
},
}
}
},
scales: {
x: {
title: {
display: true,
text: 'Days since today'
}
},
y: {
beginAtZero:true,
ticks: {
callback: function(value, index, ticks) {
return value % 1 === 0 ? value : '';
}
}
},
},
}
JS);
}
}
+2
View File
@@ -371,6 +371,7 @@ class LoadEvents
'data' => $dataset_home,
'tension' => 0.5,
'borderColor' => '#fb2c36',
'backgroundColor' => '#fb2c36',
'fill' => [
'target' => 1,
'above' => '#fb2c3680',
@@ -385,6 +386,7 @@ class LoadEvents
'data' => $dataset_away,
'tension' => 0.5,
'borderColor' => '#fdc700',
'backgroundColor' => '#fdc700',
'fill' => false,
],
],
+85 -107
View File
@@ -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;
@@ -0,0 +1,107 @@
<?php
namespace App\Filament\Widgets\Data;
use App\Models\StatistikoPlayer;
use Illuminate\Support\Carbon;
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;
$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'];
if (! $league_id) {
return [];
}
if (! $team_id) {
return [];
}
if (! $tm_player_id) {
return [];
}
if ($statistic_type == 'none') {
$statistic_type = 'gls';
}
$res = StatistikoPlayer::with('event')->where('tm_player_id', (int) $tm_player_id)->get();
$labels = [];
$datasets = [];
foreach ($res as $value) {
// dd($value);
$val = 0;
if (isset($value->event->starttime)) {
// $labels[] = $value->event->starttime->format('d.M.y');
$labels[] = round($value->event->starttime->diffInDays(Carbon::now()));
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;
}
}