statistic wip
This commit is contained in:
1 parent
01a3f41ec0
commit
d6620fb0a1
10 files changed
+408
-333
No files matched your search
@@ -1,71 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions\Statistics;
|
||||
|
||||
use App\Models\StatistikoEvent;
|
||||
|
||||
class EventData
|
||||
{
|
||||
public static function get($filter)
|
||||
{
|
||||
$league_id = (int) $filter['league_id'] ?? 0;
|
||||
$team_id = (int) $filter['team_id'] ?? 0;
|
||||
|
||||
if (! $league_id) {
|
||||
return [];
|
||||
}
|
||||
if (! $team_id) {
|
||||
return [];
|
||||
}
|
||||
|
||||
switch ($filter['team_position']) {
|
||||
case 'home':
|
||||
$res = StatistikoEvent::where('league_id', $league_id)->where('home_id', '=', $team_id)->get();
|
||||
break;
|
||||
|
||||
case 'away':
|
||||
$res = StatistikoEvent::where('league_id', $league_id)->where('away_id', '=', $team_id)->get();
|
||||
break;
|
||||
|
||||
default:
|
||||
$res = StatistikoEvent::where('league_id', $league_id)
|
||||
->where(function ($query) use ($team_id) {
|
||||
$query->where('home_id', '=', $team_id)->orWhere('away_id', '=', $team_id);
|
||||
})->get();
|
||||
break;
|
||||
}
|
||||
|
||||
$datasets = [];
|
||||
$labels = [];
|
||||
|
||||
foreach ($res as $value) {
|
||||
$labels[] = $value['starttime']->format('d. M.y');
|
||||
|
||||
$tmp = [];
|
||||
$tmp['crd_a'] = (int) $value['crd_a'];
|
||||
$tmp['crd_h'] = (int) $value['crd_h'];
|
||||
$tmp['crn_a'] = (int) $value['crn_a'];
|
||||
$tmp['crn_h'] = (int) $value['crn_h'];
|
||||
$tmp['fls_a'] = (int) $value['fls_a'];
|
||||
$tmp['fls_h'] = (int) $value['fls_h'];
|
||||
$tmp['gls_a'] = (int) $value['gls_a'];
|
||||
$tmp['gls_h'] = (int) $value['gls_h'];
|
||||
$tmp['ofs_a'] = (int) $value['ofs_a'];
|
||||
$tmp['ofs_h'] = (int) $value['ofs_h'];
|
||||
$tmp['snt_a'] = (int) $value['snt_a'];
|
||||
$tmp['snt_h'] = (int) $value['snt_h'];
|
||||
$tmp['tsh_a'] = (int) $value['tsh_a'];
|
||||
$tmp['tsh_h'] = (int) $value['tsh_h'];
|
||||
|
||||
$tmp['exp_handicap'] = (float) $value['exp_handicap'];
|
||||
$tmp['exp_total'] = (float) $value['exp_total'];
|
||||
$tmp['exp_away'] = (float) $value['expgoalsaway_value'];
|
||||
$tmp['exp_home'] = (float) $value['expgoalshome_value'];
|
||||
|
||||
$datasets[] = $tmp;
|
||||
}
|
||||
|
||||
return ['lables' => $labels, 'datasets' => $datasets];
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions\Statistics;
|
||||
|
||||
use App\Models\StatistikoEvent;
|
||||
|
||||
class LoadEvents
|
||||
{
|
||||
public static function load($filter)
|
||||
{
|
||||
$league_id = (int) $filter['league_id'] ?? 0;
|
||||
$team_id = (int) $filter['team_id'] ?? 0;
|
||||
|
||||
if (! $league_id) {
|
||||
return [];
|
||||
}
|
||||
if (! $team_id) {
|
||||
return [];
|
||||
}
|
||||
|
||||
switch ($filter['team_position']) {
|
||||
case 'home':
|
||||
$res = StatistikoEvent::where('league_id', $league_id)->where('home_id', '=', $team_id)->get();
|
||||
break;
|
||||
|
||||
case 'away':
|
||||
$res = StatistikoEvent::where('league_id', $league_id)->where('away_id', '=', $team_id)->get();
|
||||
break;
|
||||
|
||||
default:
|
||||
$res = StatistikoEvent::where('league_id', $league_id)
|
||||
->where(function ($query) use ($team_id) {
|
||||
$query->where('home_id', '=', $team_id)->orWhere('away_id', '=', $team_id);
|
||||
})->get();
|
||||
break;
|
||||
}
|
||||
|
||||
$datasets = [];
|
||||
$labels = [];
|
||||
|
||||
foreach ($res as $value) {
|
||||
$labels[] = $value['starttime']->format('d. M.y');
|
||||
|
||||
// $tmp['exp_handicap'] = (float) $value['exp_handicap'];
|
||||
// $tmp['exp_total'] = (float) $value['exp_total'];
|
||||
// $tmp['exp_away'] = (float) $value['expgoalsaway_value'];
|
||||
// $tmp['exp_home'] = (float) $value['expgoalshome_value'];
|
||||
|
||||
switch ($filter['statistic_type']) {
|
||||
case 'gls':
|
||||
$tmp['gls_a'] = (int) $value['gls_a'];
|
||||
$tmp['gls_h'] = (int) $value['gls_h'];
|
||||
break;
|
||||
case 'crn':
|
||||
$tmp['crn_a'] = (int) $value['crn_a'];
|
||||
$tmp['crn_h'] = (int) $value['crn_h'];
|
||||
break;
|
||||
case 'fls':
|
||||
$tmp['fls_a'] = (int) $value['fls_a'];
|
||||
$tmp['fls_h'] = (int) $value['fls_h'];
|
||||
break;
|
||||
case 'ofs':
|
||||
$tmp['ofs_a'] = (int) $value['ofs_a'];
|
||||
$tmp['ofs_h'] = (int) $value['ofs_h'];
|
||||
break;
|
||||
case 'crd':
|
||||
$tmp['crd_a'] = (int) $value['crd_a'];
|
||||
$tmp['crd_h'] = (int) $value['crd_h'];
|
||||
break;
|
||||
case 'snt':
|
||||
$tmp['snt_a'] = (int) $value['snt_a'];
|
||||
$tmp['snt_h'] = (int) $value['snt_h'];
|
||||
break;
|
||||
case 'tsh':
|
||||
$tmp['tsh_a'] = (int) $value['tsh_a'];
|
||||
$tmp['tsh_h'] = (int) $value['tsh_h'];
|
||||
break;
|
||||
}
|
||||
|
||||
$datasets[] = $tmp;
|
||||
}
|
||||
|
||||
return ['lables' => $labels, 'datasets' => $datasets];
|
||||
}
|
||||
}
|
||||
@@ -4,41 +4,5 @@ namespace App\Actions\Statistics;
|
||||
|
||||
class StatisticEvents
|
||||
{
|
||||
public static function load($filter)
|
||||
{
|
||||
$data = EventData::get($filter);
|
||||
|
||||
if (! $data) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return [];
|
||||
dd($data);
|
||||
|
||||
/*
|
||||
"team_position" => "away"
|
||||
"similar_past_matches" => "none"
|
||||
"statistic_type" => "none"
|
||||
"accuracy" => 0.5
|
||||
"league_id" => "87"
|
||||
"team_id" => null
|
||||
"startDate" => null
|
||||
"endDate" => null
|
||||
"palyer_id" => null
|
||||
|
||||
'sport_id',
|
||||
'league_id',
|
||||
'home_id',
|
||||
'away_id',
|
||||
'starttime',
|
||||
*/
|
||||
|
||||
// $res = StatistikoEvent::where('league_id', $league_id)->get();
|
||||
// $result = DB::connection('mongodb')
|
||||
// ->table('movies')
|
||||
// ->where('league_id', $league_id)
|
||||
// ->orWhere('home_id', $home_id)
|
||||
// ->get();
|
||||
|
||||
}
|
||||
public static function load($filter) {}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions\Statistics;
|
||||
|
||||
class StatisticType
|
||||
{
|
||||
protected static array $types = [
|
||||
'gls' => 'Goals',
|
||||
'crn' => 'Corner',
|
||||
'fls' => 'Fouls commited',
|
||||
'ofs' => 'Offside',
|
||||
'crd' => 'Cards',
|
||||
'snt' => 'Shot on target',
|
||||
'tsh' => 'Total shots',
|
||||
];
|
||||
|
||||
public static function get($filter): string
|
||||
{
|
||||
|
||||
$tmp = $filter['statistic_type'] ?? 'none';
|
||||
|
||||
if (isset(self::$types[$tmp])) {
|
||||
return self::$types[$tmp];
|
||||
}
|
||||
|
||||
return 'Goals';
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,6 @@
|
||||
namespace App\Filament\Pages;
|
||||
|
||||
use App\Actions\LoadStatisticFixturesLeaguesOptions;
|
||||
use App\Actions\Statistics\StatisticEvents;
|
||||
use App\Filament\Widgets\MovingAverageChart;
|
||||
use App\Filament\Widgets\PunctualChart;
|
||||
use App\Models\Element;
|
||||
@@ -27,21 +26,6 @@ class Statistic extends BaseDashboard
|
||||
|
||||
protected static ?string $title = 'Statistic';
|
||||
|
||||
protected static array $types = [
|
||||
'gls' => 'Goals',
|
||||
'crn' => 'Corner',
|
||||
'fls' => 'Fouls commited',
|
||||
'ofs' => 'Offside',
|
||||
'crd' => 'Cards',
|
||||
'snt' => 'Shot on target',
|
||||
'tsh' => 'Total shots',
|
||||
];
|
||||
|
||||
public function getColumns(): int|array
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
public function filtersForm(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
@@ -153,26 +137,16 @@ class Statistic extends BaseDashboard
|
||||
]);
|
||||
}
|
||||
|
||||
public function update()
|
||||
{
|
||||
dd($this->filter);
|
||||
}
|
||||
|
||||
protected function getFooterWidgets(): array
|
||||
{
|
||||
|
||||
$data = StatisticEvents::load($this->filters);
|
||||
|
||||
$type = self::$types[$this->filters['statistic_type']];
|
||||
|
||||
// $data = [
|
||||
// 'datasets' => [
|
||||
// [
|
||||
// 'label' => 'test',
|
||||
// 'data' => [0, 10, 5, 2, 21, 32, 45, 74, 65, 45, 77, 89],
|
||||
// ],
|
||||
// ],
|
||||
// 'labels' => ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
|
||||
// ];
|
||||
|
||||
return [
|
||||
MovingAverageChart::make(['filters' => $data, 'header' => $type.' Punctual']),
|
||||
PunctualChart::make(['filters' => $data, 'header' => $type.' Moving Avverage']),
|
||||
PunctualChart::make(),
|
||||
MovingAverageChart::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Tables\Columns;
|
||||
|
||||
use Filament\Tables\Columns\Column;
|
||||
|
||||
class StatistikEventColumn extends Column
|
||||
{
|
||||
protected string $view = 'filament.tables.columns.statistik-event-column';
|
||||
}
|
||||
@@ -2,19 +2,59 @@
|
||||
|
||||
namespace App\Filament\Widgets;
|
||||
|
||||
use App\Actions\Statistics\LoadEvents;
|
||||
use App\Actions\Statistics\StatisticType;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Widgets\ChartWidget;
|
||||
use Filament\Widgets\Concerns\InteractsWithPageFilters;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class MovingAverageChart extends ChartWidget
|
||||
{
|
||||
public ?array $filters = [];
|
||||
use InteractsWithPageFilters;
|
||||
|
||||
protected ?string $pollingInterval = null;
|
||||
|
||||
public ?string $header;
|
||||
|
||||
public function getDescription(): ?string
|
||||
{
|
||||
return 'Moving Average';
|
||||
}
|
||||
|
||||
protected function getData(): array
|
||||
{
|
||||
$this->heading = $this->header;
|
||||
$this->heading = StatisticType::get($this->filters);
|
||||
|
||||
return $this->filters;
|
||||
if (! $this->filters['league_id']) {
|
||||
return [];
|
||||
}
|
||||
if (! $this->filters['team_id']) {
|
||||
// Notification::make()
|
||||
// ->title('Team is missing')
|
||||
// ->warning()
|
||||
// ->send();
|
||||
return [];
|
||||
}
|
||||
|
||||
// Log::info($this->filters);
|
||||
|
||||
$tmp = LoadEvents::load($this->filters);
|
||||
Log::info($tmp);
|
||||
|
||||
$data = [
|
||||
'datasets' => [
|
||||
[
|
||||
'label' => 'test',
|
||||
'data' => [0, 10, 5, 2, 21, 32, 45, 74, 65, 45, 77, 89],
|
||||
'borderColor' => '#00c950',
|
||||
'backgroundColor' => '#00c950',
|
||||
],
|
||||
],
|
||||
'labels' => ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
|
||||
];
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function getType(): string
|
||||
|
||||
@@ -2,19 +2,40 @@
|
||||
|
||||
namespace App\Filament\Widgets;
|
||||
|
||||
// use App\Actions\Statistics\StatisticEvents;
|
||||
use App\Actions\Statistics\StatisticType;
|
||||
use Filament\Widgets\ChartWidget;
|
||||
use Filament\Widgets\Concerns\InteractsWithPageFilters;
|
||||
|
||||
class PunctualChart extends ChartWidget
|
||||
{
|
||||
public ?array $filters = [];
|
||||
use InteractsWithPageFilters;
|
||||
|
||||
protected ?string $pollingInterval = null;
|
||||
|
||||
public ?string $header;
|
||||
|
||||
public function getDescription(): ?string
|
||||
{
|
||||
return 'Punctual';
|
||||
}
|
||||
|
||||
protected function getData(): array
|
||||
{
|
||||
$this->heading = $this->header;
|
||||
$this->heading = StatisticType::get($this->filters);
|
||||
|
||||
return $this->filters;
|
||||
$data = [
|
||||
'datasets' => [
|
||||
[
|
||||
'label' => 'test',
|
||||
'data' => [0, 10, 5, 2, 21, 32, 45, 74, 65, 45, 77, 89],
|
||||
'backgroundColor' => '#36A2EB',
|
||||
],
|
||||
],
|
||||
'labels' => ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
|
||||
];
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function getType(): string
|
||||
|
||||
Reference in new issue
Block a user