File size: 2,546 Bytes
c385a45
 
93a8810
c385a45
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import re
from datetime import datetime

SKILL_WEIGHTS = {
    "python": 5,
    "java": 5,
    "c++": 4,
    "sql": 4,
    "machine learning": 6,
    "data analysis": 5,
    "project management": 3,
    "communication": 2,
    "teamwork": 2,
    "leadership": 3,
}

EDUCATION_SCORES = {
    "PhD": 20,
    "Masters": 15,
    "Bachelors": 10,
    "Diploma": 5,
    "High School": 2,
    "Not Found": 0,
}

CERTIFICATION_KEYWORDS = [
    "certified", "certificate", "certification", "professional certification",
    "pmp", "aws certified", "cisco", "cissp", "six sigma", "scrum master"
]

def extract_experience_years(text):
    years = 0
    matches = re.findall(r'(\d+)\+?\s+years?', text.lower())
    if matches:
        years = max([int(m) for m in matches])
    year_ranges = re.findall(r'(\d{4})\s*[-to]{1,3}\s*(\d{4}|present)', text.lower())
    for start, end in year_ranges:
        try:
            start_year = int(start)
            end_year = datetime.now().year if end == "present" else int(end)
            diff = end_year - start_year
            if diff > years:
                years = diff
        except:
            continue
    return years

def score_experience(years):
    max_years = 10
    if years > max_years:
        years = max_years
    return (years / max_years) * 50

def score_skills(text):
    text_lower = text.lower()
    score = 0
    for skill, weight in SKILL_WEIGHTS.items():
        if skill in text_lower:
            score += weight
    max_score = sum(SKILL_WEIGHTS.values())
    return (score / max_score) * 30 if max_score else 0

def score_education(level):
    return EDUCATION_SCORES.get(level, 0)

def score_certifications(text):
    text_lower = text.lower()
    count = 0
    for cert_kw in CERTIFICATION_KEYWORDS:
        if cert_kw in text_lower:
            count += 1
    max_count = 3
    if count > max_count:
        count = max_count
    return (count / max_count) * 5

def calculate_cv_score(cv_text, education_level):
    years_exp = extract_experience_years(cv_text)
    exp_score = score_experience(years_exp)
    skill_score = score_skills(cv_text)
    edu_score = score_education(education_level)
    cert_score = score_certifications(cv_text)
    total_score = exp_score + skill_score + edu_score + cert_score
    return round(total_score, 2), {
        "Experience Score": round(exp_score, 2),
        "Skill Score": round(skill_score, 2),
        "Education Score": edu_score,
        "Certification Score": round(cert_score, 2),
        "Years of Experience": years_exp
    }