TFT 데이터 분석- 유닛, 아이템, 증강체 summary

Jaehyun_onelion·2023년 3월 20일
0

Side Project - TFT

목록 보기
6/10
post-thumbnail

저번 포스트에서 api에서 얻을 수 있는 원데이터에서 경기 데이터를 수집했다.

수집한 데이터를 바탕으로 실제 분석에 사용할 수 있는 유닛, 아이템, 증강체 데이터프레임 만든 과정을 정리했다.

  • 이전 포스트부터 이어지는 이야기이다. 코드 중 이전 포스트 코드가 포함되어 있으니 참고하기.

1. 현재 만든 데이터프레임

현재까지 만든 데이터프레임은 다음과 같다.

하지만 해당 데이터프레임에서는 유닛과, 유닛에 해당하는 성(star)수, 아이템을 뽑기 어렵다. 따라서 해당 데이터프레임에서는 증강체만, unit 데이터프레임을 따로 만들어 두 데이터프레임을 합쳐줄 것이다.

2. 유닛 정보 데이터프레임 만들기

1) unit dataframe 만들기

첫 번째로 unit 데이터프레임을 만들어주어야 한다. player별로 사용한 유닛과 해당 유닛의 성수, 사용 아이템을 열로 하는 데이터프레임을 만들어주었다.

def make_unit_dataframe(unit):
    
        units = pd.DataFrame(unit)
        
        if units.shape[0]==0:
            return pd.DataFrame(columns = ['character_id', 'champ_name', 'rarity', 'tier', 'items', 'item1', 'item2', 'item3'])
        

        item_list = []
        champ_name = []
        for i in range(len(units['character_id'])):
            
            champ_name.append(champ_list[units['character_id'][i]])
            check = units['itemNames'][i]

            check += [0]*(3-len(check))

            item_list.append(check)

        units['items'] = item_list

        item1 = []
        item2 = []
        item3 = []

        for item in item_list:

            check_item = []

            for i in item:
                if i=='None':
                    check_item.append('None')
                else:
                    item_kor = items.loc[items.apiName==i, 'name'].values[0]
                    check_item.append(item_kor)
            item1.append(check_item[0])
            item2.append(check_item[1])
            item3.append(check_item[2])


        units = pd.DataFrame(unit).drop(['itemNames', 'name'], axis=1)

        units['item1'] = item1
        units['item2'] = item2
        units['item3'] = item3
        units['champ_name'] = champ_name

        return units

해당 함수는 이전 포스트에서 유닛 데이터프레임을 직접 만들어주는 함수이다. 특정 플레이어의 유닛 결과를(participants - unit) 입력하면, 다음과 같은 데이터프레임을 얻을 수 있다.

make_unit_dataframe(pd.DataFrame(participants.loc[0, 'units']))

해당 데이터프레임에서 필요한 것은 tier, item1, item2, item3, champ_name이다. 또한 다른 데이터프레임과 합쳐지려면 해당 게임의 datetime, id, 그리고 해당 player_id가 필요하다. 따라서 해당 column들로 이루어진 데이터프레임을 만들어주는 함수를 만들었다.

def make_unit_result(dataframe, number, game_id, datetime):

    unit1 = make_unit_dataframe(dataframe.loc[number, 'units'])
    unit1['Datetime'] = datetime
    unit1['Game_id'] = game_id
    unit1['Player_id'] = dataframe.loc[number, 'puuid']
    unit1 = unit1[['Datetime', 'Game_id', 'Player_id', 'character_id', 'champ_name', 'rarity', 'tier', 'item1', 'item2', 'item3']]
    return unit1

# 코드 실행
make_unit_result(participants, 0, game_summary['Game_id'][0], game_summary['Datetime'][0])

해당 데이터프레임은 한 게임의 한 플레이어의 유닛 결과이다. 게임 플레이어마다 쌓아주면 unit 정보 데이터프레임이 완성된다.

unit_dataframe = pd.DataFrame(dict(Datetime = [], Game_id = [], Player_id = [], character_id = [], champ_name=[], rarity = [], tier = [], item1=[], item2=[], item3=[]))

for i in range(participants.shape[0]):
    check = make_unit_result(participants, i, game_summary['Game_id'][0], game_summary['Datetime'][0])
    unit_dataframe = pd.concat([unit_dataframe, check])
    
    
unit_dataframe = unit_dataframe.reset_index(drop=True)

