statistico players wip
This commit is contained in:
1 parent
314ab7885b
commit
5010e7ac02
12 files changed
+75
-54
No files matched your search
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Widgets;
|
||||
|
||||
use App\Filament\Widgets\Data\EventsLoad;
|
||||
use App\Filament\Widgets\Data\EventsLoadAspGoal;
|
||||
use Filament\Widgets\Concerns\InteractsWithPageFilters;
|
||||
use Filament\Widgets\StatsOverviewWidget;
|
||||
use Filament\Widgets\StatsOverviewWidget\Stat;
|
||||
|
||||
class StatsMedianAverage extends StatsOverviewWidget
|
||||
{
|
||||
use InteractsWithPageFilters;
|
||||
|
||||
protected function getStats(): array
|
||||
{
|
||||
$filters = $this->filters;
|
||||
|
||||
if ($filters['similar_past_matches'] == 'none') {
|
||||
$data = EventsLoad::load($filters);
|
||||
} else {
|
||||
$data = EventsLoadAspGoal::load($filters);
|
||||
}
|
||||
|
||||
if (! isset($data['datasets'][0])) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$arr = $data['datasets'][0]['data'];
|
||||
$total = count($arr);
|
||||
$summe = array_sum($arr);
|
||||
|
||||
if (! $total) {
|
||||
return [];
|
||||
}
|
||||
|
||||
sort($arr);
|
||||
|
||||
if ($total % 2 == 0) {
|
||||
// even
|
||||
$m = $total / 2;
|
||||
$m1 = floor($m);
|
||||
$m2 = ceil($m);
|
||||
$median = round(($arr[$m1] + $arr[$m2]) / 2, 2);
|
||||
|
||||
} else {
|
||||
// odd
|
||||
$m = floor($total / 2);
|
||||
$median = $arr[$m];
|
||||
}
|
||||
|
||||
return [
|
||||
Stat::make('Number of events', $total),
|
||||
Stat::make('Average', round($summe / $total, 2)),
|
||||
Stat::make('Median', $median),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user