pubg json api包装器和游戏遥测可视化工具

chicken-dinner的Python项目详细描述


rtdpypipyversions

python pubg json api包装器和(可选)回放可视化工具。

还包括用于重播、排行榜、统计和更新资产的基本cli功能。

安装

要安装鸡肉晚餐,请使用pip。这将安装核心依赖项 为api包装器和cli提供功能。

pip install chicken-dinner

要使用回放可视化效果,您需要使用 绘图的额外依赖项(matplotlibpillow)。 为此,您还可以使用pip:

pip install chicken-dinner[visual]

要生成动画,还需要在 机器。在max osx上,您可以使用brew安装ffmpeg

brew install ffmpeg

您可以从here在其他系统上安装ffmpeg。

用法

使用低级api类。

fromchicken_dinner.pubgapiimportPUBGCoreapi_key="your_api_key"pubgcore=PUBGCore(api_key,"pc-na")shroud=pubgcore.players("player_names","shroud")print(shroud)# {'data': [{'type': 'player', 'id': 'account.d50f...

使用高级api类。

fromchicken_dinner.pubgapiimportPUBGapi_key="your_api_key"pubg=PUBG(api_key,"pc-na")shroud=pubg.players_from_names("shroud")[0]shroud_season=shroud.get_current_season()squad_fpp_stats=shroud_season.game_mode_stats("squad","fpp")print(squad_fpp_stats)# {'assists': 136, 'boosts': 313, 'dbnos': 550, 'daily_kills':...

可视化遥测数据

fromchicken_dinner.pubgapiimportPUBGapi_key="your_api_key"pubg=PUBG(api_key,"pc-na")shroud=pubg.players_from_names("shroud")[0]recent_match_id=shroud.match_ids[0]recent_match=pubg.match(recent_match_id)recent_match_telemetry=recent_match.get_telemetry()recent_match_telemetry.playback_animation("recent_match.html")

建议的播放设置:

telemetry.playback_animation("match.html",zoom=True,labels=True,label_players=[],highlight_winner=True,label_highlights=True,size=6,end_frames=60,use_hi_res=False,color_teams=True,interpolate=True,damage=True,interval=2,fps=30,)

有关详细信息,请参见documentation 细节。

cli

对于使用pubg api的cli命令,需要api密钥。 您可以通过环境变量提供api密钥 命名为PUBG_API_KEY或使用cli选项--api-key

exportPUBG_API_KEY=your_pubg_api_key
chicken-dinner [command] --shard=steam ...

chicken-dinner [command] --api-key=your_pubg_api_key --shard=steam ...

shard是可选的,但默认shard是steam

资产

要更新本地资源,包括高分辨率地图和资源字典:

chicken-dinner assets

排行榜

显示游戏模式的排行榜(shard默认为steam):

chicken-dinner leaderboard --shard=steam solo-fpp

玩家统计

显示终身或当前赛季的玩家统计信息(碎片默认为蒸汽):

# Get the lifetime stats for chocoTaco in solo-fpp
chicken-dinner stats --shard=steam --lifetime --group=solo --perspective=fpp chocoTaco

# Get the latest season stats for chocoTaco in solo-fpp
chicken-dinner stats -g solo -p fpp chocoTaco

回放

为匹配项生成html5重播(shard默认为steam):

# Generate a replay for the latest win of chocoTaco in specified path
chicken-dinner replay --latest --wins-only --size=6 --path=/path/to/my/replays chocoTaco

# Generate a replay for the latest game of chocoTaco
chicken-dinner replay -l chocoTaco

# Generate a replay for all of chocoTaco's wins in recent games
chicken-dinner replay -w chocoTaco

# Generate a replay for all of the recent games of chocoTaco
chicken-dinner replay chocoTaco

更多示例

设置

正在创建PUBG实例。

fromchicken_dinner.pubgapiimportPUBGapi_key="my_api_key"pubg=PUBG(api_key=api_key,shard="steam")

玩家示例

根据玩家的名字获取信息。

