-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmatchings.py
129 lines (101 loc) · 4.28 KB
/
matchings.py
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
from collections import Counter
import sys
from copy import deepcopy
def skill_skill_similarity(provided_level, required_level):
"""
Computes the similarity between two mastery levels of the same skill.
Args:
provided_level (int): Mastery level of the provided_skill.
required_level (int): Mastery level of the required_skill.
Returns:
float: Similarity ratio for the given skill levels, ranging from 0 to 1.
"""
return min(provided_level, required_level) / required_level
def learner_job_matching(learner, job):
"""
Computes the compatibility score between a learner's skills and a job's required skills.
For each required skill in the job, the function checks if the learner possesses that skill.
If so, it calculates a similarity ratio based on the learner's mastery level and the
job's required level for that skill. The final matching score is the average of all these
similarity ratios for all required skills, expressed as a percentage.
Args:
learner (dict): Dictionary containing details about the learner.
- "possessed_skills": Dictionary where keys are skill names and values
represent mastery levels.
- "year": Year associated with the learner's data.
job (dict): Dictionary containing job requirements.
- "required_skills": Dictionary where keys are skill names and values
represent required mastery levels.
- "year": Year associated with the job's data.
Returns:
float: Matching score between the learner and the job, ranging from 0 to 1.
Example:
learner = {
"possessed_skills": {
"Python": 3,
"JavaScript": 1
},
"year": 2020
}
job = {
"required_skills": {
"Python": 2,
"JavaScript": 3
},
"year": 2023
}
score = learner_job_matching(learner, job)
print(score) # This would output 66.66666
"""
matching = 0
# For each required skill in the job
for jskill, jlevel in job:
for lskill, llevel in learner:
if jskill == lskill:
matching += skill_skill_similarity(llevel, jlevel)
matching /= len(job)
return matching
def learner_course_required_matching(learner, course):
"""Computes the matching between a learner and a course based on the required skills.
If the course has no required skills, the matching is 1.
Args:
learner (dict): Learner's profile including possessed skills and levels.
course (dict): Course required and provided skills.
Returns:
float: matching value between 0 and 1
"""
if not course[0]:
return 1.0
required_matching = 0
for cskill, clevel in course[0]:
for lskill, llevel in learner:
if cskill == lskill:
sim = skill_skill_similarity(llevel, clevel)
required_matching += sim
return required_matching / len(course[0])
def learner_course_provided_matching(learner, course):
"""Computes the matching between a learner and a course based on the provided skills.
Args:
learner (dict): Learner's profile including possessed skills and levels.
course (dict): Course required and provided skills.
Returns:
float: matching value between 0 and 1
"""
provided_matching = 0
for cskill, clevel in course[1]:
for lskill, llevel in learner:
if cskill == lskill:
sim = skill_skill_similarity(llevel, clevel)
provided_matching += sim
return provided_matching / len(course[1])
def learner_course_matching(learner, course):
"""Computes the matching between a learner and a course.
Args:
learner (dict): Learner's profile including possessed skills and levels.
course (dict): Course required and provided skills.
Returns:
float: matching value between 0 and 1
"""
required_matching = learner_course_required_matching(learner, course)
provided_matching = learner_course_provided_matching(learner, course)
return required_matching * (1 - provided_matching)