# 결과 출력

unit_dataframe

2) 도적의 장갑 변환하기

도적의 장갑이나 장난꾸러기의 장갑을 사용할 경우 item1에는 도적의 장갑(또는 장난꾸러기의 장갑)이, item2, item3에는 마지막 라운드에서의 도적의 장갑 아이템이 추출된다. 따라서 도적의 장갑을 가지고 있는 유닛의 나머지 두 아이템은 없는 것으로 처리해야 한다. 위의 unit_dataframe을 입력하면 도적의 장갑 처리를 해주는 함수를 만들었다.

 def change_gloves_item(item_result):
    
    check = np.logical_or(item_result.item1=='도적의 장갑', item_result.item1=='장난꾸러기의 장갑')
    
    item_result.loc[check, 'item2']='None'
    
    item_result.loc[check, 'item3'] = 'None'
                          
    return item_result

# 결과 출력

unit_dataframe = change_gloves_item(unit_dataframe)

unit_dataframe

보이는 것과 같이 index 59에 해당하는 item2, item3가 사라졌다.

착용한 아이템 개수 세기

유닛이 착용한 아이템 수는 해당 유닛이 키 유닛인지 아닌지 판단하는 지표가 될 수 있다. 따라서 unit_dataframe에서 해당 unit이 가지고 있는 아이템의 수를 num_item column으로 만들어주었다.


def check_item_unit_itemver(unit_result):
    
    check = unit_result.apply(lambda x : 3-list(x).count('None'), axis=1)
    
    
    unit_result['num_item'] = check
    
    return unit_result


# 결과 출력

unit_dataframe = check_item_unit_itemver(unit_dataframe)

unit_dataframe

해당 데이터프레임(unit_dataframe)과 이전 포스트에서 만든 게임 결과 데이터프레임(game_summary)을 이용해 유닛, 증강체, 아이템 간 통계 정보를 요약해주는 데이터프레임을 만들 것이다.

3. Summary 데이터프레임 만들기

통계 정보 요약 데이터프레임을 만들기 위해, 해당 유닛을 사용한 유저의 등수가 필요하다. 따라서 join을 통해 두 데이터프레임을 묶어주고, 필요한 column만 추출해주는 함수를 만들었다.


def joining_game_unit(game_result, item_result):
    
    result = pd.merge(item_result, game_result[['Game_id', 'Player_id', 'Placement', 'augment1', 'augment2', 'augment3']], on=['Game_id', 'Player_id'])

    result = result[['Datetime', 'Game_id', 'Player_id', 'Placement', 'augment1', 'augment2', 'augment3', 'champ_name', 'rarity', 'tier', 'item1', 'item2', 'item3', 'num_item']]
    
    return result
    
# 결과 출력

after_join = joining_game_unit(game_summary, unit_dataframe)

after_join

이제 증강체, 유닛, 아이템에 대한 통계량을 만들면 된다. 각각에 대해 살펴볼 통계량은 다음과 같다. 여기서 순방은 게임 등수가 4위 이내인 경우를 뜻하고, 승리는 게임 등수가 1위인 경우를 뜻한다.

증강체

  1. Count : 해당 증강체를 사용한 횟수
  2. Ave_score : 해당 증강체를 사용한 플레이어의 평균 등수
  3. Ave_score_save : 해당 증강체를 사용한 플레이어가 순방했을 때의 평균 등수
  4. Win_count : 해당 증강체를 사용한 플레이어가 승리한 횟수
  5. Win_rate : 해당 증강체를 사용한 플레이어 중 승리한 플레이어 비율
  6. Save_count : 해당 증강체를 사용한 플레이어가 순방한 횟수
  7. Save_rate : 해당 증강체를 사용한 플레이어 중 순방한 플레이어 비율

