From a15ae0fd11bc53d5ef54c74e5ed60240e54b7100 Mon Sep 17 00:00:00 2001 From: Jacob Henry Date: Tue, 20 Nov 2018 17:42:10 -0500 Subject: [PATCH] Theoretically better handling of unassigned or N/A jobs --- house_management.py | 15 +++++++++------ job_commands.py | 23 ++++++++++++++--------- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/house_management.py b/house_management.py index 7061980..a927d72 100644 --- a/house_management.py +++ b/house_management.py @@ -46,7 +46,7 @@ class JobAssignment(object): Tracks a job's assignment and completion """ job: Job - assignee: scroll_util.Brother + assignee: Optional[scroll_util.Brother] signer: Optional[scroll_util.Brother] late: bool bonus: bool @@ -152,11 +152,14 @@ async def import_assignments() -> List[Optional[JobAssignment]]: # Now make an assignment for the job # Find the brother it is assigned to - try: - assignee = await scroll_util.find_by_name(assignee, SHEET_LOOKUP_THRESHOLD) - except scroll_util.BrotherNotFound: - # If we can't get one close enough, make a dummy - assignee = scroll_util.Brother(assignee, scroll_util.MISSINGBRO_SCROLL) + if assignee is not None and assignee != "" and assignee != "N/A": + try: + assignee = await scroll_util.find_by_name(assignee, SHEET_LOOKUP_THRESHOLD) + except scroll_util.BrotherNotFound: + # If we can't get one close enough, make a dummy + assignee = scroll_util.Brother(assignee, scroll_util.MISSINGBRO_SCROLL) + else: + assignee = None # Find the brother who is currently listed as having signed it off try: diff --git a/job_commands.py b/job_commands.py index 41361c2..52e28ea 100644 --- a/job_commands.py +++ b/job_commands.py @@ -160,9 +160,10 @@ async def signoff_callback(slack: SlackClient, msg: dict, match: Match) -> None: # Score by name similarity, only accepting non-assigned jobs def scorer(assign: house_management.JobAssignment): - r = fuzz.ratio(signee.name, assign.assignee.name) - if assign.signer is None and r > MIN_RATIO: - return r + if assign.assignee is not None: + r = fuzz.ratio(signee.name, assign.assignee.name) + if assign.signer is None and r > MIN_RATIO: + return r # Set the assigner, and notify def modifier(context: _ModJobContext): @@ -187,9 +188,10 @@ async def late_callback(slack: SlackClient, msg: dict, match: Match) -> None: # Score by name similarity. Don't care if signed off or not def scorer(assign: house_management.JobAssignment): - r = fuzz.ratio(signee.name, assign.assignee.name) - if r > MIN_RATIO: - return r + if assign.assignee is not None: + r = fuzz.ratio(signee.name, assign.assignee.name) + if r > MIN_RATIO: + return r # Just set the assigner def modifier(context: _ModJobContext): @@ -218,9 +220,10 @@ async def reassign_callback(slack: SlackClient, msg: dict, match: Match) -> None # Score by name similarity to the first brother. Don't care if signed off or not, # as we want to be able to transfer even after signoffs (why not, amirite?) def scorer(assign: house_management.JobAssignment): - r = fuzz.ratio(from_bro.name, assign.assignee.name) - if r > MIN_RATIO: - return r + if assign.assignee is not None: + r = fuzz.ratio(from_bro.name, assign.assignee.name) + if r > MIN_RATIO: + return r # Change the assignee def modifier(context: _ModJobContext): @@ -291,6 +294,8 @@ async def nag_callback(slack, msg, match): response = "Do yer jerbs! They are as follows:\n" for assign in assigns: # Make the row template + if assign.assignee is None: + continue response += "({}) {} -- {} ".format(assign.job.house, assign.job.name, assign.assignee.name) # Find the people to @