null, 'suite' => null, 'level' => null, 'model' => null, 'result' => null, ]; private const SORTABLE = [ 'ran_at', 'model_id', 'suite', 'task', 'section', 'level', 'ok', 'decode', 'user_tps', 'ttft', 't_answer', 'wall', 'total', ]; public function resetFilters(): void { $this->filters = [ 'search' => null, 'suite' => null, 'level' => null, 'model' => null, 'result' => null, ]; $this->resetPage(); } #[Computed] public function results(): LengthAwarePaginator { return RunResult::query() ->join('benchmark_runs', 'run_results.benchmark_run_id', '=', 'benchmark_runs.id') ->select('run_results.*', 'benchmark_runs.ran_at', 'benchmark_runs.model_id', 'benchmark_runs.model_quant', 'benchmark_runs.engine', 'benchmark_runs.run_id', 'benchmark_runs.visibility', 'benchmark_runs.user_id as run_user_id') ->tap(fn (Builder $q) => $q->where(BenchmarkRun::visibleClause(auth()->user()))) ->tap(fn (Builder $q) => $this->applySorting($q)) ->tap(fn (Builder $q) => $this->applyFilters($q)) ->with('run:id,run_id') ->paginate(25); } #[Computed] public function suites(): array { return RunResult::query()->distinct()->orderBy('suite')->pluck('suite')->all(); } #[Computed] public function models(): array { return BenchmarkRun::visibleTo(auth()->user()) ->distinct()->orderBy('model_id')->pluck('model_id')->all(); } private function applySorting(Builder $query): Builder { $column = in_array($this->sortBy, self::SORTABLE, true) ? $this->sortBy : 'ran_at'; return $query->orderBy($column, $this->sortDirection === 'asc' ? 'asc' : 'desc') ->orderBy('run_results.id', 'desc'); } private function applyFilters(Builder $query): Builder { return $query ->when($this->filters['search'], fn (Builder $q, string $search) => $q->where(function (Builder $q) use ($search) { $q->where('run_results.task', 'like', "%{$search}%") ->orWhere('benchmark_runs.model_id', 'like', "%{$search}%") ->orWhere('benchmark_runs.label', 'like', "%{$search}%"); })) ->when($this->filters['suite'], fn (Builder $q, string $suite) => $q->where('run_results.suite', $suite)) ->when($this->filters['level'], fn (Builder $q, string $level) => $q->where('run_results.level', $level)) ->when($this->filters['model'], fn (Builder $q, string $model) => $q->where('benchmark_runs.model_id', $model)) ->when($this->filters['result'] !== null && $this->filters['result'] !== '', fn (Builder $q) => $q->where('run_results.ok', (bool) $this->filters['result'])); } }; ?>