유닛

  1. Count : 해당 유닛 사용한 회수
  2. Ave_score : 해당 유닛을 사용한 플레이어의 평균 등수
  3. Ave_score_save : 해당 유닛을 사용한 플레이어가 순방했을 때의 평균 등수
  4. Ave_star : 해당 유닛의 평균 성수
  5. Ave_star_save : 해당 유닛을 사용한 플레이어 중 순방했을 때의 평균 성수
  6. Ave_star_win : 해당 유닛을 사용한 플레이어 중 승리했을 때의 평균 성수
  7. Win_count : 해당 유닛을 사용한 플레이어가 승리한 횟수
  8. Win_rate : 해당 유닛을 사용한 플레이어 중 승리한 플레이어 비율
  9. Save_count : 해당 유닛을 사용한 플레이어가 순방한 횟수
  10. Save_rate : 해당 유닛을 사용한 플레이어 중 순방한 플레이어 비율
  11. Num_items_count : 해당 유닛의 아이템 총 수
  12. Num_items_avg : 해당 유닛의 아이템 평균 숫자
  13. Num_items_save : 해당 유닛을 사용한 플레이어가 순방했을 때, 유닛이 가진 아이템 평균 숫자
  14. Num_items_win : 해당 유닛을 사용한 플레이어가 이겼을 때, 유닛이 가진 아이템 평균 숫자
  15. Full_items_count : 해당 유닛을 사용한 플레이어 중 해당 유닛에 3개의 아이템을 부여한 횟수
  16. Full_item_rate : 해당 유닛을 사용한 플레이어 중 해당 유닛에 3개의 아이템을 부여한 비율
  17. Full_item_save : 해당 유닛을 사용한 플레이어가 순방했을 때, 해당 유닛에 3개의 아이템을 부여한 비율
  18. Full_item_win : 해당 유닛을 사용한 플레이어가 승리했을 때, 해당 유닛에 3개의 아이템을 부여한 비율

아이템

  1. Count : 해당 아이템을 사용한 플레이어 수
  2. Ave_score : 해당 아이템을 사용한 플레이어의 평균 등수
  3. Ave_score_save : 해당 아이템을 사용한 플레이어가 순방했을 때, 평균 등수
  4. Win_count : 해당 아이템을 사용한 플레이어가 승리한 횟수
  5. Win_rate : 해당 아이템을 사용한 플레이어 중 승리한 플레이어 비율
  6. Save_count : 해당 아이템를 사용한 플레이어가 순방한 횟수
  7. Save_rate : 해당 아이템를 사용한 플레이어 중 순방한 플레이어 비율
  • 순방 여부를 따지는 이유는 게임 결과 4위 이내 달성 시 랭크 점수가 오르고, 5위 이후부터는 랭크 점수가 떨어지기 때문이다. 따라서 4위 이내 달성 여부 또한 확인해야할 지표 중 하나이다.
  • 유닛의 경우 순방했을 때의 성수, 아이템 수 등을 추가했는데, 순방을 못하는 플레이어 중 상대적으로 4코스트 이하의 유닛들이 많기 때문이다.(5코스트보다 뽑기 쉽기 때문에) 따라서 평균 등수를 낮추는 원인이라고 생각하여, 순방한 플레이어 중에서 해당 유닛의 통계를 추가적으로 조사했다.

기본 골조 데이터프레임

위에서 제시한 지표를 column으로, 각각의 아이템/유닛/증강체를 row로 하는 데이터프레임을 csv파일로 제작했다.

해당 데이터프레임을 각각 item_list, unit_list, augment_list로 작성했다. 해당 csv 파일은 github에서 확인가능하다.

github


item_list = pd.read_csv('item_list.csv', encoding='cp949')

unit_list = pd.read_csv('champion_list.csv', encoding='cp949')

augment_list = pd.read_csv('augment_list.csv', encoding='cp949')




차례로 item_list, unit_list, augment_list이다.

이제 해당 데이터프레임에 결과를 축적시키면 된다. 앞서 작성한 after_join 데이터를 이용하여 각각 데이터프레임에 결과를 입력해주는 함수를 작성했다.
after_join의 row마다 결과를 입력해주면 for문을 사용하게 되는데, 데이터의 수가 커지면 시간이 오래 걸리는 문제가 발생한다. 따라서 augment와 item의 경우 등수에 따라 데이터를 분리한 뒤, Counter를 이용해서 증강체/아이템 별 사용 횟수를 계산해주고, 조건에 맞는 entry에 해당 값을 더해주었다. unit의 경우 등수, 아이템, 성수에 따라 데이터를 분리했다.

해당 방법론을 사용했을 때, 3만여 게임 결과 통계 제작 시 1분 내로 제작이 가능했다. (빠른 방법 있으면 추천 받습니다... 데이터 처리 및 관리 부분은 잘 몰라서요..)

from collections import Counter
from copy import deepcopy


