Theoretically better handling of unassigned or N/A jobs

This commit is contained in:
Jacob Henry 2018-11-20 17:42:10 -05:00
parent 4d94d7586b
commit a15ae0fd11
2 changed files with 23 additions and 15 deletions

View File

@ -46,7 +46,7 @@ class JobAssignment(object):
Tracks a job's assignment and completion Tracks a job's assignment and completion
""" """
job: Job job: Job
assignee: scroll_util.Brother assignee: Optional[scroll_util.Brother]
signer: Optional[scroll_util.Brother] signer: Optional[scroll_util.Brother]
late: bool late: bool
bonus: bool bonus: bool
@ -152,11 +152,14 @@ async def import_assignments() -> List[Optional[JobAssignment]]:
# Now make an assignment for the job # Now make an assignment for the job
# Find the brother it is assigned to # Find the brother it is assigned to
if assignee is not None and assignee != "" and assignee != "N/A":
try: try:
assignee = await scroll_util.find_by_name(assignee, SHEET_LOOKUP_THRESHOLD) assignee = await scroll_util.find_by_name(assignee, SHEET_LOOKUP_THRESHOLD)
except scroll_util.BrotherNotFound: except scroll_util.BrotherNotFound:
# If we can't get one close enough, make a dummy # If we can't get one close enough, make a dummy
assignee = scroll_util.Brother(assignee, scroll_util.MISSINGBRO_SCROLL) assignee = scroll_util.Brother(assignee, scroll_util.MISSINGBRO_SCROLL)
else:
assignee = None
# Find the brother who is currently listed as having signed it off # Find the brother who is currently listed as having signed it off
try: try:

View File

@ -160,6 +160,7 @@ async def signoff_callback(slack: SlackClient, msg: dict, match: Match) -> None:
# Score by name similarity, only accepting non-assigned jobs # Score by name similarity, only accepting non-assigned jobs
def scorer(assign: house_management.JobAssignment): def scorer(assign: house_management.JobAssignment):
if assign.assignee is not None:
r = fuzz.ratio(signee.name, assign.assignee.name) r = fuzz.ratio(signee.name, assign.assignee.name)
if assign.signer is None and r > MIN_RATIO: if assign.signer is None and r > MIN_RATIO:
return r return r
@ -187,6 +188,7 @@ async def late_callback(slack: SlackClient, msg: dict, match: Match) -> None:
# Score by name similarity. Don't care if signed off or not # Score by name similarity. Don't care if signed off or not
def scorer(assign: house_management.JobAssignment): def scorer(assign: house_management.JobAssignment):
if assign.assignee is not None:
r = fuzz.ratio(signee.name, assign.assignee.name) r = fuzz.ratio(signee.name, assign.assignee.name)
if r > MIN_RATIO: if r > MIN_RATIO:
return r return r
@ -218,6 +220,7 @@ 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, # 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?) # as we want to be able to transfer even after signoffs (why not, amirite?)
def scorer(assign: house_management.JobAssignment): def scorer(assign: house_management.JobAssignment):
if assign.assignee is not None:
r = fuzz.ratio(from_bro.name, assign.assignee.name) r = fuzz.ratio(from_bro.name, assign.assignee.name)
if r > MIN_RATIO: if r > MIN_RATIO:
return r return r
@ -291,6 +294,8 @@ async def nag_callback(slack, msg, match):
response = "Do yer jerbs! They are as follows:\n" response = "Do yer jerbs! They are as follows:\n"
for assign in assigns: for assign in assigns:
# Make the row template # Make the row template
if assign.assignee is None:
continue
response += "({}) {} -- {} ".format(assign.job.house, assign.job.name, assign.assignee.name) response += "({}) {} -- {} ".format(assign.job.house, assign.job.name, assign.assignee.name)
# Find the people to @ # Find the people to @