def get_leaderboard(): db.session.expire_all() teams = list(Teams.query.all()) teams.sort(key=lambda x: (x.points(), -x.get_last_solved()), reverse=True) result = [] count, ranked_count = 0, 0 prevPoints = 0 for team in teams: points = team.points() if points == prevPoints and points == 0: if count > 0: count -= 1 if ranked_count > 0: ranked_count -= 1 if team.is_observer(): ranked_count -= 1 ranked_count += 1 count += 1 result.append((ranked_count, count, team)) prevPoints = points return result
def get_leaderboard_tids(ranked=True): teams = get_leaderboard() result = [(place if ranked == True else unranked_place, team.tid) if not(ranked == True and team.is_observer()) else None for place, unranked_place, team in teams] return filter(lambda x: x is not None, result)