def make_augment_stack(game_result, augment_list, num_game):

        check = game_result[['Datetime', 'Game_id', 'Player_id', 'Placement', 'augment1', 'augment2', 'augment3']].drop_duplicates()

        result = augment_list.copy()

        for i in range(1, 9):
            place = check.loc[check.Placement==i, ]

            augments = place.augment1.tolist() + place.augment2.tolist() + place.augment3.tolist()

            augments = Counter(augments)

            augment_result = [0]*7


            for augment in augments.keys():

                number = augments[augment]

                if i==1:
                    augment_score = [number, number*i, number*i, number, number, number, number]

                elif i<=4:
                    augment_score = [number, number*i, number*i, 0, 0, number, number]

                else:
                    augment_score = [number, number*i, 0, 0, 0, 0, 0]


                result.loc[result.Name == augment, 
                                 ['Count', 'Ave_score', 'Ave_score_save', 'Win_count', 'Win_rate', 'Save_count', 'Save_rate']] +=augment_score



        result.Ave_score = round(result.Ave_score/result.Count, 1)

        result.Ave_score_save = round(result.Ave_score_save/result.Save_count, 1)

        result.Win_rate = round(result.Win_rate/result.Count*100, 1)

        result.Save_rate = round(result.Save_rate/result.Count*100, 1)



        return result




    def make_unit_stack(self, game_result, champion_list, num_game):

        result = champion_list.copy()

        for placement in range(1, 9):

            for tier in range(1, 4):

                for num_item in range(1, 4):


                    case = np.logical_and(np.logical_and(game_result.Placement == placement, game_result.tier==tier),
                                          game_result.num_item == num_item)

                    champions = game_result.loc[case, 'champ_name'].tolist()

                    champions = Counter(champions)


                    for champion in champions.keys():

                        number = champions[champion]

                        if placement==1:



                            score = [number, number*placement, number*placement, number*tier, number*tier, number*tier, number, number, number, number, num_item*number, num_item*number, num_item*number, num_item*number]

                            if num_item==3:
                                score += [number]*4
                            else:
                                score += [0]*4

                        elif placement<=4:

                            score = [number, number*placement, number*placement, number*tier, number*tier, 0, 0, 0, number, number, num_item*number, num_item*number, num_item*number, 0]

                            if num_item==3:
                                score += [number]*3 +[0]

                            else:
                                score += [0]*4
                        else:

                            score = [number, number*placement, 0, number*tier, 0, 0, 0, 0, 0, 0, num_item*number, num_item*number, 0, 0]

                            if num_item==3:

                                score += [number]*2 +[0]*2
                            else:
                                score += [0]*4


                        result.loc[result.Name == champion, ['Count', 'Ave_score', 'Ave_score_save', 'Ave_star', 'Ave_star_save', 'Ave_star_win',
                                                                          'Win_count', 'Win_rate', 'Save_count', 'Save_rate',
                                                                          'Num_items_count', 'Num_items_avg', 'Num_items_save', 'Num_items_win', 'Full_item_count', 'Full_item_rate', 'Full_item_save', 'Full_item_win']] += score


        result.Ave_score = round(result.Ave_score / result.Count, 1)

        result.Ave_score_save =round(result.Ave_score_save / result.Save_count, 1)

        result.Win_rate = round(result.Win_rate / result.Count*100, 1)

        result.Save_rate = round(result.Save_rate / result.Count*100, 1)

        result.Ave_star = round(result.Ave_star / result.Count, 1)

        result.Ave_star_save = round(result.Ave_star_save / result.Save_count, 1)

        result.Ave_star_win = round(result.Ave_star_win/result.Win_count, 1)


        result.Num_items_avg = round(result.Num_items_avg/result.Count, 1)

        result.Num_items_save = round(result.Num_items_save/result.Save_count, 1)

        result.Num_items_win = round(result.Num_items_win/result.Win_count, 1)

        result.Full_item_rate = round(result.Full_item_rate/result.Count*100, 1)

        result.Full_item_save = round(result.Full_item_save/result.Save_count*100, 1)

        result.Full_item_win = round(result.Full_item_win / result.Win_count*100, 1)



        return result







    def make_item_stack(self, game_result, item_list, num_game):

        result = item_list.copy()

        for placement in range(1, 9):

            check = game_result.loc[game_result.Placement==placement, :]

            items = check.item1.tolist() + check.item2.tolist() + check.item3.tolist()

            items = Counter(items)

            for item in items.keys():

                if item=='None':
                    continue

                else:

                    number = items[item]

                    if placement==1:
                        item_score = [number, number*placement, number*placement, number, number, number, number]

                    elif placement<=4:
                        item_score = [number, number*placement, number*placement, 0, 0, number, number]

                    else:
                        item_score = [number, number*placement, 0, 0, 0, 0, 0]

                result.loc[result.Name==item, ['Count', 'Ave_score', 'Ave_score_save', 'Win_count', 'Win_rate', 'Save_count', 'Save_rate']] += item_score


        result.Ave_score = round(result.Ave_score/result.Count, 1)

        result.Ave_score_save = round(result.Ave_score_save/result.Save_count, 1)

        result.Win_rate = round(result.Win_rate/result.Count*100, 1)

        result.Save_rate = round(result.Save_rate/result.Count*100, 1)


        return result

