wip player performance
This commit is contained in:
1 parent
fcbf718492
commit
37d28eec21
12 files changed
+214
-207
No files matched your search
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Widgets\Data;
|
||||
|
||||
use App\Models\StatistikoPlayer;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
class LoadPlayerPerformance
|
||||
{
|
||||
public static $last_query = [];
|
||||
|
||||
public static function load($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;
|
||||
|
||||
$statistic_type = $filter['statistic_type'];
|
||||
|
||||
$player_on_field = $filter['player_on_field'];
|
||||
|
||||
if (! $league_id) {
|
||||
return [];
|
||||
}
|
||||
if (! $team_id) {
|
||||
return [];
|
||||
}
|
||||
if (! $tm_player_id) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if ($statistic_type == 'none') {
|
||||
$statistic_type = 'gls';
|
||||
}
|
||||
|
||||
$matches_played = StatistikoPlayer::with('event')
|
||||
->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');
|
||||
}
|
||||
})->get();
|
||||
|
||||
$tmp = [];
|
||||
foreach ($matches_played as $value) {
|
||||
$key = round($value->event->starttime->diffInDays(Carbon::now()));
|
||||
$val = $value->playerrating_value;
|
||||
$tmp[$key] = $val;
|
||||
}
|
||||
|
||||
ksort($tmp);
|
||||
$dataset = [];
|
||||
$labels = [];
|
||||
foreach ($tmp as $key => $value) {
|
||||
$labels[] = $key;
|
||||
$dataset[] = $value;
|
||||
}
|
||||
|
||||
$labels = array_keys($dataset);
|
||||
|
||||
$data = [
|
||||
'datasets' => [
|
||||
[
|
||||
'label' => 'Player Rating',
|
||||
'data' => $dataset,
|
||||
'tension' => 0.5,
|
||||
'borderColor' => '#36A2EB',
|
||||
],
|
||||
],
|
||||
'labels' => $labels,
|
||||
];
|
||||
|
||||
self::$last_query = $data;
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user