Exemplo n.º 1
0
def Freq_table():
    # The dictionary to pass to pandas DataFrame
    df_dict = {}
    df_dict_index = 0

    for player in m.player_name_list():
        
        game_list = m.find_player_games(player)
        # len(game.index) -> The fastest way to get # of rows
        if len(game_list.index) == 0:
            continue

        # Extract file name (discard file extension)        
        game_list = list(set(game_list['File name'].to_list())) # Get rid of the same file names
        game_list = [int(os.path.splitext(game)[0]) for game in game_list]
        
        game_list.sort(reverse=True)
        game_diff = np.array([(game_list[i]-game_list[i+1]) for i in range(len(game_list)-1)])    

        # Game diff table
        if len(game_diff) == 0:
            continue
        df_dict[df_dict_index] = {"name":player,"min":np.min(game_diff), "max":np.max(game_diff), "avg": np.average(game_diff)}
        df_dict_index += 1

    df = pd.DataFrame.from_dict(df_dict, "index")
    path = rw.save_table_path('Freq_table.pkl')
    df.to_pickle(path) # --> Save file <--
Exemplo n.º 2
0
def find_player_ranks(name):
    '''
    -> Result_table: File name, Black player, Black Rank, White player, White Rank, Result
    -> Player_table: name,  n_game,  n_win,  n_lose,  n_black, ...
    -> Record_table: File name, Record


    extract RANKS from each game from the result table FOR A GIVEN PLAYER NAME
    loop through each player and read the result table, output the filename and the player’s rank 


    order by file name
    read (b/w) rank and player name
    print df

    input player name -> file name | rank
    '''

    player = m.find_player_games(name) # table of 'name' player only

    playerRank = player.loc[:, ['File name']] # create new df

    # print(player) # see original table

    player.loc[player['Black player'].str.contains(name), 'rank'] = player["Black Rank"]
    player.loc[player['White player'].str.contains(name), 'rank'] = player["White Rank"]
    playerRank['rank'] = player['rank'] # add player's rank to dataframe
    
    player.loc[player['Black player'].str.contains(name), 'op_rank'] = player["White Rank"]
    player.loc[player['White player'].str.contains(name), 'op_rank'] = player["Black Rank"]
    playerRank['op_rank'] = player['op_rank'] # add opponent's rank to dataframe

    return playerRank
Exemplo n.º 3
0
def beautiful_graph():
    df = rw.read_level_up_player_table()
    f_index = 0
    for index, player in df.iterrows():

        games = m.find_player_games(player['name'])
        name = hashlib.md5(player['name'].encode('UTF-8')).hexdigest()

        games['Black player'] = games['Black player'].map(
            lambda name: hashlib.md5(name.encode('UTF-8')).hexdigest())
        games['White player'] = games['White player'].map(
            lambda name: hashlib.md5(name.encode('UTF-8')).hexdigest())
        print(name)
        print(games.to_string())
        print(name)
        print(player[['rank', 'op rank']])

        # --- Graph Stuff ---
        plt.title(name)
        plt.xlabel('Game')
        plt.ylabel('Rank')
        plt.style.use('seaborn')

        x = [i for i in range(len(player['rank']))]
        y1 = player['rank']
        y2 = player['op rank']

        plt.plot(x, y1, color='g', alpha=0.6)
        plt.plot(x, y2, color='r', alpha=0.5)
        plt.legend(['player rank', 'opponent rank'])
        path = rw.save_graph_path(f'fuck_this_shit\\rank_graph_{f_index}.png')
        f_index += 1
        plt.savefig(path)
        plt.cla()
Exemplo n.º 4
0
# New sgf file path
path = r"/home/tatchakorn/Downloads/new gibo/"
path_list = os.listdir(path) # directory list
sgf_file_path = [os.path.join(path, _path, '*.sgf') for _path in path_list]
# generator expression for files end with '.sgf'
sgf_file_list = (glob.glob(_path) for _path in sgf_file_path)
sgf_files = (sgf_file for sgf_files in sgf_file_list for sgf_file in sgf_files)

counter_g = 0
for sgf_file in sgf_files:
    counter_g += 1
print(counter_g)
sys.exit()

player_game = m.find_player_games(name_f)
player_game = player_game["File name"].to_list()
for file_name in player_game:
    print(file_name)


player_game_path = [i for i in sgf_files if os.path.split(i)[-1] in player_game]

print(len(player_game_path))



dest_path = '/home/tatchakorn/Desktop/sgf_file_temp'

for game_path in player_game_path:
    g_file_name = os.path.split(game_path)[-1]
Exemplo n.º 5
0
loop through each player and read the result table, output the filename and the player’s rank 


order by file name
read (b/w) rank and player name
print df

input player name -> file name | rank
'''

name = 'shigepo'  # search this player

# df = rw.read_result_table() # the original table
# print(df.loc[:,:], '\n') # show table

player = m.find_player_games(name)  # table of 'name' player only
print(player.loc[:, :], '\n')  # show table

playerRank = player.loc[:, ['File name']]  # create new df

player.loc[player['Black player'].str.contains(name),
           'rank'] = player["Black Rank"]
player.loc[player['White player'].str.contains(name),
           'rank'] = player["White Rank"]
print(player)

playerRank['rank'] = player['rank']  #
print(playerRank.to_string())

# # bot_name = lambda df: (df["Black player"].str.contains('GoTrend', regex=False) | df["White player"].str.contains('GoTrend', regex=False))
# if (player.loc[player['Black player'].str.contains(name)], 'sth'):