# augment 결과 출력

make_augment_stack(after_join, augment_list).sort_values('Count', ascending=False)

# unit 결과 출력

make_unit_stack(after_join, unit_list).sort_values('Count', ascending=False)

# item 결과 출력

make_item_stack(after_join, item_list).sort_values('Count', ascending=False)

차례로 augment 통계, 챔피언 통계, 아이템 통계를 뜻한다.

4. augment, unit, item 상호 비교

이제 해당 통계를 아이템과 유닛, 증강체 단독으로도 만들 수 있지만, 두 변수를 연결지어 생각할 수도 있다. 예를 들어

  • 유닛 사미라가 사용한 아이템/증강체 통계를 알고 싶다.
  • 사냥의 전율 증강체를 사용했을 때 아이템/유닛 통계를 알고 싶다.
  • 무한의 대검을 사용한 챔피언/증강체 통계를 알고 싶다.

이 경우 특정 아이템/유닛/증강체를 사용한 플레이어가 속한 게임을 추출한 뒤, 위의 통계 데이터프레임을 제작하면 된다. 이에 대한 함수가 앞으로 나올 9개의 함수이다.

# 증강체 vs 증강체

def augment_augment_crosscheck(game_result, augment_result, augment):
    
    check = np.logical_or(np.logical_or(game_result.augment1==augment, game_result.augment2==augment), game_result.augment3==augment)
    
    check = game_result[check]
    
    check_augment = make_augment_stack(check, augment_result)
    
    return check_augment

# 증강체 vs 유닛

def augment_champion_crosscheck(game_result, champion_result, augment):
    
    check = np.logical_or(np.logical_or(game_result.augment1==augment, game_result.augment2==augment), game_result.augment3==augment)
    
    check = game_result[check]
    
    check_champion = make_unit_stack(check, champion_result)
    
    
    return check_champion

# 증강체 vs 아이템

def augment_item_crosscheck(game_result, item_result, augment):
    
    check = np.logical_or(np.logical_or(game_result.augment1==augment, game_result.augment2==augment), game_result.augment3==augment)
    
    check = game_result[check]
    
    check_item = make_item_stack(check, item_result)
    
    return check_item

###############################################################################################################

# 유닛 vs 유닛

def champion_champion_crosscheck(game_result, champion_result, champion):
    
    check = after_join.loc[after_join.champ_name == champion, ['Game_id', 'Player_id']]
    
    check = pd.merge(game_result, check, on=['Game_id', 'Player_id'])
    
    check_champion = make_unit_stack(check, champion_result)
    
    return check_champion

# 유닛 vs 증강체

def champion_augment_crosscheck(game_result, augment_result, champion):
    
    check = game_result.champ_name==champion
    
    check = game_result[check]
    
    check_augment = make_augment_stack(check, augment_result)
    
    return check_augment

# 유닛 vs 아이템

def champion_item_crosscheck(game_result, item_result, champion):
    
    check = game_result.champ_name==champion
    
    check = game_result[check]
    
    check_item = make_item_stack(check, item_result)
    
    return check_item

###############################################################################################################

# 아이템 vs 아이템

def item_item_crosscheck(game_result, item_result, item):
    
    check = np.logical_or(np.logical_or(game_result.item1==item, game_result.item2==item), game_result.item3==item)
    
    
    check = game_result[check]
    
    
    check_item = make_item_stack(check, item_result)
    
    return check_item


# 아이템 vs 유닛

def item_champion_crosscheck(game_result, champion_result, item):
    
    check = np.logical_or(np.logical_or(game_result.item1==item, game_result.item2==item), game_result.item3==item)    
    
    check = game_result[check]
    
    check_champion = make_unit_stack(check, champion_result)
    
    return check_champion

