Пример #1
0
    def print_group(self, channel, group):
        try:
            season = db.get_current_season()
            all_matches = db.get_matches_for_season(season)
            all_players = db.get_players()
            group_matches = [
                m for m in all_matches if m.grouping.lower() == group.lower()
            ]

            if not len(group_matches):
                raise Exception('Not a match')

            players = gather_scores(group_matches)
            message = 'Group ' + group.upper() + ':'

            for p in players:
                message += '\n' + get_player_name(
                    all_players, p['player_id']) + ' ' + str(
                        p['m_w']) + '-' + str(p['m_l'])
                message += ' (' + str(p['s_w']) + '-' + str(p['s_l']) + ')'

            self.slack_client.api_call("chat.postMessage",
                                       channel=channel,
                                       text=message,
                                       as_user=True)
        except Exception as e:
            self.logger.debug(e)
            self.slack_client.api_call("chat.postMessage",
                                       channel=channel,
                                       text="Not a group (or I messed up).",
                                       as_user=True)
Пример #2
0
def add_player_to_group(player_name, season_num):
    player = db.get_player_by_name(player_name)
    group_players = [
        p for p in db.get_active_players()
        if p.grouping == player.grouping and p.name != player_name
    ]
    dates = [m.week for m in db.get_matches_for_season(season_num)]
    dates = sorted(list(set(dates)))
    first = True
    for week in dates:
        if first:
            db.add_match(player, group_players.pop(0), week, player.grouping,
                         season_num)
            first = False
        db.add_match(player, group_players.pop(0), week, player.grouping,
                     season_num)
Пример #3
0
def send_custom_for_missed_games(message, num_missed, week, debug=True):
    season = db.get_current_season()
    season_matches = db.get_matches_for_season(season)
    players = {}
    for match in season_matches:
        if match.week <= week and match.winner_id is None:
            if match.player_1_id not in players:
                players[match.player_1_id] = set()
            if match.player_2_id not in players:
                players[match.player_2_id] = set()

            players[match.player_1_id].add(match.week)
            players[match.player_2_id].add(match.week)

    for player_id in players:
        test = len(players[player_id])
        if len(players[player_id]) >= num_missed:
            if debug and not player_id == bot_config.get_commissioner_slack_id(
            ):
                print('Sending to', player_id, ':', message)
            else:
                # slack_client.chat.post_message(player_id, message, as_user=True)
                print('For reals sent to', player_id, ':', message)
            time.sleep(1.5)
Пример #4
0
def print_new_groups():
    season = db.get_current_season()
    all_matches = db.get_matches_for_season(season)
    all_players = db.get_players()
    groups = sorted(list(set([m.grouping for m in all_matches])))

    last_group_letter = ''
    last_group = []
    last_relegated = []
    last_relegated_2 = []

    for group in groups:
        group_matches = [m for m in all_matches if m.grouping == group]
        players = match_making.gather_scores(group_matches)
        promoted = players[:2]
        player_names = []

        if len(last_group):
            for player in last_group + promoted + last_relegated_2:
                name = [
                    p.name for p in all_players
                    if p.slack_id == player['player_id']
                ][0]
                print("u'" + name + "': '" + last_group_letter + "',")

        last_relegated_2 = last_relegated[:]
        last_relegated = players[-2:]
        last_group = players[2:len(players) - 2]
        last_group_letter = group

    player_names = []
    for player in last_group + last_relegated_2:
        name = [
            p.name for p in all_players if p.slack_id == player['player_id']
        ][0]
        print("u'" + name + "': '" + last_group_letter + "',")
Пример #5
0
def print_season_markup(season=None):
    if season is None:
        season = db.get_current_season()
    all_matches = db.get_matches_for_season(season)
    all_players = db.get_players()
    groupings = list(set(map(lambda match: match.grouping, all_matches)))
    weeks = list(set(map(lambda match: match.week, all_matches)))
    groupings.sort()
    weeks.sort()
    output = ''
    ###
    ###||heading 1||heading 2||heading 3||
    ###|cell A1|cell A2|cell A3|
    ###|cell B1|cell B2|cell B3|
    max_group_size = 0
    for grouping in groupings:
        group_players = [p for p in all_players if p.grouping == grouping]
        if len(group_players) > max_group_size:
            max_group_size = len(group_players)

    standing_groups = []
    # standing_groups.append(groupings)
    standing_groups.append(groupings[:6])
    standing_groups.append(groupings[6:])
    first_group = True

    for standing_group in standing_groups:
        if first_group:
            first_group = False
            output += 'h2. Standings\n'
        else:
            output += 'h2. Standings Cont.\n'
        for grouping in standing_group:
            output += '||Group ' + grouping
        output += '||\n'
        for i in range(0, max_group_size):
            output += '|'

            for grouping in standing_group:
                group_matches = [
                    m for m in all_matches if m.grouping == grouping
                ]
                players = gather_scores(group_matches)
                if len(players) > i:
                    p = players[i]
                    output += get_player_name(
                        all_players,
                        p['player_id']) + ' ' + str(p['m_w']) + '-' + str(
                            p['m_l']
                        )  # + ' (' + str(p['s_w']) + '-' + str(p['s_l']) + ')'
                else:
                    output += ' '
                output += '|'
            output += '\n'

    for grouping in groupings:
        group_matches = [m for m in all_matches if m.grouping == grouping]
        output += '\nh2. Group ' + grouping + '\n'
        matches_by_week = {}
        for week in weeks:
            output += '||' + str(week)
            matches_by_week[week] = [
                m for m in group_matches if m.week == week
            ]
        output += '||\n'

        for i in range(0, len(matches_by_week[weeks[0]])):
            for week in weeks:
                if i >= len(matches_by_week[week]):
                    break
                m = matches_by_week[week][i]
                output += '|' + get_player_print(
                    all_players, m.player_1_id, m) + '\\\\' + get_player_print(
                        all_players, m.player_2_id, m)
            output += '|\n'

    return output
Пример #6
0
    player_ids = list(
        set([m.player_1_id
             for m in group_matches] + [m.player_2_id for m in group_matches]))
    played_matches = [m for m in group_matches if m.winner_id is not None]
    unplayed_matches = [copy(m) for m in group_matches if m.winner_id is None]
    #focus on each match, one at a time to see if it has implications for anyone
    for match in unplayed_matches:
        player_outcomes = {}
        for i in range(0, 6):
            player_outcomes[str(i)] = {}
            for player_id in player_ids:
                player_outcomes[str(i)][player_id] = []
            apply_combo(match, i)

            unplayed_matches_copy = [m for m in unplayed_matches if m != match]
            combinations = long(pow(2, len(unplayed_matches_copy)))
            for j in range(0, combinations):
                theoretical_matches = create_match_scenario(
                    unplayed_matches_copy, j)
                full_scenario = played_matches + [match] + theoretical_matches
                ordered_players = match_making.gather_scores(full_scenario)
                for player_id in player_ids:
                    player_outcomes[str(i)][player_id].append(
                        index_by_player_id(ordered_players, player_id))

        a = 0


all_matches = db.get_matches_for_season(db.get_current_season())
group_matches = [m for m in all_matches if m.grouping == 'B']
run_match_combinations(group_matches)