Dota2 戰(zhàn)績(jī)統(tǒng)計(jì)腳本

utils.py的內(nèi)容如下

import dota2api

API_KEY = "xxxx" # 這個(gè)需要去steam打開開發(fā)者權(quán)限. 然后把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

查詢的使用, 比如 查找我的戰(zhàn)績(jī), 和隊(duì)友的開黑戰(zhàn)績(jī):

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權(quán)限需要充值5美元. 不需要消費(fèi), 僅充值就好. 或者有5美元的消費(fèi)記錄也是可以的. 點(diǎn)擊這個(gè)鏈接可以開啟api權(quán)限: https://steamcommunity.com/dev/apikey. 如果你已經(jīng)開啟了, 那么這個(gè)鏈接就可以顯示你的key

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容