Skip to content

Commit

Permalink
Merge pull request #88 from UCL-ARC/Shiying/tidying-up
Browse files Browse the repository at this point in the history
Shiying/tidying up
  • Loading branch information
shiyingwucl authored Jan 22, 2025
2 parents 168f88c + fa7a1b5 commit b12d80a
Show file tree
Hide file tree
Showing 14 changed files with 453 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.venv/
*pycache*/
.vscode/
test_role/shortlist.pickle
test-role_0001/shortlist.pickle
tests/shortlist.pickle
.pytest_cache/
.ruff_cache/
Expand Down
422 changes: 422 additions & 0 deletions 01.ipynb

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions notebooks/to-do-list
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
cancel sort
save comparison data for ranked file
alter comparison data


change where pickle,xlsx files are saved
15 changes: 10 additions & 5 deletions src/shortlister/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ def __init__(self, path, wv_window=None):
"s": (self.sort, "SCORE ASCENDING"),
"d": (self.sort, "SCORE DESCENDING"),
"c": (self.sort, "COMPARISON"),
"q":(self.sort,"QUIT SORT")
}
self.options_applicant_detail = {
"e": (self.score_applicant_step_1, "SCORE"),
Expand Down Expand Up @@ -321,6 +322,9 @@ def sort(self, k=None):
self.ctx.applicants = result
print()

elif k == "q":
self.option = self.options_applicant_table

self.show_applicants_table()

def filter_applicants(self, k=None):
Expand Down Expand Up @@ -373,13 +377,14 @@ def export_applicants_excel(self, k=None):
print()

def rank_selected_applicants(self, k=None):
result = tournament.get_existing_result(
Path(tournament.COMPARISON_RESULT_FILE_NAME)
)
result = tournament.comparison(self.ctx.applicants, result)

ranked_pickle_path = self.path/Path(tournament.COMPARISON_RESULT_FILE_NAME)
result = tournament.get_existing_result(ranked_pickle_path)
new_result = tournament.comparison(self.ctx.applicants, result)

tournament.save_rank(new_result,ranked_pickle_path)
# Condition to avoid exception (caused by empty result when quitting comparison with "q")
if result:
if not tournament.get_pair(self.ctx.applicants,new_result):
ranked_list = tournament.rank(self.ctx.applicants, result)
print("RESULT:", [applicant.name for applicant in ranked_list])
print()
Expand Down
10 changes: 7 additions & 3 deletions src/shortlister/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ def __repr__(self) -> str:
return self.name


@dataclass(eq=False)
@dataclass
class Applicant:
"""A property of Shortlist - contained within the attribute applicants(list of Applicant objects)."""

name: str = field(compare=True)
name: str
cv: Path
email: str
phone: str
Expand All @@ -47,6 +47,9 @@ def __repr__(self):

def __hash__(self):
return hash(self.cv)

def __eq__(self, other):
return hash(self) == hash(other)


@dataclass
Expand Down Expand Up @@ -118,7 +121,8 @@ def load_shortlist(path: Path) -> (Shortlist, str):

def load_role(path, criteria):
"""Generates role object instance."""
role = Role(str(path), "0001", criteria)
name, id = str(path).rsplit("_",1)
role = Role(job_title=name, job_id=id, criteria=criteria)
return role


Expand Down
13 changes: 3 additions & 10 deletions src/shortlister/tournament.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,7 @@ def comparison(list_to_rank, result: Dict = None):
print("TOURNAMENT COMPARISON")
print()

# start with an empty dict if we don't have existing results
if result is None:
result = {}

# Queue is a list of pairs that have not been compared yet
queue = get_pair(list_to_rank, result)

queue = get_pair(list_to_rank,result)
# Loop while there are still pairs to be compared in the queue
while len(queue) > 0:
# Remove the first pair in the queue and start the comparison
Expand All @@ -42,7 +36,7 @@ def comparison(list_to_rank, result: Dict = None):
if choice == "q":
print("EXITING TOURNAMENT COMPARISON")
print()
return
return result
# if undo last choice
elif choice == "u":
# take the key and requeue the pair
Expand Down Expand Up @@ -109,11 +103,10 @@ def save_rank(match_result, file: Path):


def get_existing_result(path: Path):
# Checks if there is existing result data
"""Checks if there is existing result data, or create a empty dict when there is no past results"""
if path.exists():
with open(path, "rb") as pickle_file:
result = pickle.load(pickle_file)
# If not, start a fresh comparison record
else:
result = {}
return result
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/test_controller.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from shortlister.controller import Controller
from pathlib import Path

controller = Controller(path=Path("test_role"))
controller = Controller(path=Path("test-role_0001"))


def test_create_controller():
Expand Down
6 changes: 3 additions & 3 deletions tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"Excellent": 40,
}
SCORES = list(SCORES_VALUES.keys())
path = Path("test_role")
path = Path("test-role_0001")
pickle_file_name = Path("shortlist.pickle")
csv_file = Path("criteria.csv")

Expand Down Expand Up @@ -52,7 +52,7 @@ def test_load_role():
]

result = model.load_role(path, model.load_criteria(path / csv_file))
expected = model.Role(job_title="test_role", job_id="0001", criteria=criteria)
expected = model.Role(job_title="test-role", job_id="0001", criteria=criteria)

assert result == expected

Expand Down Expand Up @@ -117,7 +117,7 @@ def test_save_load():

def test_load_applicant_from_pdf():
applicant: model.Applicant = model.load_applicants_from_pdf(
Path("test_role/Emma_Jones_16743_Candidate_Pack.pdf")
Path("test-role_0001/Emma_Jones_16743_Candidate_Pack.pdf")
)
assert applicant.name == "Emma Jones"
assert applicant.email == "[email protected]"
Expand Down

0 comments on commit b12d80a

Please sign in to comment.