python dota2数据 2 英雄名和胜负

python dota2数据 2 英雄名和胜负

将英雄id转化为英雄名

API

查询英雄id和名字对应表的函数为get_heroes(),返回值为一个dictionary。

{
    count                       - Number of results
    status                      - HTTP status code
    [heroes]
    {
        id                      - Unique hero ID
        name                    - Hero's name
        localized_name          - Localized version of hero's name
        url_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未被使用,如24
    name_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 in
    radiant_win             - Win status of game (True for Radiant win, False for Dire win)
    duration                - Elapsed match time in seconds
    start_time              - Unix timestamp for beginning of match
    match_id                - Unique match ID
    match_seq_num           - Number indicating position in which this match was recorded
    tower_status_radiant    - Status of Radiant towers
    tower_status_dire       - Status of Dire towers
    barracks_status_radiant - Status of Radiant barracks
    barracks_status_dire    - Status of Dire barracks
    cluster                 - The server cluster the match was played on, used in retrieving replays
    cluster_name            - The region the match was played on
    first_blood_time        - Time elapsed in seconds since first blood of the match
    lobby_type              - See lobby_type table
    lobby_name              - See lobby_type table
    human_players           - Number of human players in the match
    leagueid                - Unique league ID
    positive_votes          - Number of positive/thumbs up votes
    negative_votes          - Number of negative/thumbs down votes
    game_mode               - See game_mode table
    game_mode_name          - See game_mode table
    radiant_captain         - Account ID for Radiant captain
    dire_captain            - Account ID for Dire captain
    [pick_bans]
    {
        {
            hero_id         - Unique hero ID
            is_pick         - True if hero was picked, False if hero was banned
            order           - Order of pick or ban in overall pick/ban sequence
            team            - See team_id table.

        }
    }
    [players]
    {
        account_id          - Unique account ID
        player_slot         - Player's position within the team
        hero_id             - Unique hero ID
        hero_name           - Hero's name
        item_#              - Item ID for item in slot # (0-5)
        item_#_name         - Item name for item in slot # (0-5)
        kills               - Number of kills by player
        deaths              - Number of player deaths
        assists             - Number of player assists
        leaver_status       - Connection/leaving status of player
        gold                - Gold held by player
        last_hits           - Number of last hits by player (creep score)
        denies              - Number of denies
        gold_per_min        - Average gold per minute
        xp_per_min          - Average XP per minute
        gold_spent          - Total amount of gold spent
        hero_damage         - Amount of hero damage dealt by player
        tower_damage        - Amount of tower damage dealt by player
        hero_healing        - Amount of healing done by player
        level               - Level of player's hero
        [ability_upgrades]  - Order of abilities chosen by player
        {
            ability         - Ability chosen
            time            - Time in seconds since match start when ability was upgraded
            level           - Level of player at time of upgrading
        }

        [additional_units]  - Only available if the player has a additional unit
        {
            unitname        - Name of unit
            item_#          - ID of item in slot # (0-5)
        }
    }
    // These fields are only available for matches with teams //
    [radiant_team]
    {
        team_name            - Team name for Radiant
        team_logo            - Team logo for Radiant
        team_complete        - ?
    }
    [dire_team]
    {
        team_name            - Team name for Dire
        team_logo            - Team logo for Dire
        team_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 = True
    else:
        side = False
    detail = 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'])

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值