species = Species::all(); $this->fetchDynamicLimits(); } public function fetchDynamicLimits() { $stats = DB::table('treatments') ->selectRaw(' MIN(emsConcentration) as min_concentration, MAX(emsConcentration) as max_concentration, MIN(soakDuration) as min_soak_duration, MAX(soakDuration) as max_soak_duration, MIN(lowestTemp) as min_lowest_temp, MAX(lowestTemp) as max_lowest_temp, MIN(highestTemp) as min_highest_temp, MAX(highestTemp) as max_highest_temp ') ->first(); $this->minConcentration = $stats->min_concentration ?? 0.01; $this->maxConcentration = $stats->max_concentration ?? 100; $this->minSoakDuration = $stats->min_soak_duration ?? 1; $this->maxSoakDuration = $stats->max_soak_duration ?? 1440; $this->minLowestTemp = $stats->min_lowest_temp ?? 0; $this->maxLowestTemp = $stats->max_lowest_temp ?? 100; $this->minHighestTemp = $stats->min_highest_temp ?? 0; $this->maxHighestTemp = $stats->max_highest_temp ?? 100; } public function rules() { return [ 'selectedSpecies' => 'required', 'concentration' => 'required|numeric', 'soakDuration' => 'required|numeric', 'lowestTemp' => 'required|numeric', 'highestTemp' => 'required|numeric', 'note' => 'nullable|string|max:500', ]; } public function processForm() { $this->validate(); $this->isLoading = true; try { $response = Http::post('http://127.0.0.1:8000/process', [ 'species' => $this->selectedSpecies, 'emsConcentration' => (float) $this->concentration, 'soakDuration' => (int) $this->soakDuration, 'lowestTemp' => (float) $this->lowestTemp, 'highestTemp' => (float) $this->highestTemp, ]); if ($response->successful()) { $data = $response->json(); $this->result = $data['result']; $this->successRate = $data['success_rate']; $this->isSuccess = $this->result == 1; $this->overrideResult = (bool)$this->result; // Convert to boolean } else { $this->isSuccess = false; $this->overrideResult = false; } } catch (\Exception $e) { $this->isSuccess = false; $this->overrideResult = false; } finally { $this->isLoading = false; $this->showModal = true; } } public function closeModal() { $this->showModal = false; $this->isLoading = false; $this->note = ''; $this->manualOverride = false; } public function toggleOverride() { $this->manualOverride = !$this->manualOverride; } public function updateOverrideResult($value) { $this->overrideResult = (bool)$value; } public function save() { $this->validate([ 'note' => 'nullable|string|max:500', ]); $speciesId = Species::where('name', $this->selectedSpecies)->first()->id; $userId = auth()->user()->id; $finalResult = $this->manualOverride ? ($this->overrideResult ? 1 : 0) : $this->result; Treatment::create([ 'user_id' => $userId, 'species_id' => $speciesId, 'emsConcentration' => (float) $this->concentration, 'soakDuration' => (int) $this->soakDuration, 'lowestTemp' => (float) $this->lowestTemp, 'highestTemp' => (float) $this->highestTemp, 'result' => $finalResult, 'successRate' => $this->successRate, 'note' => $this->note, 'overridden' => $this->manualOverride, ]); Notification::make() ->title('Treatment Saved!') ->success() ->send(); $this->dispatch('treatment-created'); $this->closeModal(); // After saving, refresh the dynamic limits to include the new data $this->fetchDynamicLimits(); } }; ?>
Please wait while we analyze your parameters...
@if($manualOverride) {{ $overrideResult ? 'You have manually marked this treatment as successful.' : 'You have manually marked this treatment as failed.' }} @else {{ $isSuccess ? 'The process was successful with the given parameters.' : 'The process was unsuccessful with the given parameters. Consider adjusting your inputs.' }} @endif