当前位置: 首页 > news >正文

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'])


http://www.taodudu.cc/news/show-5696984.html

相关文章:

  • 《探索图像处理的无限可能:从技术突破到未来应用》
  • GoF之代理模式(静态代理+动态代理(JDK动态代理+CGLIB动态代理带有一步一步详细步骤))
  • ffmpeg7.0 + visual studio 2022 release lib 静态库编译使用
  • 【面试必看】MySQL部分
  • Google: 在新知识上微调大语言模型是否会鼓励产生幻觉?
  • Acrel-1000变电站综合自动化监控系统 实时测控保护、远动于一体
  • 微信小程序—使用app.js里定义的全局方法
  • 不用下载,使用app的方法,太绝了
  • vue3+ts使用app.config.globalProperties全局挂载实例方法,扩展模块解决ts类型检查报错
  • 使用adb操作app
  • matlab使用App designer生成可独立运行的app(预测模型为BP神经网络模型)
  • 解决微信小程序中在其他页面无法使用app.js中获取的userInfo或openid的问题
  • 微信小程序关于utils.js 需要使用app.js 的全局变量,怎么做?
  • 使用App Ops修改APP隐藏权限(Android)
  • 在matlab中使用APP designer创建多窗口APP
  • WPF教程(十)使用App.xaml
  • 使用AppUploader上传ipa文件到APPstore
  • 网络提速器 v1.1 免费
  • 使用 mamba 提速 conda
  • Sqoop提速性能调整
  • android 9.0 后台录音,不限制1分钟
  • Android多媒体之照相、录音、录像之视图横拉
  • Android6.0以下判断手机录音和相机权限
  • html5录音兼容性,详解HTML5 录音遇到的坑
  • php手机网页在线录音ios,iOS 实现录音功能
  • 备忘录想要查看录音时长怎么办?
  • c语言密码登录
  • C语言求鞍点
  • C语言工程创建
  • 【C语言总结篇】新起点
  • Linux如何写C语言
  • 更改administrator名称
  • git本地配置用户名_git配置全局用户名
  • 【笔记】Win10 安装系统跳过创建用户,直接启用 Administrator
  • 好听的歌曲 那一天
  • 网络四大黑之中奖