LoadEvents with description
This commit is contained in:
1 parent
4f63a4ef2c
commit
1f4fb9cf8a
6 files changed
+48
-144
No files matched your search
@@ -5,7 +5,6 @@ namespace App\Filament\Widgets;
|
||||
use App\Filament\Widgets\Data\HelperMoveingAverage;
|
||||
use App\Filament\Widgets\Data\HelperStatisticType;
|
||||
use App\Filament\Widgets\Data\LoadEvents;
|
||||
use Filament\Support\RawJs;
|
||||
use Filament\Widgets\ChartWidget;
|
||||
use Filament\Widgets\Concerns\InteractsWithPageFilters;
|
||||
|
||||
@@ -15,8 +14,6 @@ class ChartMovingAverageEvent extends ChartWidget
|
||||
|
||||
protected ?string $pollingInterval = null;
|
||||
|
||||
public ?string $header;
|
||||
|
||||
protected ?array $options = [
|
||||
'plugins' => [
|
||||
'legend' => [
|
||||
@@ -28,19 +25,16 @@ class ChartMovingAverageEvent extends ChartWidget
|
||||
],
|
||||
];
|
||||
|
||||
public function getDescription(): ?string
|
||||
{
|
||||
return 'Events Moving Average';
|
||||
}
|
||||
|
||||
protected function getData(): array
|
||||
{
|
||||
$this->heading = HelperStatisticType::get($this->filters);
|
||||
$this->heading = 'Events '.HelperStatisticType::get($this->filters);
|
||||
|
||||
$data = LoadEvents::load($this->filters);
|
||||
|
||||
if ($data) {
|
||||
HelperMoveingAverage::get($data);
|
||||
|
||||
$this->description = 'Moving Average '.$data['description'];
|
||||
}
|
||||
|
||||
return $data;
|
||||
@@ -50,32 +44,4 @@ class ChartMovingAverageEvent extends ChartWidget
|
||||
{
|
||||
return 'line';
|
||||
}
|
||||
|
||||
// protected function getOptions(): array|RawJs|null
|
||||
// {
|
||||
// return [
|
||||
// 'plugins' => [
|
||||
// 'legend' => [
|
||||
// 'display' => display,
|
||||
// ],
|
||||
// 'tooltip' => [
|
||||
// 'callbacks' => [
|
||||
// 'label' => RawJs::make(<<<'JS'
|
||||
// function(context) {
|
||||
// let label = context.dataset.label || '';
|
||||
|
||||
// if (label) {
|
||||
// label += ': ';
|
||||
// }
|
||||
// return label;
|
||||
// }
|
||||
// JS),
|
||||
// ],
|
||||
// ],
|
||||
// ],
|
||||
// 'interaction' => [
|
||||
// 'intersect' => false,
|
||||
// ],
|
||||
// ];
|
||||
// }
|
||||
}
|
||||
@@ -22,6 +22,9 @@ class ChartMovingAveragePlayer extends ChartWidget
|
||||
'display' => false,
|
||||
],
|
||||
],
|
||||
'interaction' => [
|
||||
'intersect' => false,
|
||||
],
|
||||
];
|
||||
|
||||
public function getDescription(): ?string
|
||||
|
||||
@@ -4,7 +4,6 @@ namespace App\Filament\Widgets;
|
||||
|
||||
use App\Filament\Widgets\Data\HelperStatisticType;
|
||||
use App\Filament\Widgets\Data\LoadEvents;
|
||||
// use Filament\Support\RawJs;
|
||||
use Filament\Widgets\ChartWidget;
|
||||
use Filament\Widgets\Concerns\InteractsWithPageFilters;
|
||||
|
||||
@@ -14,8 +13,6 @@ class ChartPunctualEvent extends ChartWidget
|
||||
|
||||
protected ?string $pollingInterval = null;
|
||||
|
||||
public ?string $header;
|
||||
|
||||
protected ?array $options = [
|
||||
'plugins' => [
|
||||
'legend' => [
|
||||
@@ -25,29 +22,16 @@ class ChartPunctualEvent extends ChartWidget
|
||||
'interaction' => [
|
||||
'intersect' => false,
|
||||
],
|
||||
// 'scales' => [
|
||||
// 'xAxes' => [
|
||||
// 'type' => 'time',
|
||||
// 'time' => [
|
||||
// 'tooltipFormat' => 'MM/DD/YYYY',
|
||||
// 'displayFormats' => 'HH:mm:ss',
|
||||
// ],
|
||||
|
||||
// ],
|
||||
// ],
|
||||
];
|
||||
|
||||
public function getDescription(): ?string
|
||||
{
|
||||
return 'Events Punctual';
|
||||
}
|
||||
|
||||
protected function getData(): array
|
||||
{
|
||||
$this->heading = HelperStatisticType::get($this->filters);
|
||||
$this->heading = 'Events '.HelperStatisticType::get($this->filters);
|
||||
|
||||
$data = LoadEvents::load($this->filters);
|
||||
|
||||
$this->description = 'Punctual '.$data['description'];
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
@@ -55,69 +39,4 @@ class ChartPunctualEvent extends ChartWidget
|
||||
{
|
||||
return 'line';
|
||||
}
|
||||
|
||||
// protected function getOptions(): RawJs|array
|
||||
// {
|
||||
// return RawJs::make(<<<'JS'
|
||||
// {
|
||||
// plugins: {
|
||||
// legend: {
|
||||
// display: false
|
||||
// },
|
||||
// datalabels: {
|
||||
// backgroundColor: function(context) {
|
||||
// return context.active ? context.dataset.backgroundColor : 'white';
|
||||
// },
|
||||
// borderColor: function(context) {
|
||||
// return context.dataset.backgroundColor;
|
||||
// },
|
||||
// borderRadius: function(context) {
|
||||
// return context.active ? 0 : 32;
|
||||
// },
|
||||
// borderWidth: 3,
|
||||
// color: function(context) {
|
||||
// return context.active ? 'white' : context.dataset.backgroundColor;
|
||||
// },
|
||||
// font: {
|
||||
// weight: 'bold'
|
||||
// },
|
||||
// formatter: function(value, context) {
|
||||
// value = Math.round(value * 100) / 100;
|
||||
// return context.active
|
||||
// ? context.dataset.label + '\n' + value + '%'
|
||||
// : Math.round(value);
|
||||
// },
|
||||
// offset: 8,
|
||||
// padding: 5,
|
||||
// textAlign: 'center'
|
||||
// }
|
||||
// },
|
||||
// // Core options
|
||||
// aspectRatio: 5 / 3,
|
||||
// layout: {
|
||||
// padding: {
|
||||
// bottom: 16,
|
||||
// right: 40,
|
||||
// left: 8,
|
||||
// top: 40
|
||||
// }
|
||||
// },
|
||||
// hover: {
|
||||
// mode: 'index',
|
||||
// intersect: false
|
||||
// },
|
||||
// elements: {
|
||||
// line: {
|
||||
// fill: false,
|
||||
// tension: 0.4
|
||||
// }
|
||||
// },
|
||||
// scales: {
|
||||
// y: {
|
||||
// stacked: true
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// JS);
|
||||
// }
|
||||
}
|
||||
@@ -21,6 +21,9 @@ class ChartPunctualPlayer extends ChartWidget
|
||||
'display' => false,
|
||||
],
|
||||
],
|
||||
'interaction' => [
|
||||
'intersect' => false,
|
||||
],
|
||||
];
|
||||
|
||||
public function getDescription(): ?string
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
|
||||
namespace App\Filament\Widgets\Data;
|
||||
|
||||
use App\Models\StatistikoDetail;
|
||||
use App\Models\StatistikoEvent;
|
||||
use App\Models\StatistikoPlayer;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class LoadEvents
|
||||
@@ -11,8 +13,6 @@ class LoadEvents
|
||||
|
||||
public static function load($filter)
|
||||
{
|
||||
// dd($filter);
|
||||
|
||||
if (self::$last_query) {
|
||||
return self::$last_query;
|
||||
}
|
||||
@@ -43,6 +43,17 @@ class LoadEvents
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* IF WITH PLAYER
|
||||
*/
|
||||
if ($tm_player_id) {
|
||||
$matches_played = StatistikoPlayer::where('tm_player_id', (int) $tm_player_id)->pluck('match_id')->toArray();
|
||||
|
||||
$description = ' (with '.StatistikoDetail::where('tm_player_id', (int) $tm_player_id)->value('name').')';
|
||||
|
||||
} else {
|
||||
$matches_played = 0;
|
||||
}
|
||||
/**
|
||||
* STATTISTIC DATA
|
||||
*/
|
||||
@@ -57,8 +68,9 @@ class LoadEvents
|
||||
return $query->where('home_id', '=', $team_id)
|
||||
->orWhere('away_id', '=', $team_id);
|
||||
}
|
||||
})
|
||||
->when($start, function ($query) use ($start) {
|
||||
})->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);
|
||||
@@ -202,6 +214,7 @@ class LoadEvents
|
||||
],
|
||||
],
|
||||
'labels' => $labels,
|
||||
'description' => $description ?? '',
|
||||
];
|
||||
|
||||
self::$last_query = $data;
|
||||
|
||||
@@ -16,25 +16,6 @@ class LoadPlayer
|
||||
return self::$last_query;
|
||||
}
|
||||
|
||||
// "team_position" => "all"
|
||||
// "statistic_type" => "gls"
|
||||
// "similar_past_matches" => "none"
|
||||
// "accuracy" => "0.5"
|
||||
// "player_on_field" => "all"
|
||||
// "league_id" => "26"
|
||||
// "team_id" => "571991"
|
||||
// "start_date" => null
|
||||
// "end_date" => null
|
||||
// "tm_player_id" => null
|
||||
|
||||
// 'gls' => 'Goals', // goals
|
||||
// 'crn' => 'Corner',
|
||||
// 'fls' => 'Fouls commited', // fouls
|
||||
// 'ofs' => 'Offside', // offsides
|
||||
// 'crd' => 'Cards',
|
||||
// 'snt' => 'Shot on target', // shots_on_target
|
||||
// 'tsh' => 'Total shots', // shots_off_target
|
||||
|
||||
$league_id = (int) $filter['league_id'] ?? 0;
|
||||
|
||||
$team_id = (int) $filter['team_id'] ?? 0;
|
||||
@@ -47,6 +28,8 @@ class LoadPlayer
|
||||
|
||||
$statistic_type = $filter['statistic_type'] ?? 0;
|
||||
|
||||
$accuracy = (float) $filter['accuracy'];
|
||||
|
||||
$similar_past_matches = $filter['similar_past_matches'] ?? 0;
|
||||
|
||||
$start = $filter['start_date'] ?? 0;
|
||||
@@ -86,6 +69,23 @@ class LoadPlayer
|
||||
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) {
|
||||
|
||||
Reference in new issue
Block a user