# Creates a Players instance (iterable Player instances)players=pubg.players_from_names("chocoTaco")# Take the first Player instance from the iterablechocotaco=players[0]chocotaco.name# chocoTacochocotaco.match_ids# ['e0b3cb15-929f-4b42-8873-68a8f9998d2b', 'dd25cf69-77f1-4791-9b14-657e904d3534'...chocotaco.id# 'account.15cbf322a9bc45e88b0cd9f12ef4188e'chocotaco.url# 'https://api.playbattlegrounds.com/shards/steam/players/account.15cbf322a9bc45e88b0cd9f12ef4188e'

或者从id中获取播放器实例。

# Creates a Players instance (iterable Player instances)players=pubg.players_from_ids("account.15cbf322a9bc45e88b0cd9f12ef4188e")# Take the first Player instance from the iterablechocotaco=players[0]

获取他们一起参与的多个球员和比赛的信息。

# Creates a Players instance (iterable of Player instances)players=pubg.players_from_names(["shroud","chocoTaco"])players.ids# ['account.d50fdc18fcad49c691d38466bed6f8fd', 'account.15cbf322a9bc45e88b0cd9f12ef4188e']players.names_to_ids()# {'shroud': 'account.d50fdc18fcad49c691d38466bed6f8fd', 'chocoTaco': 'account.15cbf322a9bc45e88b0cd9f12ef4188e'}players.ids_to_names()# {'account.d50fdc18fcad49c691d38466bed6f8fd': 'shroud', 'account.15cbf322a9bc45e88b0cd9f12ef4188e': 'chocoTaco'}players.shared_matches()# ['e0b3cb15-929f-4b42-8873-68a8f9998d2b', 'dd25cf69-77f1-4791-9b14-657e904d3534'...shroud=players[0]chocotaco=players[1]

季节示例

获取Seasons对象的iterable

seasons=pubg.seasons()seasons.ids# ['division.bro.official.2017-beta', 'division.bro.official.2017-pre1'...# Get the current seasoncurrent_season=seasons.current()

使用Season实例

season=pubg.current_season()season.id# 'division.bro.official.pc-2018-04'season.is_current()# Trueseason.is_offseason()# False# Get a player-season for a specific playerchocotaco_season=season.get_player("account.15cbf322a9bc45e88b0cd9f12ef4188e")

获取有关球员赛季的信息

# Using the factory instance directlychocotaco_season=pubg.player_season("account.15cbf322a9bc45e88b0cd9f12ef4188e","division.bro.official.pc-2018-04")# Using a seasonseason=pubg.current_season()chocotaco_season=season.get_player("account.15cbf322a9bc45e88b0cd9f12ef4188e")# Using a playerchocotaco=pubg.players_from_names("chocoTaco")[0]chocotaco_season=chocotaco.get_season("division.bro.official.pc-2018-04")chocotaco_season.id# {'player_id': 'account.15cbf322a9bc45e88b0cd9f12ef4188e', 'season_id': 'division.bro.official.pc-2018-04'}chocotaco_season.player_id# 'account.15cbf322a9bc45e88b0cd9f12ef4188e'chocotaco_season.season_id# 'division.bro.official.pc-2018-04'chocotaco_season.match_ids("solo","fpp")# ['4b0c5898-7149-4bcc-8da7-df4cdc07fd80', 'b26880e5-916d-4be8-abd7-45d8dddb6df3'...chocotaco_season.game_mode_stats("solo","fpp")# {'assists': 38, 'boosts': 498, 'dbnos': 0, 'daily_kills': 18, 'daily_wins': 0, 'damage_dealt': 95036.79...

排行榜

排行榜为特定游戏模式提供前25名玩家。