# 아이템 vs 증강체

def item_augment_crosscheck(game_result, augment_result, item):
    
    check = np.logical_or(np.logical_or(game_result.item1==item, game_result.item2==item), game_result.item3==item)
    
    
    check = game_result[check]
    
    check_augment = make_augment_stack(check, augment_result)
    
    return check_augment

game_result에는 after_join 데이터프레임은, item/champion/augment_result에는 앞서 만든 csv파일인 item/unit/augment_list를, augment/champion/item에는 원하는 조건을 입력하면 된다.

5. 모든 증강체/유닛/아이템에 대한 summary dictionary 만들기

이제 주어진 게임 경기 데이터로부터 모든 증강체, 유닛, 아이템 각각에 대해서 통계량을 만든 후, 이를 dictionary로 저장해주면 된다.

첫 3개의 함수는 특정 augment/unit/item의 요약통계량을 제공하는 함수이며, 이 후 3개의 함수는 특정 augment/unit/item 기준 다른 augment, unit, item의 요약 통계량을 제공하는 함수, 마지막 making_dictionary_automation 함수는 모든 증강체, 유닛, 아이템 각각에 대해 요약통계량, 다른 augment, unit, item의 요약통계량을 제공하는 함수이다.

# 특정 유닛 요약 통계량 제공 함수

def champion_summary(after_join, champion):

    check = after_join[after_join.champ_name==champion].copy()

    check.loc[:, 'Winner'] = check.Placement==1
    check.loc[:, 'Save'] = check.Placement<=4

    check = check.groupby('Datetime')

    result = check.agg({'rarity' : ['count'], 'Placement' : ['mean'], 'tier' : ['mean'], 'Save' : ['mean'], 'Winner' : ['mean']})

    result.columns = ['Count', 'Avg_placement', 'Avg_tier', 'Avg_save', 'Avg_winner']

    result = result.reset_index()

    return result

# 특정 증강체 요약 통계량 제공 함수

def augment_summary(after_join, augment):

    check = np.logical_or(np.logical_or(after_join.augment1==augment, after_join.augment2==augment), after_join.augment3==augment)

    check = after_join[check].copy()

    check.loc[:, 'Winner'] = check.Placement==1
    check.loc[:, 'Save'] = check.Placement<=4

    check = check.groupby('Datetime')

    result = check.agg({'rarity' : ['count'], 'Placement' : ['mean'], 'Save' : ['mean'], 'Winner' : ['mean']})

    result.columns = ['Count', 'Avg_placement', 'Ave_save', 'Ave_winner']

    result = result.reset_index()

    return result

# 특정 아이템 요약 통계량 제공 함수

def item_summary(after_join, item):

    check = np.logical_or(np.logical_or(after_join.item1==item, after_join.item2==item), after_join.item3==item)
    check = after_join[check].copy()

    check.loc[:, 'Winner'] = check.Placement==1
    check.loc[:, 'Save'] = check.Placement<=4

    check = check.groupby('Datetime')

    result = check.agg({'rarity' : ['count'], 'Placement' : ['mean'], 'Save' : ['mean'], 'Winner' : ['mean']})

    result.columns = ['Count', 'Avg_placement', 'Ave_save', 'Ave_winner']

    result = result.reset_index()

    return result        


############################################################################################


# 특정 유닛과 같이 사용한 유닛, 아이템, 증강체 별 통계량 제공 함수

def making_champ_dictionary(after_join,augment_list, champion_list, item_list, champion):

    champ_summary = champion_summary(after_join, champion)
    champ_augment = champion_augment_crosscheck(after_join, augment_list, champion)
    champ_champion = champion_champion_crosscheck(after_join, champion_list, champion)
    champ_item = champion_item_crosscheck(after_join, item_list, champion)

    result = dict(summary = champ_summary.to_dict(), augment = champ_augment.to_dict(), champion = champ_champion.to_dict(),
                 item = champ_item.to_dict())

    return result


# 특정 증강체와 같이 사용한 유닛, 아이템, 증강체 별 통계량 제공 함수


def making_augment_dictionary(after_join,augment_list, champion_list, item_list, augment):

    aug_summary = augment_summary(after_join, augment)
    aug_augment = augment_augment_crosscheck(after_join, augment_list, augment)
    aug_champion = augment_champion_crosscheck(after_join, champion_list, augment)
    aug_item = augment_item_crosscheck(after_join, item_list, augment)

    result = dict(summary = aug_summary.to_dict(), augment = aug_augment.to_dict(), champion = aug_champion.to_dict(),
                 item = aug_item.to_dict())

    return result

