wip statistic events quasi

This commit is contained in:
salam committed 2026-04-30 13:57:38 +02:00
1 parent 897a327709
commit 58b9abbd32
6 files changed
+106 -25

No files matched your search

@@ -0,0 +1,46 @@
<?php
namespace App\Filament\Widgets;
use App\Actions\Statistics\LoadEvents;
use Filament\Widgets\Concerns\InteractsWithPageFilters;
use Filament\Widgets\StatsOverviewWidget;
use Filament\Widgets\StatsOverviewWidget\Stat;
class MedianAverageWidget extends StatsOverviewWidget
{
use InteractsWithPageFilters;
protected function getStats(): array
{
$data = LoadEvents::load($this->filters);
if (! isset($data['datasets'][0])) {
return [];
}
$arr = $data['datasets'][0]['data'];
$total = count($arr);
$summe = array_sum($arr);
if (! $total) {
return [];
}
if ($total % 2) {
$m = $total / 2 + 1;
$median = $arr[$m];
} else {
$m = $total / 2;
$m1 = floor($m);
$m2 = ceil($m);
$median = round(($arr[$m1] + $arr[$m2]) / 2, 2);
}
return [
Stat::make('Number of events', $total),
Stat::make('Average', round($summe / $total, 2)),
Stat::make('Median', $median),
];
}
}