美文网首页
Dota2 战绩统计脚本

Dota2 战绩统计脚本

作者: 0_oHuanyu | 来源:发表于2024-01-21 16:44 被阅读0次

utils.py的内容如下

import dota2api

API_KEY = "xxxx" # 这个需要去steam打开开发者权限. 然后把key放到这里

api = dota2api.Initialise(API_KEY)


def query_all(my_id, end_match_id, start_match_id=None):
    last_game_id = start_match_id
    cnt = 0
    jump_one = False

    all_matches = []
    while True:
        print("start at ", last_game_id)
        hist1 = api.get_match_history(account_id=my_id, matches_requested=100, start_at_match_id=last_game_id)
        for match in hist1["matches"]:
            if jump_one:
                jump_one = False
                continue
            cnt += 1
            all_matches.append(match)
            if match["match_id"] == end_match_id:
                print("done! total cnt = ", cnt)
                return all_matches
            last_game_id = match["match_id"]
        jump_one = True


def query_win_lose(all_matches, my_id, tm_id):
    togather_cnt = 0
    togather_win_cnt = 0

    cnt = len(all_matches)
    win_cnt = 0
    for match in all_matches:
        win = False
        with_teammate = False
        for player_info in match["players"]:
            if player_info["account_id"] == my_id:
                team_id = player_info["team_number"]
                match_info = api.get_match_details(match_id=match["match_id"])
                if match_info["radiant_win"] and team_id == 0:
                    win = True
                elif not match_info["radiant_win"] and team_id == 1:
                    win = True

            if player_info["account_id"] == tm_id:
                with_teammate = True
        if win:
            win_cnt += 1
        if with_teammate:
            togather_cnt += 1
            if win:
                togather_win_cnt += 1

        print("match_id = ", match["match_id"], ". winning: ", win, ", with teammate: ", with_teammate)

    return win_cnt, cnt, togather_win_cnt, togather_cnt

查询的使用, 比如 查找我的战绩, 和队友的开黑战绩:

from utils import *

END_MATCH_ID = 7486178491
MY_ID = 1035741118
TM_ID = 1125973295

all_matches = query_all(MY_ID, END_MATCH_ID)
for match in all_matches:
    print(match)
print(len(all_matches))

win_cnt, cnt, togather_win_cnt, togather_cnt = query_win_lose(all_matches, MY_ID, TM_ID)

print("------------------all------------------")
print("cnt = ", cnt)
print("win_cnt = ", win_cnt)
print("winning rate = ", float(win_cnt) / cnt)

print("------------------togather------------------")
print("togather_cnt = ", togather_cnt)
print("togather_win_cnt = ", togather_win_cnt)
print("winning rate = ", float(togather_win_cnt) / togather_cnt)

print("------------------solo------------------")
print("cnt = ", cnt - togather_cnt)
print("win_cnt = ", win_cnt - togather_win_cnt)
print("winning rate = ", float(win_cnt - togather_win_cnt) / (cnt - togather_cnt))

dota2api的安装见github :https://github.com/joshuaduffy/dota2api
api的文档见:https://steamapi.xpaw.me/#IDOTA2Match_570/GetMatchHistory
开通steam的api权限需要充值5美元. 不需要消费, 仅充值就好. 或者有5美元的消费记录也是可以的. 点击这个链接可以开启api权限: https://steamcommunity.com/dev/apikey. 如果你已经开启了, 那么这个链接就可以显示你的key

相关文章

  • 统计脚本

    var tablenames = db.getCollectionNames();for(var i=0; i< ...

  • 安博电竞报:Epicenter震中杯即将开启,最良心DOTA2赛

    早些年曾经有外媒统计过DOTA2玩家世界的分布图,我们中国是世界上人口最多的国家,而且在DOTA2的赛事中经常会出...

  • 2018年星航战绩统计

    2月24日,v6,星航5:3多彩,小池~3球,小谢~1球,大拿~1球。 3月3日,v6,星航4:4百昌,崔~1球,...

  • Shell脚本统计DNA序列中碱基数目

    为了不编写perl脚本统计DNA中各碱基的数目,我采用了shell脚本直接对DNA序列进行统计。我的DNA序列如下...

  • 【前端日志采集】传输方案

    传统解决方案遇到的问题 统计脚本和其它脚本参合在一起,导致用户关闭页面过早,统计脚本还未加载/初始化完成。解决方法...

  • 自用链接汇总

    斗鱼Dota2熊猫Dota2火猫Dota2 虎牙Dota2斗鱼棋牌 一直播斗鱼美女花椒美女熊猫娱乐区全民星秀龙珠美...

  • GSE_统计位点测序深度

    统计位点测序深度 新建文件夹 新建脚本前文件 新建脚本 激活并运行脚本 进入结果文件夹

  • grep和wc来统计行数

    grep和wc来统计行数 功能: 统计行数 脚本: cat logs* | grep 返回编码 |wc -l ca...

  • shell awk 笔记

    用shell 脚本统计loj信息的思路 awk的行处理就是循环。{} 用数值统计 {shuzu[对象]++}...

  • svn 代码统计脚本

    公司用的版本管理是svn。有时候就好奇自己到底改了多少行代码才完成任务的。于是在网上一通百度,结果还真有人写了个神...

网友评论

      本文标题:Dota2 战绩统计脚本

      本文链接:https://www.haomeiwen.com/subject/copeodtx.html