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)
def create_matches_for_season(start_date, skip_weeks=[], include_byes=False): all_players = db.get_active_players() groupings = list(set(map(lambda player: player.grouping, all_players))) groupings.sort() all_matches = [] for grouping in groupings: group_players = [p for p in all_players if p.grouping == grouping] random.shuffle(group_players) group_matches = create_matches(start_date, group_players, skip_weeks, include_byes) for match in group_matches: match['grouping'] = grouping all_matches.extend(group_matches) season = db.get_current_season() season += 1 for match in all_matches: db.add_match(match['player_1'], match['player_2'], match['week'], match['grouping'], season) a = 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)
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 + "',")
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
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)