python dota2数据 2 英雄名和胜负
python dota2数据 2 英雄名和胜负
将英雄id转化为英雄名
API
查询英雄id和名字对应表的函数为get_heroes(),返回值为一个dictionary。
{count - Number of resultsstatus - HTTP status code[heroes]{id - Unique hero IDname - Hero's namelocalized_name - Localized version of hero's nameurl_full_portrait - URL to full-size hero portrait (256x144)url_large_portrait - URL to large hero portrait (205x115)url_small_portrait - URL to small hero portrait (59x33)url_vertical_portrait - URL to vertical hero portrait (235x272)}
}
其中的heroes键为一个包含了所有英雄的列表,记录了英雄的id和名字。
改写get_match_history.py
加入函数get_hero_name_list(),用于请求并返回英雄id和名字对应的列表。
def get_hero_name_list():hero_dict = api.get_heroes()#英雄ID和名字列表heroes = hero_dict['heroes']#根据ID排序heroes.sort(key = lambda k: (k.get('id'), 0))#有部分ID未被使用,如24name_list = ['unused'] * (MAX_NUM + 1)for i in range(len(heroes)):name_list[heroes[i]['id']] = heroes[i]['localized_name']return name_list
加入:
name_list = get_hero_name_list()
h_name = name_list[h_id]
即可得到英雄名。
判断胜负
API
get_match_history()的返回内容并没有包含所查询比赛的胜负。另一个API函数get_match_details(),该函数的参数仅有一个match_id,这可以从get_match_history()的返回中获取。该函数的返回内容:
{season - Season the game was played inradiant_win - Win status of game (True for Radiant win, False for Dire win)duration - Elapsed match time in secondsstart_time - Unix timestamp for beginning of matchmatch_id - Unique match IDmatch_seq_num - Number indicating position in which this match was recordedtower_status_radiant - Status of Radiant towerstower_status_dire - Status of Dire towersbarracks_status_radiant - Status of Radiant barracksbarracks_status_dire - Status of Dire barrackscluster - The server cluster the match was played on, used in retrieving replayscluster_name - The region the match was played onfirst_blood_time - Time elapsed in seconds since first blood of the matchlobby_type - See lobby_type tablelobby_name - See lobby_type tablehuman_players - Number of human players in the matchleagueid - Unique league IDpositive_votes - Number of positive/thumbs up votesnegative_votes - Number of negative/thumbs down votesgame_mode - See game_mode tablegame_mode_name - See game_mode tableradiant_captain - Account ID for Radiant captaindire_captain - Account ID for Dire captain[pick_bans]{{hero_id - Unique hero IDis_pick - True if hero was picked, False if hero was bannedorder - Order of pick or ban in overall pick/ban sequenceteam - See team_id table.}}[players]{account_id - Unique account IDplayer_slot - Player's position within the teamhero_id - Unique hero IDhero_name - Hero's nameitem_# - Item ID for item in slot # (0-5)item_#_name - Item name for item in slot # (0-5)kills - Number of kills by playerdeaths - Number of player deathsassists - Number of player assistsleaver_status - Connection/leaving status of playergold - Gold held by playerlast_hits - Number of last hits by player (creep score)denies - Number of deniesgold_per_min - Average gold per minutexp_per_min - Average XP per minutegold_spent - Total amount of gold spenthero_damage - Amount of hero damage dealt by playertower_damage - Amount of tower damage dealt by playerhero_healing - Amount of healing done by playerlevel - Level of player's hero[ability_upgrades] - Order of abilities chosen by player{ability - Ability chosentime - Time in seconds since match start when ability was upgradedlevel - Level of player at time of upgrading}[additional_units] - Only available if the player has a additional unit{unitname - Name of unititem_# - ID of item in slot # (0-5)}}// These fields are only available for matches with teams //[radiant_team]{team_name - Team name for Radiantteam_logo - Team logo for Radiantteam_complete - ?}[dire_team]{team_name - Team name for Direteam_logo - Team logo for Direteam_team_complete - ?}
}
该函数返回了所能获得一场比赛的所有详细数据,包括了一血时间、双方防御塔、每个英雄的正反补、伤害、每级加点等等详细的数据。胜负关系数据:radiant_win,说明是True表示天辉胜利,False表示夜魇胜利。
get_match_history中返回的每场比赛信息中包含了每个玩家的位置player_slot,由一个8位整数表示:
即天辉为0~4,夜魇为128~132。
改写get_match_history.py
加入函数win_or_lose(m_id, player_slot),用于返回胜负信息:
def win_or_lose(m_id, player_slot):#确定玩家位置,True为天辉False为夜魇if player_slot < 5:side = Trueelse:side = Falsedetail = api.get_match_details(m_id)#获取比赛胜负win_side = detail['radiant_win']#比较判断if side == win_side:return 'win 'else:return 'lose'
加入:
result = win_or_lose(m_id, p['player_slot'])