From 4d94d7586b5a07c1e68d51a54ba602bb70fec92a Mon Sep 17 00:00:00 2001 From: Jacob Henry Date: Tue, 20 Nov 2018 17:19:09 -0500 Subject: [PATCH] Made points more stable --- house_management.py | 15 +++++++++------ job_commands.py | 4 ++-- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/house_management.py b/house_management.py index 727ae7b..7061980 100644 --- a/house_management.py +++ b/house_management.py @@ -64,8 +64,7 @@ class PointStatus(object): """ Tracks a brothers points """ - brother_raw: str - brother: scroll_util.Brother # Interpereted + brother: scroll_util.Brother job_points: float = 0 signoff_points: float = 0 towel_points: float = 0 @@ -77,7 +76,7 @@ class PointStatus(object): def fmt(x: float): return round(x, 2) - return (self.brother_raw, + return (self.brother.name, fmt(self.job_points), fmt(self.signoff_points), fmt(self.towel_points), @@ -216,7 +215,8 @@ async def import_points() -> (List[str], List[PointStatus]): return None # Ensure its the proper length - row: List[Any] = row + ([0] * (field_count - len(row) - 1)) + while len(row) < field_count: + row: List[Any] = row + [0] # Ensure all past the first column are float. If can't convert, make 0 for i in range(1, len(row)): @@ -227,10 +227,13 @@ async def import_points() -> (List[str], List[PointStatus]): row[i] = x # Get the brother for the last item - real_brother = await scroll_util.find_by_name(row[0]) + try: + brother = await scroll_util.find_by_name(row[0]) + except scroll_util.BrotherNotFound: + brother = scroll_util.Brother(row[0], scroll_util.MISSINGBRO_SCROLL) # Ok! Now, we just map it directly to a PointStatus - status = PointStatus(row[0], real_brother, *(row[1:])) + status = PointStatus(brother, *(row[1:])) return status # Perform conversion and return diff --git a/job_commands.py b/job_commands.py index 0f55b16..41361c2 100644 --- a/job_commands.py +++ b/job_commands.py @@ -18,7 +18,7 @@ MIN_RATIO = 0.8 def alert_user(slack: SlackClient, brother: scroll_util.Brother, saywhat: str) -> None: """ - DM a brother saying something + DM a brother saying something. Wrapper around several simpler methods """ # We do this as a for loop just in case multiple people reg. to same scroll for some reason (e.g. dup accounts) for slack_id in identifier.lookup_brother_userids(brother): @@ -252,7 +252,7 @@ async def reset_callback(slack: SlackClient, msg: dict, match: Match) -> None: # Set to 0/default for i in range(len(points)): - new = house_management.PointStatus(brother_raw=points[i].brother_raw, brother=points[i].brother) + new = house_management.PointStatus(brother=points[i].brother) points[i] = new house_management.export_points(headers, points)