def generate_match_list(contest_id): contest = get_contest_by_id(contest_id) player_list = get_player_list_by_contest_id(contest_id) print player_list.userIds if contest.format == "Single Round-Robin": n = contest.totalPlayers if n % 2 == 0: matches = [] for i in range(0, n - 1): for j in range(i, n - 1): t = (i + j) % (n - 1) + 1 if i == j: player1_id = player_list.userIds[i] player2_id = player_list.userIds[n - 1] else: player1_id = player_list.userIds[i] player2_id = player_list.userIds[j] match = Match(player1Id = player1_id, player2Id = player2_id, score1 = -1, score2 = -1, day = t) match.save() matches.append(match) else: matches = [] for i in range(0, n): for j in range(i, n): t = (i + j) % n + 1 if i == j: player1_id = player_list.userIds[i] player2_id = usermanage.get_user_by_name("", "BYE").id else: player1_id = player_list.userIds[i] player2_id = player_list.userIds[j] match = Match(player1Id = player1_id, player2Id = player2_id, score1 = -1, score2 = -1, day = t) match.save() matches.append(match) matches.sort(key = lambda Match: Match.day) match_list = MatchList(contestId = contest_id, matches = []) for i in matches: match_list.matches.append(i.id) match_list.save()
def get_match_list_by_contest_id(contest_id): return MatchList.objects(contestId = contest_id)[0]