# 특정 아이템과 같이 사용한 유닛, 아이템, 증강체 별 통계량 제공 함수


def making_item_dictionary(after_join,augment_list, champion_list, item_list, item):

    items_summary = item_summary(after_join, item)
    item_augment = item_augment_crosscheck(after_join, augment_list, item)
    item_champion = item_champion_crosscheck(after_join, champion_list, item)
    item_item = item_item_crosscheck(after_join, item_list, item)

    result = dict(summary = items_summary.to_dict(), augment = item_augment.to_dict(), champion = item_champion.to_dict(),
                 item = item_item.to_dict())

    return result

##############################################################################################

# 모든 증강체, 유닛, 아이템 각각에 대해 통합 정보 제공해주는 함수

def making_dictionary_automation(after_join, augment_list, champion_list, item_list):

    champion_result = champion_list.Name
    item_result = item_list.Name
    augment_result = augment_list.Name


    champ_dict = {i : making_champ_dictionary(after_join, augment_list, champion_list, item_list, i) for i in champ_list}
    item_dict = {i : making_item_dictionary(after_join, augment_list, champion_list, item_list, i) for i in item_list}
    augment_dict = {i : making_augment_dictionary(after_join, augment_list, champion_list, item_list, i) for i in augment_list}

    final_dictionary = dict(champion = champ_dict, item = item_dict, augment = augment_dict)

    return final_dictionary

최종적으로 making_dictionary_automation 함수를 실행했을 때, 얻게 되는 데이터 구조는 다음과 같다.

  • 최종 결과 dictionary의 key로는 champion, item, augment가 존재한다.

  • champion에 속한 값은 시즌 8에 존재하는 모든 유닛을 key로 가지는 dictionary이다. 해당 champion에 속한 값은 해당 champion(유닛)에 대한 요약 통계량, 같이 사용한 champion의 요약 통계량, 해당 champion이 사용한 item의 요약 통계량, 해당 champion과 같이 사용한 augment의 요약 통계량으로 구성된 dictionary이다.

  • item에 속한 값은 시즌 8에 존재하는 모든 아이템을 key로 가지는 dictionary이다. 해당 item에 속한 값은 해당 item에 대한 요약 통계량, 같이 사용한 champion의 요약 통계량, 해당 item과 같이 사용한(한 유닛에) item의 요약 통계량, 해당 아이템을 사용한 유닛의 요약 통계량, 해당 아이템과 같이 사용한 augment의 요약 통계량으로 구성된 dictionary이다.

  • augment에 속한 값은 시즌 8에 존재하는 모든 증강체를 key로 가지는 dictionary이다. 해당 augment에 속한 값은 해당 증강체에 대한 요약 통계량, 같이 사용한 증강체의 요약 통계량, 해당 증강체와 같이 사용한 item의 요약 통계량, 해당 증강체와 같이 사용한 item의 요약 통계량으로 구성된 dictionary이다.

최종 dictionary까지 만드는 과정을 class로 정리한 코드는 다음 github에서 확인할 수 있다.

github

이제 분석을 위한 기본 데이터는 모두 수집했다. 다음 포스트를 위해서 2월 초부터 3월 중순까지 challenger의 게임 데이터 약 3만개를 수집했다. 이를 토대로 해당 티어 유저들이 사용한 유닛, 특성을 기반으로 주류 덱을 클러스터링할 예정이다.

  • 현재 product 형태로 만들어진게 없어 riot api를 이용할 때 제약사항이 존재한다. 그래서 해당 3만개의 게임 데이터를 얻는데 꼬박 하루가 걸렸다...

  • 3만개의 게임데이터를 이용하여 이번 포스트에서 만든 최종 데이터프레임을 만드는데 약 3~4시간이 소요되었다. 각각의 게임 결과를 이용하여 게임 결과 데이터프레임을 만드는데 시간이 많이 소요되었는데, 이를 줄일 방법을 생각해보아야 겠다. - 게임 결과 데이터프레임을 만들지 않고 바로 요약통계량으로 만들 수 있는 방법을 고민해야 할 것 같다.

profile
데이터 분석가 새싹

0개의 댓글