예제 #1
0
def balance(bot, msg):
    participants = get_participants(bot, msg)

    # ensure that a valid number of participants have been passed
    if len(participants) not in [4, 6, 9, 12]:
        message = "Please provide a total of 4, 6, 9, or 12 usernames/times to balance."
        bot.sendmsg(msg.channel, message)
        return

    if len(participants) == 4:
        team_size = 2
    else:
        team_size = 3

    num_teams = len(participants) // team_size
    optimal_teams = list(chunk_list(participants, team_size))
    optimal_variance = variance([get_team_time(team).total_seconds() for team in optimal_teams])
    for pattern in PATTERNS_DICT[team_size][num_teams]:
        order = [participants[x] for x in pattern]
        new_teams = list(chunk_list(order, team_size))
        new_variance = variance([get_team_time(team).total_seconds() for team in new_teams])
        if new_variance < optimal_variance:
            optimal_teams = new_teams
            optimal_variance = new_variance

    message = ""
    for index, team in enumerate(optimal_teams):
        message += "Team " + NUMBERS[index] + ": \"" + ", ".join([participant.name for participant in team])
        message += "\" (" + format_time(get_team_time(team)) + ")\n"
    bot.sendmsg(msg.channel, message)
예제 #2
0
def team_time(bot, msg):
    participants = get_participants(bot, msg)

    blackout_time = get_team_time(participants)

    message = "Team \"" + ", ".join(msg.usernames + [str(time) for time in msg.times])
    message += "\" would take about " + format_time(blackout_time) + " to complete a blackout."
    bot.sendmsg(msg.channel, message)
예제 #3
0
def fast_balance(bot, msg):
    participants = get_participants(bot, msg)

    if len(participants) % 3 != 0:
        message = "Must be divisible by three to form teams"
        bot.sendmsg(msg.channel, message)
        return

    # sort so highest work rates are at the top
    participants = sorted(participants, reverse=True)

    # sort into three tiers of players
    num_teams = len(participants) // 3

    tier_one = participants[:num_teams]
    tier_two = participants[num_teams:num_teams * 2]
    tier_three = participants[num_teams * 2:]

    teams = []

    # pair the best of tier 1 with worst of tier 2
    for player_index in range(num_teams):
        teams.append([tier_one[player_index], tier_two[-player_index - 1]])

    # sorts the resulting teams with highest work rates at the top
    team_rate = lambda team: team[0].work_rate + team[1].work_rate
    teams = sorted(teams, key=team_rate, reverse=True)

    # pair the best current teams with the worst tier 3 players
    for player_index in range(num_teams):
        teams[player_index].append(tier_three[-player_index - 1])

    message = ""
    for index, team in enumerate(teams):
        message += "Team " + NUMBERS[index] + ": \"" + ", ".join([participant.name for participant in team])
        message += "\" (" + format_time(get_team_time(team)) + ")\n"
    bot.sendmsg(msg.channel, message)