File size: 2,686 Bytes
c643b04
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from __future__ import annotations


def profile(candidate: dict) -> dict:
    return candidate.get("profile") or {}


def current_role(candidate: dict) -> dict:
    roles = candidate.get("career_history") or []
    for role in roles:
        if role.get("is_current"):
            return role
    return roles[0] if roles else {}


def career_text(candidate: dict) -> str:
    parts: list[str] = []
    for role in candidate.get("career_history") or []:
        title = role.get("title") or ""
        company = role.get("company") or ""
        industry = role.get("industry") or ""
        desc = role.get("description") or ""
        parts.append(f"{title} at {company} ({industry}). {desc}")
    return "\n".join(p for p in parts if p.strip())


def summary_text(candidate: dict) -> str:
    p = profile(candidate)
    return "\n".join(str(x) for x in [p.get("headline"), p.get("summary")] if x)


def profile_text(candidate: dict) -> str:
    p = profile(candidate)
    return "\n".join(
        str(x)
        for x in [
            p.get("headline"),
            p.get("summary"),
            p.get("current_title"),
            p.get("current_industry"),
            p.get("location"),
            p.get("country"),
        ]
        if x
    )


def certification_text(candidate: dict) -> str:
    certs = candidate.get("certifications") or []
    if not certs:
        return ""
    names = [f"{c.get('name', '')} ({c.get('issuer', '')})" for c in certs[:6] if c.get("name")]
    return "Certifications: " + ", ".join(names) if names else ""


def language_text(candidate: dict) -> str:
    langs = candidate.get("languages") or []
    if not langs:
        return ""
    names = [f"{l.get('language', '')} ({l.get('proficiency', '')})" for l in langs[:4] if l.get("language")]
    return "Languages: " + ", ".join(names) if names else ""


def trusted_skill_names(candidate: dict, limit: int = 8) -> list[str]:
    skills = candidate.get("skills") or []
    ranked = sorted(
        skills,
        key=lambda s: (
            int(s.get("endorsements") or 0),
            int(s.get("duration_months") or 0),
            str(s.get("proficiency") or ""),
        ),
        reverse=True,
    )
    return [str(s.get("name")) for s in ranked[:limit] if s.get("name")]


def full_text(candidate: dict) -> str:
    skills = trusted_skill_names(candidate)
    skill_part = f"Skills: {', '.join(skills)}" if skills else ""
    return "\n".join(
        p
        for p in [
            profile_text(candidate),
            career_text(candidate),
            certification_text(candidate),
            language_text(candidate),
            skill_part,
        ]
        if p
    )