-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapplicant_review_processor.py
66 lines (48 loc) · 2.28 KB
/
applicant_review_processor.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
from typing import Any
from models.ApplicationData import Decision
def include_hacker_app_fields(
applicant_record: dict[str, Any], accept_threshold: float, waitlist_threshold: float
) -> None:
_include_decision_based_on_threshold(
applicant_record, accept_threshold, waitlist_threshold
)
_include_reviewers(applicant_record)
_include_avg_score(applicant_record)
def include_review_decision(applicant_record: dict[str, Any]) -> None:
"""Sets the applicant's decision as the last submitted review decision or None."""
reviews = applicant_record["application_data"]["reviews"]
applicant_record["decision"] = reviews[-1][2] if reviews else None
def get_num_unique_reviewers(applicant_record: dict[str, Any]) -> int:
reviews = applicant_record["application_data"]["reviews"]
unique_reviewers = {t[1] for t in reviews}
return len(unique_reviewers)
def _get_last_score(reviewer: str, reviews: list[tuple[str, str, float]]) -> float:
for review in reversed(reviews):
if review[1] == reviewer:
return review[2]
return -1
def _get_avg_score(reviews: list[tuple[str, str, float]]) -> float:
unique_reviewers = {t[1] for t in reviews}
if len(unique_reviewers) < 2:
return -1
last_score = _get_last_score(unique_reviewers.pop(), reviews)
last_score2 = _get_last_score(unique_reviewers.pop(), reviews)
return (last_score + last_score2) / 2
def _include_decision_based_on_threshold(
applicant_record: dict[str, Any], accept: float, waitlist: float
) -> None:
avg_score = _get_avg_score(applicant_record["application_data"]["reviews"])
if avg_score >= accept:
applicant_record["decision"] = Decision.ACCEPTED
elif avg_score >= waitlist:
applicant_record["decision"] = Decision.WAITLISTED
else:
applicant_record["decision"] = Decision.REJECTED
def _include_reviewers(applicant_record: dict[str, Any]) -> None:
reviews = applicant_record["application_data"]["reviews"]
unique_reviewers = {t[1].split(".")[-1] for t in reviews}
applicant_record["reviewers"] = sorted(list(unique_reviewers))
def _include_avg_score(applicant_record: dict[str, Any]) -> None:
applicant_record["avg_score"] = _get_avg_score(
applicant_record["application_data"]["reviews"]
)