wip performance
This commit is contained in:
1 parent
f0658cb658
commit
b330f52835
10 files changed
+258
-14
No files matched your search
@@ -6,8 +6,10 @@ use App\Actions\LoadStatisticFixturesLeaguesOptions;
|
||||
use App\Actions\LoadStatisticFixturesMatchOptions;
|
||||
use App\Filament\Widgets\ChartEvent;
|
||||
use App\Filament\Widgets\ChartEventMoAv;
|
||||
use App\Filament\Widgets\ChartEventPerf;
|
||||
use App\Filament\Widgets\ChartPlayer;
|
||||
use App\Filament\Widgets\ChartPlayerMoAv;
|
||||
use App\Filament\Widgets\ChartPlayerPerf;
|
||||
use App\Filament\Widgets\StatsMedianAverage;
|
||||
use App\Models\Element;
|
||||
use App\Models\StatisticFixtures;
|
||||
@@ -229,7 +231,7 @@ class Statistic extends BaseDashboard
|
||||
return [
|
||||
'default' => 1,
|
||||
'md' => 2,
|
||||
// 'lg' => 6,
|
||||
'lg' => 3,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -253,9 +255,11 @@ class Statistic extends BaseDashboard
|
||||
// Events
|
||||
ChartEvent::make(),
|
||||
ChartEventMoAv::make(),
|
||||
ChartEventPerf::make(),
|
||||
// Players
|
||||
ChartPlayer::make(),
|
||||
ChartPlayerMoAv::make(),
|
||||
ChartPlayerPerf::make(),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,8 @@ class ChartEvent extends ChartWidget
|
||||
{
|
||||
use InteractsWithPageFilters;
|
||||
|
||||
protected ?string $heading = 'Events';
|
||||
|
||||
protected ?string $pollingInterval = null;
|
||||
|
||||
protected bool $isCollapsible = true;
|
||||
@@ -20,8 +22,6 @@ class ChartEvent extends ChartWidget
|
||||
|
||||
protected function getData(): array
|
||||
{
|
||||
$this->heading = 'Events';
|
||||
|
||||
$data = LoadEvents::load($this->filters);
|
||||
|
||||
$this->description = ucfirst(HelperStatisticType::get($this->filters));
|
||||
|
||||
@@ -13,14 +13,14 @@ class ChartEventMoAv extends ChartWidget
|
||||
{
|
||||
use InteractsWithPageFilters;
|
||||
|
||||
protected ?string $heading = 'Events';
|
||||
|
||||
protected ?string $pollingInterval = null;
|
||||
|
||||
protected bool $isCollapsible = true;
|
||||
|
||||
protected function getData(): array
|
||||
{
|
||||
$this->heading = 'Events';
|
||||
|
||||
$data = LoadEvents::load($this->filters);
|
||||
|
||||
$this->description = ucfirst(HelperStatisticType::get($this->filters)).' Moving Average';
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Widgets;
|
||||
|
||||
use App\Filament\Widgets\Data\LoadPerformance;
|
||||
use Filament\Support\RawJs;
|
||||
use Filament\Widgets\ChartWidget;
|
||||
use Filament\Widgets\Concerns\InteractsWithPageFilters;
|
||||
|
||||
class ChartEventPerf extends ChartWidget
|
||||
{
|
||||
use InteractsWithPageFilters;
|
||||
|
||||
protected ?string $heading = 'Events';
|
||||
|
||||
protected ?string $description = 'Performance';
|
||||
|
||||
protected ?string $pollingInterval = null;
|
||||
|
||||
protected bool $isCollapsible = true;
|
||||
|
||||
protected function getData(): array
|
||||
{
|
||||
return LoadPerformance::load($this->filters);
|
||||
}
|
||||
|
||||
protected function getType(): string
|
||||
{
|
||||
return 'line';
|
||||
}
|
||||
|
||||
protected function getOptions(): RawJs
|
||||
{
|
||||
return RawJs::make(<<<'JS'
|
||||
{
|
||||
interaction: {
|
||||
intersect: false,
|
||||
},
|
||||
// plugins: {
|
||||
// tooltip: {
|
||||
// callbacks: {
|
||||
// label: (context) => {
|
||||
// return [' '+context.parsed.y, ' '+context.dataset.playing_date[context.dataIndex], ' '+context.dataset.events[context.dataIndex], ' '+context.dataset.results_per_event[context.dataIndex]];
|
||||
// },
|
||||
// }
|
||||
// }
|
||||
// },
|
||||
scales: {
|
||||
x: {
|
||||
title: {
|
||||
display: true,
|
||||
text: 'Days since today'
|
||||
}
|
||||
},
|
||||
y: {
|
||||
beginAtZero:true,
|
||||
ticks: {
|
||||
callback: function(value, index, ticks) {
|
||||
return value % 1 === 0 ? value : '';
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
JS);
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,8 @@ class ChartPlayer extends ChartWidget
|
||||
|
||||
protected bool $isCollapsible = true;
|
||||
|
||||
protected ?string $heading = 'Player';
|
||||
|
||||
protected ?array $options = [
|
||||
'plugins' => [
|
||||
'legend' => [
|
||||
@@ -37,8 +39,6 @@ class ChartPlayer extends ChartWidget
|
||||
return [];
|
||||
}
|
||||
|
||||
$this->heading = 'Player';
|
||||
|
||||
$this->description = HelperStatisticType::get($this->filters);
|
||||
|
||||
if (isset($data['description'])) {
|
||||
|
||||
@@ -16,7 +16,7 @@ class ChartPlayerMoAv extends ChartWidget
|
||||
|
||||
protected bool $isCollapsible = true;
|
||||
|
||||
public ?string $header;
|
||||
protected ?string $heading = 'Player';
|
||||
|
||||
protected ?array $options = [
|
||||
'plugins' => [
|
||||
@@ -40,8 +40,6 @@ class ChartPlayerMoAv extends ChartWidget
|
||||
return [];
|
||||
}
|
||||
|
||||
$this->heading = 'Player';
|
||||
|
||||
$this->description = ucfirst(HelperStatisticType::get($this->filters)).' Moving Average';
|
||||
|
||||
$data = LoadPlayer::load($this->filters);
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Widgets;
|
||||
|
||||
use Filament\Widgets\ChartWidget;
|
||||
use Filament\Widgets\Concerns\InteractsWithPageFilters;
|
||||
|
||||
class ChartPlayerPerf extends ChartWidget
|
||||
{
|
||||
use InteractsWithPageFilters;
|
||||
|
||||
protected ?string $heading = 'Player';
|
||||
|
||||
protected ?string $description = 'Performance';
|
||||
|
||||
protected ?string $pollingInterval = null;
|
||||
|
||||
protected bool $isCollapsible = true;
|
||||
|
||||
protected function getData(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
protected function getType(): string
|
||||
{
|
||||
return 'line';
|
||||
}
|
||||
}
|
||||
@@ -152,7 +152,7 @@ class LoadEvents
|
||||
|
||||
foreach ($res as $value) {
|
||||
|
||||
$labels[] = round($value['starttime']->diffInDays(Carbon::now())).'';
|
||||
$labels[] = round($value['starttime']->diffInDays(Carbon::now()));
|
||||
|
||||
$playing_date[] = $value['starttime']->format('d. F Y H:i');
|
||||
|
||||
|
||||
@@ -0,0 +1,146 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Widgets\Data;
|
||||
|
||||
use App\Models\StatisticFixtures;
|
||||
use App\Models\StatistikoDetail;
|
||||
use App\Models\StatistikoEvent;
|
||||
use App\Models\StatistikoPlayer;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
class LoadPerformance
|
||||
{
|
||||
public static $last_query = [];
|
||||
|
||||
public static $events_data = [];
|
||||
|
||||
public static function load(array $filter)
|
||||
{
|
||||
// dd($filter);
|
||||
|
||||
$league_id = (int) $filter['league_id'] ?? 0;
|
||||
|
||||
$match_id = (int) $filter['match_id'] ?? 0;
|
||||
|
||||
$tm_player_id = (int) $filter['tm_player_id'] ?? 0;
|
||||
|
||||
if (! $league_id) {
|
||||
return [];
|
||||
}
|
||||
if (! $match_id) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$match = StatisticFixtures::with('home')->with('away')->where('id', $match_id)->first();
|
||||
$home_id = $match->home_id;
|
||||
$away_id = $match->away_id;
|
||||
|
||||
$res = StatistikoEvent::where('league_id', $league_id)->get();
|
||||
|
||||
$home_matches = [];
|
||||
$away_matches = [];
|
||||
$labels = [];
|
||||
foreach ($res as $val) {
|
||||
if ($val->home_id == $home_id or $val->away_id == $home_id or $val->home_id == $away_id or $val->away_id == $away_id) {
|
||||
$labels[] = round($val->starttime->diffInDays(Carbon::now()));
|
||||
$label_formatted[$val->match_id] = $val->starttime->format('d. F Y H:i');
|
||||
|
||||
if ($val->home_id == $home_id or $val->away_id == $home_id) {
|
||||
$home_matches[] = $val->match_id;
|
||||
} else {
|
||||
$home_matches[] = null;
|
||||
}
|
||||
if ($val->home_id == $away_id or $val->away_id == $away_id) {
|
||||
$away_matches[] = $val->match_id;
|
||||
} else {
|
||||
$away_matches[] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$res = StatistikoPlayer::whereIn('match_id', $home_matches)->select('match_id', 'minutes_played', 'playerrating_value')->get();
|
||||
$homes = self::filterMatches($res, $home_matches);
|
||||
|
||||
$res = StatistikoPlayer::whereIn('match_id', $away_matches)->select('match_id', 'minutes_played', 'playerrating_value')->get();
|
||||
$aways = self::filterMatches($res, $away_matches);
|
||||
|
||||
$data = [
|
||||
'datasets' => [
|
||||
[
|
||||
'label' => $match->home->name,
|
||||
'data' => $homes,
|
||||
'spanGaps' => true,
|
||||
'tension' => 0.5,
|
||||
'borderColor' => '#fb2c36',
|
||||
'fill' => [
|
||||
'target' => 1,
|
||||
'above' => '#fb2c3680',
|
||||
'below' => '#fdc70080',
|
||||
],
|
||||
],
|
||||
[
|
||||
'label' => $match->away->name,
|
||||
'data' => $aways,
|
||||
'spanGaps' => true,
|
||||
'tension' => 0.5,
|
||||
'borderColor' => '#fdc700',
|
||||
'fill' => false,
|
||||
],
|
||||
],
|
||||
'labels' => $labels,
|
||||
];
|
||||
|
||||
return $data;
|
||||
|
||||
/**
|
||||
* IF WITH PLAYER
|
||||
*/
|
||||
// $matches_played = 0;
|
||||
// $description = '';
|
||||
// if ($tm_player_id) {
|
||||
// $matches_played = StatistikoPlayer::where('tm_player_id', (int) $tm_player_id)
|
||||
// ->when($player_on_field, function ($query) use ($player_on_field) {
|
||||
// switch ($player_on_field) {
|
||||
// case 'lineup':
|
||||
// return $query->where('lineup', 'T');
|
||||
// case 'substituted':
|
||||
// return $query->where('lineup', 'P');
|
||||
// }
|
||||
// })
|
||||
// ->pluck('match_id')->toArray();
|
||||
|
||||
// if (! $matches_played) {
|
||||
// return [];
|
||||
// }
|
||||
|
||||
// $description = ' (with '.StatistikoDetail::where('tm_player_id', (int) $tm_player_id)->value('name').')';
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
public static function filterMatches($res, $matches)
|
||||
{
|
||||
$result = [];
|
||||
foreach ($res as $value) {
|
||||
$match_id = $value->match_id;
|
||||
if (isset($return[$match_id])) {
|
||||
$result[$match_id]['sum_min'] += $value->minutes_played;
|
||||
$result[$match_id]['rating'] += $value->playerrating_value * $value->minutes_played;
|
||||
} else {
|
||||
$result[$match_id]['sum_min'] = $value->minutes_played;
|
||||
$result[$match_id]['rating'] = $value->playerrating_value * $value->minutes_played;
|
||||
}
|
||||
}
|
||||
|
||||
$return = [];
|
||||
foreach ($matches as $matchid) {
|
||||
if (isset($result[$matchid])) {
|
||||
$return[] = $result[$matchid]['rating'] / $result[$matchid]['sum_min'];
|
||||
} else {
|
||||
$return[] = null;
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
@@ -24,9 +24,7 @@ class StatsMedianAverage extends StatsOverviewWidget
|
||||
|
||||
protected function getStats(): array
|
||||
{
|
||||
$filters = $this->filters;
|
||||
|
||||
$data = LoadEvents::load($filters);
|
||||
$data = LoadEvents::load($this->filters, 'Events');
|
||||
|
||||
if (! isset($data['datasets'][0])) {
|
||||
return [];
|
||||
|
||||
Reference in new issue
Block a user