plan implementation 6, 7, 8, 9, 10
This commit is contained in:
37
app/Services/ScoringService.php
Normal file
37
app/Services/ScoringService.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\Session;
|
||||
|
||||
final class ScoringService
|
||||
{
|
||||
/**
|
||||
* Calculate the score for a session based on scored answers.
|
||||
*/
|
||||
public function calculateScore(Session $session): int
|
||||
{
|
||||
return $session->answers()
|
||||
->whereHas('question', fn ($q) => $q->where('is_scored', true))
|
||||
->where('value', 'yes')
|
||||
->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine the result based on the score.
|
||||
*/
|
||||
public function determineResult(int $score): string
|
||||
{
|
||||
if ($score >= 10) {
|
||||
return 'go';
|
||||
}
|
||||
|
||||
if ($score >= 5) {
|
||||
return 'consult_leadership';
|
||||
}
|
||||
|
||||
return 'no_go';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user