Ajustement des scores : test technique rapporté sur 20 et moyenne pondérée corrigée

This commit is contained in:
jeremy bayse
2026-03-20 17:46:42 +01:00
parent ec75942a79
commit 5c2bcb0169
5 changed files with 150 additions and 2 deletions

View File

@@ -9,11 +9,30 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Factories\HasFactory;
#[Fillable(['user_id', 'phone', 'linkedin_url', 'status', 'notes'])]
#[Fillable(['user_id', 'phone', 'linkedin_url', 'status', 'notes', 'cv_score', 'motivation_score', 'interview_score'])]
class Candidate extends Model
{
use HasFactory;
protected $appends = ['weighted_score'];
public function getWeightedScoreAttribute(): float
{
$cv = (float)$this->cv_score;
$motivation = (float)$this->motivation_score;
$interview = (float)$this->interview_score;
// On récupère le meilleur test (ramené sur 20)
$bestAttempt = $this->attempts()->whereNotNull('finished_at')->get()->map(function($a) {
return $a->max_score > 0 ? ($a->score / $a->max_score) * 20 : 0;
})->max() ?? 0;
$totalPoints = $cv + $motivation + $interview + $bestAttempt;
$maxPoints = 20 + 10 + 30 + 20; // Total potentiel = 80
return round(($totalPoints / $maxPoints) * 20, 2);
}
public function user(): BelongsTo
{
return $this->belongsTo(User::class);