wip
This commit is contained in:
1 parent
d954a9fa5c
commit
4b4952bfec
16 files changed
+251
-340
No files matched your search
@@ -7,6 +7,7 @@ use App\Filament\Widgets\Data\LoadEvents;
|
||||
use App\Utilities\Round;
|
||||
use Filament\Widgets\StatsOverviewWidget;
|
||||
use Filament\Widgets\StatsOverviewWidget\Stat;
|
||||
use Illuminate\Support\HtmlString;
|
||||
use Livewire\Attributes\Reactive;
|
||||
|
||||
class StatsMedianAverage extends StatsOverviewWidget
|
||||
@@ -18,6 +19,8 @@ class StatsMedianAverage extends StatsOverviewWidget
|
||||
#[Reactive]
|
||||
public ?array $filters = [];
|
||||
|
||||
public ?int $count;
|
||||
|
||||
public function mount(array $filters)
|
||||
{
|
||||
$this->filters = $filters;
|
||||
@@ -36,7 +39,7 @@ class StatsMedianAverage extends StatsOverviewWidget
|
||||
'lg' => 6,
|
||||
];
|
||||
|
||||
$statistic_type = ucfirst(HelperStatisticType::get($this->filters));
|
||||
$statistic_type = HelperStatisticType::get($this->filters);
|
||||
|
||||
if (! isset($data['datasets'][0])) {
|
||||
$data['datasets'][0]['data'] = [];
|
||||
@@ -60,36 +63,12 @@ class StatsMedianAverage extends StatsOverviewWidget
|
||||
|
||||
if (! $total_home) {
|
||||
return [
|
||||
Stat::make('stat1', 'stat1')->view('filament.resources.events.widgets.statistic-regular', [
|
||||
'titel' => 'Number of events',
|
||||
'value' => '0',
|
||||
]),
|
||||
Stat::make('stat2', 'stat2')->view('filament.resources.events.widgets.statistic-average', [
|
||||
'titel' => 'Average '.$statistic_type,
|
||||
'value1' => 0,
|
||||
'value2' => 0,
|
||||
'home' => $home_team,
|
||||
'away' => $away_team,
|
||||
]),
|
||||
Stat::make('stat3', 'stat3')->view('filament.resources.events.widgets.statistic-average', [
|
||||
'titel' => 'Median '.$statistic_type,
|
||||
'value1' => 0,
|
||||
'value2' => 0,
|
||||
'home' => $home_team,
|
||||
'away' => $away_team,
|
||||
]),
|
||||
Stat::make('stat4', 'stat4')->view('filament.resources.events.widgets.statistic-regular', [
|
||||
'titel' => 'Win',
|
||||
'value' => 0,
|
||||
]),
|
||||
Stat::make('stat5', 'stat5')->view('filament.resources.events.widgets.statistic-regular', [
|
||||
'titel' => 'Draw',
|
||||
'value' => 0,
|
||||
]),
|
||||
Stat::make('stat6', 'stat6')->view('filament.resources.events.widgets.statistic-regular', [
|
||||
'titel' => 'Lost',
|
||||
'value' => 0,
|
||||
]),
|
||||
Stat::make('Number of events', 0),
|
||||
Stat::make('Average '.$statistic_type, self::template(0, 0, $home_team, $away_team)),
|
||||
Stat::make('Median '.$statistic_type, self::template(0, 0, $home_team, $away_team)),
|
||||
Stat::make('Win', 0),
|
||||
Stat::make('Draw', 0),
|
||||
Stat::make('Lost', 0),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -119,37 +98,26 @@ class StatsMedianAverage extends StatsOverviewWidget
|
||||
$draw = $data['results']['d'] ? number_format(Round::odd($total_home / $data['results']['d']), 2) : 0;
|
||||
$lost = $data['results']['l'] ? number_format(Round::odd($total_home / $data['results']['l']), 2) : 0;
|
||||
|
||||
$value_home = number_format($summe_home / $total_home, 1);
|
||||
$value_away = number_format($summe_away / $total_away, 1);
|
||||
|
||||
return [
|
||||
Stat::make('stat1', 'stat1')->view('filament.resources.events.widgets.statistic-regular', [
|
||||
'titel' => 'Number of events',
|
||||
'value' => $total_home,
|
||||
]),
|
||||
Stat::make('stat2', 'stat2')->view('filament.resources.events.widgets.statistic-average', [
|
||||
'titel' => 'Average '.$statistic_type,
|
||||
'value1' => number_format($summe_home / $total_home, 1),
|
||||
'value2' => number_format($summe_away / $total_away, 1),
|
||||
'home' => $home_team,
|
||||
'away' => $away_team,
|
||||
]),
|
||||
Stat::make('stat3', 'stat3')->view('filament.resources.events.widgets.statistic-average', [
|
||||
'titel' => 'Median '.$statistic_type,
|
||||
'value1' => $median_home,
|
||||
'value2' => $median_away,
|
||||
'home' => $home_team,
|
||||
'away' => $away_team,
|
||||
]),
|
||||
Stat::make('stat4', 'stat4')->view('filament.resources.events.widgets.statistic-regular', [
|
||||
'titel' => ($data['similar_past_matches'] != 'none') ? 'Win' : 'Win: '.$data['results']['w'],
|
||||
'value' => $win,
|
||||
]),
|
||||
Stat::make('stat5', 'stat5')->view('filament.resources.events.widgets.statistic-regular', [
|
||||
'titel' => ($data['similar_past_matches'] != 'none') ? 'Draw' : 'Draw: '.$data['results']['d'],
|
||||
'value' => $draw,
|
||||
]),
|
||||
Stat::make('stat6', 'stat6')->view('filament.resources.events.widgets.statistic-regular', [
|
||||
'titel' => ($data['similar_past_matches'] != 'none') ? 'Lost' : 'Lost: '.$data['results']['l'],
|
||||
'value' => $lost,
|
||||
]),
|
||||
Stat::make('Number of events', new HtmlString('<div id="number-of-events">'.$total_home.'</div>'))->extraAttributes(['x-init' => "animate('number-of-events', $total_home)"]),
|
||||
Stat::make('Average '.$statistic_type, self::template('avhome', 'avaway', $home_team, $away_team))->extraAttributes(['x-init' => "animate('avhome', $value_home); animate('avaway', $value_away)"]),
|
||||
Stat::make('Median '.$statistic_type, self::template('mehome', 'meaway', $home_team, $away_team))->extraAttributes(['x-init' => "animate('mehome', $median_home); animate('meaway', $median_away)"]),
|
||||
Stat::make($data['similar_past_matches'] != 'none' ? 'Win' : 'Win: '.$data['results']['w'], new HtmlString('<div id="number-of-win">'.$win.'</div>'))->extraAttributes(['x-init' => "animate('number-of-win', $win)"]),
|
||||
Stat::make($data['similar_past_matches'] != 'none' ? 'Draw' : 'Draw: '.$data['results']['d'], new HtmlString('<div id="number-of-draw">'.$draw.'</div>'))->extraAttributes(['x-init' => "animate('number-of-draw', $draw)"]),
|
||||
Stat::make($data['similar_past_matches'] != 'none' ? 'Lost' : 'Lost: '.$data['results']['l'], new HtmlString('<div id="number-of-lost">'.$lost.'</div>'))->extraAttributes(['x-init' => "animate('number-of-lost', $lost)"]),
|
||||
];
|
||||
}
|
||||
|
||||
protected function template(string $home_id, string $away_id, string $home_name, string $away_name): HtmlString
|
||||
{
|
||||
return new HtmlString('<div class="grid grid-cols-2 justify-center font-bold text-4xl">
|
||||
<span class="text-center" id="'.$home_id.'"></span>
|
||||
<span class="text-center" id="'.$away_id.'"></span>
|
||||
<span class="text-center text-xs text-gray-500 dark:text-gray-400">'.$home_name.'</span>
|
||||
<span class="text-center text-xs text-gray-500 dark:text-gray-400">'.$away_name.'</span>
|
||||
</div>');
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user