statistiko dedicated page wip
This commit is contained in:
1 parent
cba90136a5
commit
1b5282d61d
14 files changed
+482
-213
No files matched your search
@@ -1,164 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire;
|
||||
|
||||
use App\Models\Event;
|
||||
use App\Models\StatistikoEvent;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Widgets\ChartWidget;
|
||||
use Filament\Widgets\ChartWidget\Concerns\HasFiltersSchema;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
use Illuminate\Support\HtmlString;
|
||||
|
||||
class StatisticEventChart extends ChartWidget
|
||||
{
|
||||
use HasFiltersSchema;
|
||||
|
||||
public Event $record;
|
||||
|
||||
// protected bool $hasDeferredFilters = true;
|
||||
|
||||
public ?string $filter = 'gls';
|
||||
|
||||
protected ?string $pollingInterval = null;
|
||||
|
||||
public function getHeading(): string|Htmlable|null
|
||||
{
|
||||
// $str = '<div class="flex flex-row gap-4 justify-center bg-gray-300 font-thin">';
|
||||
// $str .= '<div>'.$this->record->country->name.' '.$this->record->group->name.'</div>';
|
||||
// if ($this->record->home->betsapi_image_id) {
|
||||
// $str .= ' <img src="https://assets.b365api.com/images/team/m/'.$this->record->home->betsapi_image_id.'.png" class="h-6">';
|
||||
// }
|
||||
// $str .= '<div>'.$this->record->home->name.'</div>';
|
||||
// $str .= '<div>vs</div>';
|
||||
// $str .= '<div>'.$this->record->away->name.'</div>';
|
||||
// if ($this->record->away->betsapi_image_id) {
|
||||
// $str .= ' <img src="https://assets.b365api.com/images/team/m/'.$this->record->away->betsapi_image_id.'.png" class="h-6">';
|
||||
// }
|
||||
// $str .= '</div>';
|
||||
|
||||
return new HtmlString($this->record->country->name.' '.$this->record->group->name);
|
||||
}
|
||||
|
||||
public function filtersSchema(Schema $schema): Schema
|
||||
{
|
||||
return $schema->schema([
|
||||
Select::make('data_mode')
|
||||
->default('gls')
|
||||
->options([
|
||||
'gls' => 'Goals',
|
||||
'crn' => 'Corner',
|
||||
'fls' => 'Committed Fouls',
|
||||
'ofs' => 'Offsides',
|
||||
'crd' => 'Cards',
|
||||
'snt' => 'Shots on target',
|
||||
'tsh' => 'TotalShots',
|
||||
]),
|
||||
Select::make('claculation_mode')
|
||||
->default('punctual')
|
||||
->options([
|
||||
'punctual' => 'Punctual',
|
||||
'average' => 'Moving average',
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
protected function getData(): array
|
||||
{
|
||||
$data_mode = $this->filters['data_mode'] ?? null;
|
||||
$claculation_mode = $this->filters['claculation_mode'] ?? null;
|
||||
|
||||
$res = StatistikoEvent::where('league_id', $this->record['competition_group_id'])
|
||||
->where('home_id', $this->record['home_id'])
|
||||
// ->where('away_id', $this->record['away_id'])
|
||||
->get();
|
||||
|
||||
switch ($data_mode) {
|
||||
case 'crn':
|
||||
$h = 'crn_h';
|
||||
$a = 'crn_a';
|
||||
break;
|
||||
case 'fls':
|
||||
$h = 'fls_h';
|
||||
$a = 'fls_a';
|
||||
break;
|
||||
case 'ofs':
|
||||
$h = 'ofs_h';
|
||||
$a = 'ofs_a';
|
||||
break;
|
||||
case 'crd':
|
||||
$h = 'crd_h';
|
||||
$a = 'crd_a';
|
||||
break;
|
||||
case 'snt':
|
||||
$h = 'snt_h';
|
||||
$a = 'snt_a';
|
||||
break;
|
||||
case 'tsh':
|
||||
$h = 'tsh_h';
|
||||
$a = 'tsh_a';
|
||||
break;
|
||||
|
||||
default:
|
||||
$h = 'gls_h';
|
||||
$a = 'gls_a';
|
||||
break;
|
||||
}
|
||||
|
||||
$starttimes = [];
|
||||
$data_home = [];
|
||||
$data_away = [];
|
||||
foreach ($res as $event) {
|
||||
$data_home[] = $event[$h];
|
||||
$data_away[] = $event[$a];
|
||||
$starttimes[] = $event['starttime']->format('d.m.Y');
|
||||
}
|
||||
|
||||
return [
|
||||
'datasets' => [
|
||||
[
|
||||
'label' => $this->record->home->name,
|
||||
'data' => $data_home,
|
||||
'backgroundColor' => '#155dfc',
|
||||
'borderColor' => '#2b7fff',
|
||||
],
|
||||
[
|
||||
'label' => $this->record->away->name,
|
||||
'data' => $data_away,
|
||||
'backgroundColor' => '#00a63e',
|
||||
'borderColor' => '#00c950',
|
||||
],
|
||||
],
|
||||
'labels' => $starttimes,
|
||||
'scales' => $this->getOptions(),
|
||||
];
|
||||
}
|
||||
|
||||
protected function getOptions(): array
|
||||
{
|
||||
return [
|
||||
'scales' => [
|
||||
'y' => [
|
||||
'ticks' => [
|
||||
'precision' => 0, // Forces integers
|
||||
'beginAtZero' => true,
|
||||
],
|
||||
],
|
||||
],
|
||||
'plugins' => [
|
||||
'legend' => [
|
||||
'display' => true,
|
||||
'position' => 'top', // Set position to 'top'
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
// ], layout: FiltersLayout::AboveContent)
|
||||
|
||||
protected function getType(): string
|
||||
{
|
||||
return 'line';
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user