bandId = $bandId; $this->rcallNorm = $rcallNorm; } public function handle(): void { $run = EvaluationRun::find($this->evaluationRunId); if (! $run || $run->isCanceled()) { return; } $coordinator = new EvaluationCoordinator(); try { $ruleSet = EvaluationRuleSet::find($run->rule_set_id); if (! $ruleSet) { $coordinator->eventError($run, 'Unpaired klasifikace nelze spustit: chybí ruleset.', [ 'step' => 'unpaired_classification', ]); return; } $coordinator->eventInfo($run, 'Unpaired bucket: krok spuštěn.', [ 'step' => 'unpaired_classification', 'round_id' => $run->round_id, 'band_id' => $this->bandId, 'rcall_norm' => $this->rcallNorm, ]); $workingQuery = WorkingQso::where('evaluation_run_id', $run->id) ->where('rcall_norm', $this->rcallNorm); if ($this->bandId !== null) { $workingQuery->where('band_id', $this->bandId); } else { $workingQuery->whereNull('band_id'); } $logQsoIds = $workingQuery->pluck('log_qso_id')->all(); if (! $logQsoIds) { return; } QsoResult::where('evaluation_run_id', $run->id) ->whereNull('matched_log_qso_id') ->whereIn('log_qso_id', $logQsoIds) ->chunkById(500, function ($results) use ($run, $ruleSet) { foreach ($results as $result) { $wqso = WorkingQso::where('evaluation_run_id', $run->id) ->where('log_qso_id', $result->log_qso_id) ->first(); if (! $wqso) { continue; } $hasCounterpartLog = false; if ($wqso->band_id && $wqso->rcall_norm) { $hasCounterpartLog = WorkingQso::where('evaluation_run_id', $run->id) ->where('band_id', $wqso->band_id) ->where('call_norm', $wqso->rcall_norm) ->exists(); } if ($hasCounterpartLog) { $result->error_code = QsoErrorCode::NOT_IN_COUNTERPART_LOG; $result->is_nil = true; } else { $isUnique = false; if ($ruleSet->uniqueQsoEnabled() && $wqso->rcall_norm) { $uniqueQuery = WorkingQso::where('evaluation_run_id', $run->id) ->where('rcall_norm', $wqso->rcall_norm); if ($wqso->band_id) { $uniqueQuery->where('band_id', $wqso->band_id); } $count = $uniqueQuery->count(); $isUnique = $count === 1; } if ($isUnique) { $result->error_code = QsoErrorCode::UNIQUE; $result->is_nil = false; } else { $result->error_code = QsoErrorCode::NO_COUNTERPART_LOG; $result->is_nil = true; } } $result->is_valid = false; $result->error_side = 'NONE'; $result->save(); } }); EvaluationRun::where('id', $run->id)->increment('progress_done'); $coordinator->eventInfo($run, 'Unpaired bucket: krok dokončen.', [ 'step' => 'unpaired_classification', 'round_id' => $run->round_id, 'band_id' => $this->bandId, 'rcall_norm' => $this->rcallNorm, ]); } catch (Throwable $e) { $coordinator->eventError($run, 'Unpaired bucket: krok selhal.', [ 'step' => 'unpaired_classification', 'round_id' => $run->round_id, 'band_id' => $this->bandId, 'rcall_norm' => $this->rcallNorm, 'error' => $e->getMessage(), ]); throw $e; } } }