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 }