|
| 1 | +import typing as t |
| 2 | + |
| 3 | +from ..schemas import Education, Experience, HrFlowProfile |
| 4 | +from .searching import is_valid_for_searching |
| 5 | + |
| 6 | + |
| 7 | +def is_valid_experiences_for_scoring( |
| 8 | + experience_list: t.Optional[t.List[Experience]], |
| 9 | +) -> bool: |
| 10 | + """ |
| 11 | + Check if a list of experiences is valid for scoring |
| 12 | +
|
| 13 | + Args: |
| 14 | + experience_list: <list> |
| 15 | + List of experiences to check |
| 16 | + Return: |
| 17 | + <bool> True if the list of experiences is valid for |
| 18 | + scoring, False otherwise |
| 19 | + """ |
| 20 | + for experience in experience_list: |
| 21 | + if experience.title: |
| 22 | + return True |
| 23 | + |
| 24 | + return False |
| 25 | + |
| 26 | + |
| 27 | +def is_valid_educations_for_scoring( |
| 28 | + education_list: t.Optional[t.List[Education]], |
| 29 | +) -> bool: |
| 30 | + """ |
| 31 | + Check if a list of educations is valid for scoring |
| 32 | +
|
| 33 | + Args: |
| 34 | + education_list: <list> |
| 35 | + List of educations to check |
| 36 | + Return: |
| 37 | + <bool> True if the list of educations is valid for |
| 38 | + scoring, False otherwise |
| 39 | + """ |
| 40 | + for education in education_list: |
| 41 | + if education.title or education.school: |
| 42 | + return True |
| 43 | + return False |
| 44 | + |
| 45 | + |
| 46 | +def is_valid_for_scoring( |
| 47 | + profile: t.Union[t.Dict, HrFlowProfile], |
| 48 | +) -> bool: |
| 49 | + """ |
| 50 | + Check if a profile is valid for scoring |
| 51 | +
|
| 52 | + Based on the following schemas https://developers.hrflow.ai/docs/profiles-scoring |
| 53 | +
|
| 54 | + Args: |
| 55 | + client: <Hrflow> |
| 56 | + Hrflow client |
| 57 | + profile: <dict> or <HrFlowProfile> |
| 58 | + Profile to check |
| 59 | + Return: |
| 60 | + <bool> True if the profile is valid for scoring, |
| 61 | + False otherwise |
| 62 | + """ |
| 63 | + if isinstance(profile, dict): |
| 64 | + profile = HrFlowProfile.parse_obj(profile) |
| 65 | + |
| 66 | + if not isinstance(profile, HrFlowProfile): |
| 67 | + raise ValueError("profile must be a dict or a HrFlowProfile object") |
| 68 | + |
| 69 | + return is_valid_for_searching(profile) and ( |
| 70 | + is_valid_experiences_for_scoring(profile.experiences) |
| 71 | + or is_valid_educations_for_scoring(profile.educations) |
| 72 | + or bool(profile.summary) |
| 73 | + or bool(profile.skills) |
| 74 | + or bool(profile.tasks) |
| 75 | + ) |
0 commit comments