solo_fpp_leaderboard=pubg.leaderboard("solo-fpp")solo_fpp_leaderboard.game_mode# 'solo-fpp'solo_fpp_leaderboard.ids# ['account.cfb13f65d5d1452294efbe7e730f7b1c', 'account.9affa4ff8e5746bbb6a199f1a773c659'...solo_fpp_leaderboard.names# ['HuYa-17152571', 'Huya_15007597_LS', 'Douyu-7250640', 'Douyu-4778209', 'DouYu-1673291'...solo_fpp_leaderboard.ids_to_names()# {'account.f897d4a4b22f45cb8a85008039f5069e': 'HuYaTv-19488958', 'account.8ca07daf6c084dea81aacc00616fde9c': 'Breukin224'...solo_fpp_leaderboard.names_to_ids()# {'HuYaTv-19488958': 'account.f897d4a4b22f45cb8a85008039f5069e', 'Breukin224': 'account.8ca07daf6c084dea81aacc00616fde9c'...# Info about a player at particular ranksolo_fpp_leaderboard.name(1)# 'HuYa-17152571'solo_fpp_leaderboard.id(1)# 'account.cfb13f65d5d1452294efbe7e730f7b1c'solo_fpp_leaderboard.stats(1)# {'rank_points': 6344, 'wins': 82, 'games': 1591, 'win_ratio': 0.0515399128, 'average_damage': 247, 'kills': 3218...# Get a player object for a player at rank 1player=solo_fpp_leaderboard.get_player(1)

样本

随机抽取匹配ID。

samples=pubg.samples()samples.match_ids# ['98192d81-8700-4e28-981d-00b14dfbb3c9', '7ce51ef0-6f73-4974-9bb6-532dec58355d'...

API状态

获取当前API状态

status=pubg.status()status.id# 'pubg-api'# Refreshes the API statusstatus.refresh()

匹配

获取匹配信息

match=pubg.match("e0b3cb15-929f-4b42-8873-68a8f9998d2b")match.asset_id# '44b787fd-c153-11e9-8b6c-0a586467d436'match.created_at# '2019-08-18T00:29:00Z'match.duration# 1686match.game_mode# 'duo-fpp'match.id# 'e0b3cb15-929f-4b42-8873-68a8f9998d2b'match.is_custom# Falsematch.map_id# 'Baltic_Main'match.map_name# 'Erangel (Remastered)'match.rosters_player_names# {'9354f12b-8e79-4ca2-9465-6bdfa6b4bca9': ['Vealzor', 'Colin630'], 'c2eb2ecf-96d5-42c3-b0cb-49d734a716a6': ['KillaCon', 'FriendlyOrc']...match.telemetry_url# 'https://telemetry-cdn.playbattlegrounds.com/bluehole-pubg/steam/2019/08/18/00/58/44b787fd-c153-11e9-8b6c-0a586467d436-telemetry.json'match.url# 'https://api.playbattlegrounds.com/shards/steam/matches/e0b3cb15-929f-4b42-8873-68a8f9998d2b'

获取名册和相关参与者

# Get rostersrosters=match.rosters# Get single rosterroster=rosters[0]roster.player_ids# ['account.7046d72ec24e45a7b0282d390dea91e5', 'account.9a154840c7db4f7f88def5198b9393b6']roster.player_names# ['Vealzor', 'Colin630']roster.stats# {'rank': 44, 'team_id': 12, 'won': 'false'}roster.won# False# Participant from a rosterroster_participants=roster.participantsparticipant=roster_participant[0]participant.name# 'Vealzor'participant.player_id# 'account.7046d72ec24e45a7b0282d390dea91e5'participant.stats# {'dbnos': 1, 'assists': 0, 'boosts': 0, 'damage_dealt': 113.032738...participant.teammates_player_ids# ['account.9a154840c7db4f7f88def5198b9393b6']participant.teammates_player_names# ['Colin630']participant.won# False# Get Participant instances for teammatesteammates=participant.teammates

从Match获取所有参与者

match_participants=match.participants

遥测

从特定匹配项获取遥测实例

# Using the PUBG instanceurl='https://telemetry-cdn.playbattlegrounds.com/bluehole-pubg/steam/2019/08/18/00/58/44b787fd-c153-11e9-8b6c-0a586467d436-telemetry.json'telemetry=pubg.telemetry(url)# Using a Match instancematch=pubg.match("e0b3cb15-929f-4b42-8873-68a8f9998d2b")telemetry=match.get_telemetry()# All available event typestelemetry.event_types()# ['log_armor_destroy', 'log_care_package_land', 'log_care_package_spawn', 'log_game_state_periodic', 'log_heal'...# All specific eventscare_package_lands=telemetry.filter_by("log_care_package_land")telemetry.map_id()# 'Baltic_Main'telemetry.map_name()# 'Erangel (Remastered)'telemetry.num_players()# 100telemetry.num_teams()# 50telemetry.platform# 'pc'# Generates an HTML5 animation with ffmpegtelemetry.playback_animation("match.html")# Many more functions related to positions, circles, damages. Refer to docs

