Skip to content

Commit

Permalink
[#44] Minor scroll improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
jrsmth-tier2 committed Apr 10, 2024
1 parent 8d72637 commit ff4718e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
5 changes: 4 additions & 1 deletion src/app/archbishop/archbishop.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ def unroll():
def group(group_id):
""" Get group information by id """
log.debug(f"[get_group] Retrieving group for id [{group_id}]")
return Response(str(redis.get_complex(group_id, Group)), status=200)
group = redis.get_complex(group_id, Group)
if group is None:
return Response("Cannot find group with id " + group_id, status=400)
return Response(str(group), status=200)

@archbishop.route(config.EVENT_PATH, methods=['POST'])
def event():
Expand Down
13 changes: 7 additions & 6 deletions src/app/model/group/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def from_dict(cls, dic):
)

def update_player(self, player):
""" Update player and handle streak reset if necessary """
for index, p in enumerate(self.players):
if p.name == player.name:
if player.streak == 0:
Expand All @@ -48,10 +49,7 @@ def update_scroll(self, player):
return

if self.__is_active(player.streak_id):
existing_record = [x for x in self.scroll if x.streak_id == player.streak_id][0]
existing_record.streak = player.streak
existing_record.date = datetime.today().strftime('%d/%m/%Y')
unsorted_scroll = [existing_record if x.streak_id == player.streak_id else x for x in self.scroll]
unsorted_scroll = [player.get_record() if x.streak_id == player.streak_id else x for x in self.scroll]
self.scroll = sorted(unsorted_scroll, key=lambda x: x.streak, reverse=True)

else:
Expand All @@ -72,9 +70,12 @@ def dethrone(self):
self.king = sorted(non_zeros, key=lambda x: x.streak, reverse=True)[0]

def __is_unworthy(self, new_streak):
""" Determine if streak is unworthy of scroll update by comparison to the lowest record """
""" Determine if streak is unworthy of scroll update """
sorted_scroll = sorted(self.scroll, key=lambda x: x.streak, reverse=False)
return len(self.scroll) == 3 and new_streak < sorted_scroll[0].streak
if new_streak < 2:
return True
else:
return len(self.scroll) == 3 and new_streak < sorted_scroll[0].streak

def __is_active(self, streak_id):
""" Determine if player streak is active in scroll by comparison with recorded streak ids """
Expand Down

0 comments on commit ff4718e

Please sign in to comment.