示例#1
0
def get_perfect_match_data(id_path, save_path):
    mid_list = util.load_pickle_file(id_path)
    match_col = dao.get_match_col()

    perfect_matches = {}  # teams: player ids, gold, win?

    for mid in mid_list:
        win_team = {}
        lose_team = {}
        perfect_matches[mid] = [win_team, lose_team]
        init_team(win_team)
        init_team(lose_team)
        print('Start working on match ID: {}'.format(mid))
        for m in match_col.find({c.MATCH_ID : mid}):
            if m[c.WINNER]:
                win_team[c.TEAM_INFO_PLAYERS].append(m[c.SUMMONER_ID])
                win_team[c.TEAM_INFO_CHAMPIONS].append(m[c.CHAMPION_ID])
                win_team[c.TEAM_INFO_GOLD_EARNED] += m[c.GOLD_EARNED]
                win_team[c.TEAM_INFO_GOLD_SPENT] += m[c.GOLD_SPENT]
            else:
                lose_team[c.TEAM_INFO_PLAYERS].append(m[c.SUMMONER_ID])
                lose_team[c.TEAM_INFO_CHAMPIONS].append(m[c.CHAMPION_ID])
                lose_team[c.TEAM_INFO_GOLD_EARNED] += m[c.GOLD_EARNED]
                lose_team[c.TEAM_INFO_GOLD_SPENT] += m[c.GOLD_SPENT]
    util.save(perfect_matches, save_path)
    print(perfect_matches[mid_list[0]])
示例#2
0
def find_perfect_matches(save_path):
    # Load player dict
    p_dict = util.load_pickle_file(player_dict_path)
    p_ids = p_dict.keys()
    # load matches
    match_col = dao.get_match_col()

    print('Start searching...')
    perfect_matches_ids = []
    done = False

    for m in match_col.find():
        m_id = m[c.MATCH_ID]
        if m_id not in perfect_matches_ids and match_col.find({c.MATCH_ID : m_id}).count() == 10:
            is_perfect = True
            for mm in match_col.find({c.MATCH_ID : m_id}):
                p_id = mm[c.SUMMONER_ID]
                if match_col.find({c.SUMMONER_ID : p_id}).count() < match_per_player:
                    is_perfect = False
                    break
            if is_perfect:
                perfect_matches_ids.append(m_id)
                print('Matches found: {}'.format(len(perfect_matches_ids)))
                if len(perfect_matches_ids) >= match_limit:
                    done = True
                    break

    print('Saving results...')
    util.save(perfect_matches_ids, save_path)
    print('Find {} perfect matches!'.format(len(perfect_matches_ids)))
def retrieve_player_features():
    # TODO load matches
    mid_list_path = "data/perfect_match_ids.pickle"

    mid_list = util.load_pickle_file(mid_list_path)
    match_col = dao.get_match_col()

    matches_per_player = 300
    player_dict_path = "data/player_dict_with_champ.pickle"
    player_dict = {}
    player_count = 0

    print("Start retrieving...")
    for mid in mid_list:
        for m in match_col.find({c.MATCH_ID: mid}):
            p_id = m[c.SUMMONER_ID]
            if p_id not in player_dict:
                player_dict[p_id] = {}
                p_match_count = 0
                for mm in match_col.find({c.SUMMONER_ID: p_id}):
                    if sanity_check(mm):
                        c_id = mm[CHAMPION_ID]
                        if c_id not in player_dict[p_id].keys():
                            init_player(player_dict, p_id, mm)
                        else:
                            update_player(player_dict, p_id, mm)
                        p_match_count += 1
                    if p_match_count == matches_per_player:
                        for c_id in player_dict[p_id]:
                            player_dict[p_id][c_id][FEATURES] = (
                                np.array(player_dict[p_id][c_id][FEATURES]) / player_dict[p_id][c_id][MATCH_COUNT]
                            )
                        player_count += 1
                        print("Finished players {}, latest player id {}".format(player_count, p_id))
                        break

    print("Writing dict to file...")
    with open(player_dict_path, "wb+") as f:
        pickle.dump(player_dict, f)

    print("Done!")
    return
示例#4
0
def find_perfect_matches_bak(save_path):
    # Load player dict
    p_dict = util.load_pickle_file(player_dict_path)
    p_ids = p_dict.keys()
    # TODO load matches
    client = MongoClient('mongodb://*****:*****@nb4800.neu.edu:12857/lol?authMechanism=SCRAM-SHA-1')
    lol_db = client['lol']
    match_col = dao.get_match_col()

    print('Start searching...')
    perfect_matches_ids = []
    done = False
    for id in p_ids:
        for m in match_col.find({c.SUMMONER_ID : id}):
            mid = m[c.MATCH_ID]
            if mid not in perfect_matches_ids:
                is_perfect_match = True
                player_count = 0
                for mm in match_col.find({c.MATCH_ID : mid}):
                    if mm[c.SUMMONER_ID] not in p_ids:
                        is_perfect_match = False
                        break
                    player_count += 1
                if is_perfect_match and player_count == 10:
                    perfect_matches_ids.append(mid)
                    print('Matches found: {}'.format(len(perfect_matches_ids)))
                    if len(perfect_matches_ids) >= match_limit:
                        done = True
                        break
        if done:
            break


    print('Saving results...')
    util.save(perfect_matches_ids, save_path)
    print('Find {} perfect matches!'.format(len(perfect_matches_ids)))