blob: 029f368e65e4e1fb90cee088238ee678fb58f6f8 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
<?php
namespace App\Policies;
use App\Models\Company;
use App\Models\Student;
class ConnectionService
{
public static function calculateSkillMatchPercentage($studentId, $companyId): float
{
// Get the student and company with their skills
$student = Student::with('skills')->findOrFail($studentId);
$company = Company::with('skills')->findOrFail($companyId);
// Get the skill IDs as collections
$studentSkillIds = $student->skills->pluck('id');
$companySkillIds = $company->skills->pluck('id');
// If either has no skills, return 0%
if ($studentSkillIds->isEmpty() || $companySkillIds->isEmpty()) {
return 0;
}
// Count the matching skills
$matchingSkillsCount = $studentSkillIds->intersect($companySkillIds)->count();
// Calculate the total unique skills
$totalUniqueSkills = $studentSkillIds->union($companySkillIds)->count();
// Score krijgen op hoeveelheid van de student zijn skills overeenkomen
$matchPercentage = ($matchingSkillsCount / $studentSkillIds->count()) * 100;
// Round to 2 decimal places
return round(pow($matchPercentage, 1.1), 2);
}
}
|