Skip to content

Commit

Permalink
Rank members on contest load
Browse files Browse the repository at this point in the history
  • Loading branch information
LukeSchmitt96 committed Sep 11, 2023
1 parent ecbf84b commit d429ff7
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions movie_bet_bot/models/movies/movies.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,10 @@ def from_config(config: dict) -> List[Contest]:
)
return contests

def rank_members(self) -> None:
"""Sort members by number of films watched first and watchtime second."""
self.members.sort(key=lambda x: (x.num_films_watched, x.watchtime), reverse=True)

async def update(self, get_film_details: bool = True, save_on_update: bool = True) -> bool:
"""
Update contest.
Expand Down Expand Up @@ -435,8 +439,7 @@ async def update(self, get_film_details: bool = True, save_on_update: bool = Tru
# update films watched since last update
member.update_films(member_last.filmlist.films)

# sort members by number of films watched first and watchtime second
self.members.sort(key=lambda x: (x.num_films_watched, x.watchtime), reverse=True)
self.rank_members()

if save_on_update and is_changed:
self.save()
Expand Down Expand Up @@ -487,6 +490,7 @@ def load(self) -> None:
return
conf = Contest.from_config(saved_data["contests"], from_config=False)[0]
self.members = conf.members
self.rank_members()
print("Loaded!")
except OSError as e:
print(f"Problem with database file at '{constants.DB_PATH}': ", e)
Expand Down

0 comments on commit d429ff7

Please sign in to comment.