Made points more stable

This commit is contained in:
Jacob Henry 2018-11-20 17:19:09 -05:00
parent d22fadf445
commit 4d94d7586b
2 changed files with 11 additions and 8 deletions

View File

@ -64,8 +64,7 @@ class PointStatus(object):
""" """
Tracks a brothers points Tracks a brothers points
""" """
brother_raw: str brother: scroll_util.Brother
brother: scroll_util.Brother # Interpereted
job_points: float = 0 job_points: float = 0
signoff_points: float = 0 signoff_points: float = 0
towel_points: float = 0 towel_points: float = 0
@ -77,7 +76,7 @@ class PointStatus(object):
def fmt(x: float): def fmt(x: float):
return round(x, 2) return round(x, 2)
return (self.brother_raw, return (self.brother.name,
fmt(self.job_points), fmt(self.job_points),
fmt(self.signoff_points), fmt(self.signoff_points),
fmt(self.towel_points), fmt(self.towel_points),
@ -216,7 +215,8 @@ async def import_points() -> (List[str], List[PointStatus]):
return None return None
# Ensure its the proper length # 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 # Ensure all past the first column are float. If can't convert, make 0
for i in range(1, len(row)): for i in range(1, len(row)):
@ -227,10 +227,13 @@ async def import_points() -> (List[str], List[PointStatus]):
row[i] = x row[i] = x
# Get the brother for the last item # 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 # 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 return status
# Perform conversion and return # Perform conversion and return

View File

@ -18,7 +18,7 @@ MIN_RATIO = 0.8
def alert_user(slack: SlackClient, brother: scroll_util.Brother, saywhat: str) -> None: 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) # 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): 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 # Set to 0/default
for i in range(len(points)): 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 points[i] = new
house_management.export_points(headers, points) house_management.export_points(headers, points)