遥测事件和对象是通用类包装器。它们是构造的 创建遥测实例时。这使得它们的遥测版本不可知, 但是需要一些工作来检查它们的内容和结构。遥测事件 遥测对象类也将有效载荷密钥转换为snake_case。

遥测事件是事件键值和结构的容器,其中包含 遥测对象的层次结构。

Telemetry Events

# Get all TelemetryEvents as a listevents=telemetry.events# Get one of the eventsevent=events[0]event.event_type# log_match_definitionevent.timestamp# '2019-08-18T00:29:00.0807375Z'event.to_dict()# {'_D': '2019-08-18T00:29:00.0807375Z', '_T': 'LogMatchDefinition', 'match_id': 'match.bro.official.pc-2018-04.steam.duo-fpp.na.2019.08.18.00.e0b3cb15-929f-4b42-8873-68a8f9998d2b', 'ping_quality': 'low', 'season_state': 'progress'}print(event.dumps())# {#     "_D": "2019-08-18T00:29:00.0807375Z",#     "_T": "LogMatchDefinition",#     "match_id": "match.bro.official.pc-2018-04.steam.duo-fpp.na.2019.08.18.00.e0b3cb15-929f-4b42-8873-68a8f9998d2b",#     "ping_quality": "low",#     "season_state": "progress"# }# Each event key can be grabbed as an attribute or keyevent.ping_quality# lowevent["ping_quality"]# low

遥测对象是指诸如播放器、项目、位置、车辆等实体。 每个遥测对象都包含一个reference属性,该属性是父对象中的键 引用此遥测对象的遥测事件或遥测对象。

Telemetry Objects

# All available event typestelemetry.event_types()# ['log_armor_destroy', 'log_care_package_land', 'log_care_package_spawn', 'log_game_state_periodic', 'log_heal'...kill_events=telemetry.filter_by("log_player_kill")kill=kill_events[0]kill.keys()# ['attack_id', 'killer', 'victim', 'assistant', 'dbno_id', 'damage_reason'...killer=kill.killerkiller.keys()# ['reference', 'name', 'team_id', 'health', 'location', 'ranking', 'account_id', 'is_in_blue_zone', 'is_in_red_zone', 'zone']killer.name# 'WigglyPotato'victim=kill.victimvictim.keys()# ['reference', 'name', 'team_id', 'health', 'location', 'ranking', 'account_id', 'is_in_blue_zone', 'is_in_red_zone', 'zone']victim.name# 'qnle'victim.to_dict()# {'account_id': 'account.d9c2d8dc8c03412eadfa3e59c8f3c16a', 'health': 0, 'is_in_blue_zone': False, 'is_in_red_zone': False...fork,vinvictim.items():print(k,v)# reference victim# name qnle# team_id 43# health 0# location TelemetryObject location object# ranking 0# account_id account.d9c2d8dc8c03412eadfa3e59c8f3c16a# is_in_blue_zone False# is_in_red_zone False# zone ['georgopol']

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
javaelk:如何在Kibana中按异常类对stacktrace进行分组   java两个组件使用MigLayout相互重叠   java Hibernate标准获取关联实体的列表,而不是父实体的列表   从Java关闭另一个应用程序,但不是由当前Java应用程序启动   java使用OGNL获取参数   java如何在SSLEngine中启用密码TLS\U DHE\U RSA\U和\U AES\U 256\U GCM\U SHA384   在Java中有效地比较两个列表<Object[]>   java杀死挂起的线程   在java中从指定模式前后的字符串中提取子字符串   存储整数的java HashMap替代方案   java如何使用LibGDX加载特定于语言的资产?   java如何使用JSON响应从维基百科读取结构化数据   java无法连接到Spark Master:原因是:[已解除关联]   java如何配置Elastic beanstalk classic负载平衡器以使用CLI终止HTTPS   java筛网中的奥斯汀大于int   java PircBot在每个用户上迭代一组命令   java将带有Jackson的hashmap编组为XML的错误结构   testng中的java设置testfailure给出了正回报   java如何在IntelliJ中正确配置Eclipse项目?