def __init__(self, gm, RoP): self.game = Game(gm, RoP) record, rot, bxs = self.game.preprocess(load=1) self.record = record self.rot = rot self.bxs = bxs self.dist = [ ' 0~ 5ft 2PT', ' 5~10ft 2PT', ' 10~15ft 2PT', ' 15~20ft 2PT', ' >20ft 2PT', ' <=25ft 3PT', ' 25~30ft 3PT', ' 30~35ft 3PT', ' 35~40ft 3PT', ' >40ft 3PT', ' restricted(RA)', ' paint(Non-RA)', ' mid range', ' left corner 3', ' right corner 3', ' above the break 3' ]
def detectgame(self, gm, playeres, season=0): game = Game(gm[:-7], 'playoff' if self.RoP else 'regular') for qtr in range(3, game.quarters): for ply in game.yieldPlay(qtr): play = Play(ply, qtr) if play.time() <= MPTime(self.lm): # 在规定时间内 rec, ind = play.record() s = play.score(ind=ind) if s and play.diffbeforescore(s) <= self.dp: try: p = self.pm2pn[rec.split(' ')[0]] except KeyError: p = rec.split(' ')[0] if season: p += ' %d_%d' % (season, season + 1) if p not in playeres: playeres[p] = np.zeros((1, len(self.columns))) if 'makes' in rec: # 得分增加命中数 playeres[p][0, 0] += s playeres[p][0, s * 3 - 1] += 1 if 'assist' in rec: # 受助攻 playeres[p][0, s + 11] += 1 playeres[p][0, 15] += 1 try: astp = self.pm2pn[rec.split(' ')[-1][:-1]] except: astp = rec.split(' ')[-1][:-1] if season: astp += ' %d_%d' % (season, season + 1) if astp not in playeres: playeres[astp] = np.zeros( (1, len(self.columns))) playeres[astp][0, s + 14] += 1 playeres = self.onlycountonce( astp, gm[:-7], playeres) playeres[p][0, s * 3] += 1 # 得分或投失增加出手数 playeres = self.onlycountonce(p, gm[:-7], playeres) # if 'LeBron James' in p and season == 2019: # print(s, play.play, gm[:-7], self.plyrcgs['LeBron James 2019_2020']) return playeres
def inline(r): line = r['R'][RoH] return sorted(line, reverse=True) lines_all = LoadPickle('./data/Lineups/anaSeason5Lineups.pickle') for season in range(2020, 2021): ss = '%d_%d' % (season, season + 1) for i in range(2): lines_all[i][ss] = {} lines = { } # {'tm1': {'line1': ['sum_time', '+/-'], 'line2': ['sum_time', '+/-'] ...}, 'tm2': ...} gms = os.listdir('D:/sunyiwu/stat/data/seasons/%s/%s/' % (ss, regularOrPlayoffs[i])) for gm in tqdm(gms): game = Game(gm, regularOrPlayoffs[i]) record = LoadPickle(gameMarkToDir(gm, regularOrPlayoffs[i], tp=3)) rot = game.rotation(record) bxs, rot = game.replayer(record, rot) et = '%d:00.0' % (48 + 5 * (game.quarters - 4)) for tmix, tm in enumerate(list(game.bxscr[0])): # 分别回溯两支球队 if tm not in lines: lines[tm] = {} RoH = list(game.bxscr[0]).index(tm) for ix, r in enumerate(rot): line = inline(r) if ' '.join(line) not in lines[tm]: lines[tm][' '.join(line)] = [ MPTime('0:00.0'), 0, [np.zeros((21, )), np.zeros((21, ))]
# ================ 球员单场数据准备 ================ mpsum += mp pts = float(sgm['PTS']) fta, ft, fga, fg, tpa, tp = float( sgm['FTA']), float(sgm['FT']), float( sgm['FGA']), float(sgm['FG']), float( sgm['3PA']), float(sgm['3P']) drb, orb, trb = float(sgm['DRB']), float( sgm['ORB']), float(sgm['TRB']) ast, stl, blk, tov, pf = float( sgm['AST']), float(sgm['STL']), float( sgm['BLK']), float(sgm['TOV']), float( sgm['PF']) # ================ 球员本队数据准备 ================ gm = sgm['Playoffs' if i else 'Date'].values[0] game = Game(gm, RoF[i]) tm_gametime = 48 if game.quarters == 4 else 48 + 5 * ( game.quarters - 4) plyrs = game.teamplyrs() ts = 0 if pm in plyrs[0] else 1 os = 0 if ts else 1 ttl = [ game.bxscr[1][0][-1], game.bxscr[1][1][-1] ] tm_ast, tm_fg = int(ttl[ts][14]), int( ttl[ts][2]) # 0.5 * ((Tm FGA + 0.4 * Tm FTA - 1.07 * (Tm ORB / (Tm ORB + Opp DRB)) * (Tm FGA - Tm FG) + Tm TOV) + # (Opp FGA + 0.4 * Opp FTA - 1.07 * (Opp ORB / (Opp ORB + Tm DRB)) * (Opp FGA - Opp FG) + Opp TOV)) tm_poss = int(ttl[ts][3]) + 0.4 * int( ttl[ts][9]) - 1.07 * ( int(ttl[ts][11]) /
[MPTime('0:00.0'), MPTime('0:00.0'), MPTime('0:00.0'), MPTime('0:00.0'), MPTime('0:00.0'), MPTime('0:00.0'), MPTime('0:00.0'), MPTime('0:00.0'), MPTime('0:00.0')], [MPTime('0:00.0'), MPTime('0:00.0'), MPTime('0:00.0'), MPTime('0:00.0'), MPTime('0:00.0'), MPTime('0:00.0'), MPTime('0:00.0'), MPTime('0:00.0'), MPTime('0:00.0')]], [[MPTime('0:00.0'), MPTime('0:00.0'), MPTime('0:00.0'), MPTime('0:00.0'), MPTime('0:00.0'), MPTime('0:00.0'), MPTime('0:00.0'), MPTime('0:00.0'), MPTime('0:00.0')], [MPTime('0:00.0'), MPTime('0:00.0'), MPTime('0:00.0'), MPTime('0:00.0'), MPTime('0:00.0'), MPTime('0:00.0'), MPTime('0:00.0'), MPTime('0:00.0'), MPTime('0:00.0')], [MPTime('0:00.0'), MPTime('0:00.0'), MPTime('0:00.0'), MPTime('0:00.0'), MPTime('0:00.0'), MPTime('0:00.0'), MPTime('0:00.0'), MPTime('0:00.0'), MPTime('0:00.0')]]] average_time = [[['', '', '', '', '', '', '', '', ''], ['', '', '', '', '', '', '', '', ''], ['', '', '', '', '', '', '', '', '']], [['', '', '', '', '', '', '', '', ''], ['', '', '', '', '', '', '', '', ''], ['', '', '', '', '', '', '', '', '']]] count_score = np.zeros((2, 3, 9)) ss = '%d_%d' % (season, season + 1) # print(ss) for i in range(2): # 分别统计常规赛、季后赛 gms = os.listdir('D:/sunyiwu/stat/data/seasons/%s/%s/' % (ss, regularOrPlayoffs[i])) for gm in tqdm(gms): count_games[i] += 1 # print('\t\t\t' + gm) game = Game(gm[:-7], regularOrPlayoffs[i]) gameplyrs = game.teamplyrs() record = LoadPickle(gameMarkToDir(gm[:-7], regularOrPlayoffs[i], tp=3)) # _, _, _, record = game.game_scanner(gm[:-7]) zoom = 0 bp = -1 pm = '' for rec in record: if zoom: # 处于抢断/失误观察期内 # 出现得失分 if 'MK' in rec or 'MS' in rec: GoM = 1 if 'MK' in rec else 0 KoS = 'MK' if GoM else 'MS' plyr_side = 0 if pm in gameplyrs[0] else 1 if tar_item: plyr_side = 0 if plyr_side else 1
#!/usr/bin/python # -*- coding:utf8 -*- from klasses.Game import Game from klasses.miscellaneous import MPTime gm = '200102280DEN' game = Game(gm, 'regular') # print(game.teamplyrs()) _, _, _, record = game.game_scanner(gm) for i in record: # if 'MK' in i or 'MS' in i: print(i) # game.game_analyser(gm, record) # game.pace(gm, record) game.find_time_series(gm, record) # a = MPTime('47:36.1') # b = MPTime('47:36.0') # print(a >= b) # True
#!/usr/bin/python # -*- coding:utf8 -*- from klasses.Game import Game from klasses.Player import Player from util import LoadPickle, playerMarkToDir, writeToPickle, gameMarkToSeason from stats_nba.Game_nba import Game_nba import pandas as pd import numpy as np np.set_printoptions(suppress=True) pd.options.display.expand_frame_repr = False pd.options.display.width = 50 RoF = 0 gm = '201201070NJN' game = Game(gm, 'playoff' if RoF else 'regular') record = game.game_scanner() # for i in record: # print(i) record = game.game_analyser(record) record = game.game_analyser(record, T=1) ss = gameMarkToSeason(gm) rof = 'playoff' if RoF else 'regular' season_dir = 'D:/sunyiwu/stat/data/seasons_scanned/%s/%s/' % (ss, rof) writeToPickle(season_dir + gm + '_scanned.pickle', record) for i in record: print(i) # print() game.find_time_series(record) game.start_of_quarter(record)
inter = 600 # 设置按时间归并区间的间隔 inter_s = inter // 10 whole = 34800 # 整场比赛时间(双加时为止) max_diff = 40 diff_inter = 5 # 1、2、3分 x 命中数、出手数 x -40~40分差 x 间隔统计时间 shoots = np.zeros((3, 2, max_diff * 2 // diff_inter + 1, whole // inter)) prctg = np.zeros((3, max_diff * 2 // diff_inter + 1, whole // inter)) for season in player.yieldSeasons(): for gameInf in player.yieldGames(season): # score += int(gameInf[26]) gm = gameInf[1] team = gameInf[3] op = gameInf[5] game = Game(gm, ROP, team, op) for qtr in range(game.quarters): for playInf in game.yieldPlay(qtr): play = Play(playInf, qtr, pm=pm, HOA=game.HOA) if play.playRecord() and play.teamPlay(): if play.playerAst(): # 助攻 asts += 1 elif play.playerMadeShoot(): # 命中投篮 s, d, t = score_diff_time(play, game, max_diff) d -= s # 关注的是球员得分前的分差 score += s t = tailTime(t, inter_s) d = groupDiff(d + 40, max_diff, diff_inter) shoots[s - 1, 0, d, t] += 1 shoots[s - 1, 1, d, t] += 1
import os from tqdm import tqdm from klasses.Game import Game from util import writeToPickle, gameMarkToDir, LoadPickle, plus_minus regularOrPlayoffs = ['regular', 'playoffs'] plyrs = {} # {'pm': [[gm], [节次], [+/-], [胜负], [是否比赛最后一节]]} for season in range(2000, 2020): ss = '%d_%d' % (season, season + 1) # print(ss) for i in range(1): gms = os.listdir('D:/sunyiwu/stat/data/seasons/%s/%s/' % (ss, regularOrPlayoffs[i])) for gmf in tqdm(gms): gm = gmf[:-7] game = Game(gm, regularOrPlayoffs[i]) _, _, _, record = game.game_scanner() rot = game.rotation(record) qtrs = rot[-1]['Q'] + 1 # 判断胜者 scores = [game.bxscr[0][x][0] for x in game.bxscr[0]] winner = int(scores[0] < scores[1]) for tm in range(2): # 分别回溯两支球队 # if tm not in plyrs: # plyrs[pm] = {} q = 0 tick = 0 SoQ = 0 for qtr in range(qtrs): # 定位至本届首发 st_pms = rot[tick]['R'][tm]
import numpy as np from klasses.Game import Game from util import writeToPickle, gameMarkToDir, LoadPickle regularOrPlayoffs = ['regular', 'playoffs'] seasons = {} plyrs = {} for season in range(1996, 2020): ss = '%d_%d' % (season, season + 1) # print(ss) seasons[ss] = [[0, 0, np.zeros((3, 7, 19))], [0, 0, np.zeros((3, 7, 19))]] for i in range(2): gms = os.listdir('D:/sunyiwu/stat/data/seasons/%s/%s/' % (ss, regularOrPlayoffs[i])) for gmf in tqdm(gms): gm = gmf[:-7] game = Game(gm, regularOrPlayoffs[i]) _, _, _, record = game.game_scanner() tmplyrs = game.teamplyrs() bx = game.boxscores(record)['STAT'] gametime = 48 if game.quarters == 4 else 48 + 5 * (game.quarters - 4) # 联盟赛季总和 seasons[ss][i][0] += 1 seasons[ss][i][1] += gametime seasons[ss][i][-1][0, 6, :] += bx[0] seasons[ss][i][-1][1, 6, :] += bx[1] seasons[ss][i][-1][2, 6, :] += (bx[0] + bx[1]) # 球员赛季总和 for rh in range(2): for pm in tmplyrs[rh]: if pm not in plyrs: plyrs[pm] = {}
class GameReviewer(object): def __init__(self, gm, RoP): self.game = Game(gm, RoP) record, rot, bxs = self.game.preprocess(load=1) self.record = record self.rot = rot self.bxs = bxs self.dist = [ ' 0~ 5ft 2PT', ' 5~10ft 2PT', ' 10~15ft 2PT', ' 15~20ft 2PT', ' >20ft 2PT', ' <=25ft 3PT', ' 25~30ft 3PT', ' 30~35ft 3PT', ' 35~40ft 3PT', ' >40ft 3PT', ' restricted(RA)', ' paint(Non-RA)', ' mid range', ' left corner 3', ' right corner 3', ' above the break 3' ] # for r in self.rot: # print(r) # # print(list(bxs.tdbxs[0][0]['team'])) # print(list(bxs.tdbxs[0][1]['team'])) # print(list(bxs.tdbxs[0][2]['team'])) # print(list(bxs.tdbxs[0][3]['team'])) # print(list(bxs.tdbxs[0][4]['team'])) # print() # print(list(bxs.tdbxs[1][0]['team'])) # print(list(bxs.tdbxs[1][1]['team'])) # print(list(bxs.tdbxs[1][2]['team'])) # print(list(bxs.tdbxs[1][3]['team'])) # print(list(bxs.tdbxs[1][4]['team'])) # print() # for tm in range(2): # for k in bxs.tdbxs[tm][0]: # if k != 'team': # print(k, 2880 / bxs.tdbxs[tm][0][k][0][-2] * bxs.tdbxs[tm][0][k][0][-3]) # print('all', list(bxs.tdbxs[tm][0][k][0])) # if k in bxs.tdbxs[tm][1]: # print(1, list(bxs.tdbxs[tm][1][k][0])[-3], list(bxs.tdbxs[tm][1][k][0])[-3] * 2880 / list(bxs.tdbxs[tm][1][k][0])[-2], list(bxs.tdbxs[tm][1][k][0])) # if k in bxs.tdbxs[tm][2]: # print(2, list(bxs.tdbxs[tm][2][k][0])[-3], list(bxs.tdbxs[tm][2][k][0])[-3] * 2880 / list(bxs.tdbxs[tm][2][k][0])[-2], list(bxs.tdbxs[tm][2][k][0])) # if k in bxs.tdbxs[tm][3]: # print(3, list(bxs.tdbxs[tm][3][k][0])[-3], list(bxs.tdbxs[tm][3][k][0])[-3] * 2880 / list(bxs.tdbxs[tm][3][k][0])[-2], list(bxs.tdbxs[tm][3][k][0])) # if k in bxs.tdbxs[tm][4]: # print(4, list(bxs.tdbxs[tm][4][k][0])[-3], list(bxs.tdbxs[tm][4][k][0])[-3] * 2880 / list(bxs.tdbxs[tm][4][k][0])[-2], list(bxs.tdbxs[tm][4][k][0])) # print() # print(list(bxs.tdbxs[0][0][k][1][0])) # print(list(bxs.tdbxs[0][0][k][1][1])) # print('\n') # 0FG 1FGA 2FG% 33P 43PA 53P% 6FT 7FTA 8FT% 9ORB 10DRB 11TRB 12AST 13STL 14BLK 15TOV 16PF 17PTS 18BP 19MP 20+/- def eFGperc(self): # 四要素之一:有效命中率 tmp = [0, 0] for i in range(2): bxsc = self.bxs.tdbxs[i][0]['team'] tmp[i] = (bxsc[0] + 0.5 * bxsc[3]) / bxsc[1] return tmp def TOVperc(self): # 四要素之一:失误率 tmp = [0, 0] for i in range(2): bxsc = self.bxs.tdbxs[i][0]['team'] tmp[i] = bxsc[15] / bxsc[18] return tmp def ORBperc(self): # 四要素之一:进攻篮板率 tmp = [0, 0] for i in range(2): bxsc = self.bxs.tdbxs[i][0]['team'] tmp[i] = bxsc[9] / (bxsc[9] + self.bxs.tdbxs[i - 1][0]['team'][10]) return tmp def FTr(self): # 四要素之一:造罚球率 tmp = [0, 0] for i in range(2): bxsc = self.bxs.tdbxs[i][0]['team'] tmp[i] = bxsc[6] / bxsc[1] return tmp def FTPtPTsperc(self): # 罚球得分占比 tmp = [0, 0] for i in range(2): bxsc = self.bxs.tdbxs[i][0]['team'] tmp[i] = bxsc[6] / bxsc[17] return tmp def FTprop(self): # 罚球出手/运动战出手比 tmp = [0, 0] for i in range(2): bxsc = self.bxs.tdbxs[i][0]['team'] tmp[i] = bxsc[7] / bxsc[1] return tmp def FTperc(self): # 罚球命中率 tmp = [0, 0] for i in range(2): bxsc = self.bxs.tdbxs[i][0]['team'] tmp[i] = bxsc[6] / bxsc[7] return tmp def twoPtperc(self): # 两分球命中率 tmp = [0, 0] for i in range(2): bxsc = self.bxs.tdbxs[i][0]['team'] tmp[i] = (bxsc[0] - bxsc[3]) / (bxsc[1] - bxsc[4]) return tmp def twoPtprop(self): # 两分球出手占比 tmp = [0, 0] for i in range(2): bxsc = self.bxs.tdbxs[i][0]['team'] tmp[i] = (bxsc[1] - bxsc[4]) / bxsc[1] return tmp def twoPtPTsperc(self): # 两分球得分占比 tmp = [0, 0] for i in range(2): bxsc = self.bxs.tdbxs[i][0]['team'] tmp[i] = (bxsc[0] - bxsc[3]) * 2 / bxsc[17] return tmp def threePtperc(self): # 三分球命中率 tmp = [0, 0] for i in range(2): bxsc = self.bxs.tdbxs[i][0]['team'] tmp[i] = bxsc[3] / bxsc[4] return tmp def threePtprop(self): # 三分球出手占比 tmp = [0, 0] for i in range(2): bxsc = self.bxs.tdbxs[i][0]['team'] tmp[i] = bxsc[4] / bxsc[1] return tmp def threePtPTsperc(self): # 三分球得分占比 tmp = [0, 0] for i in range(2): bxsc = self.bxs.tdbxs[i][0]['team'] tmp[i] = bxsc[3] * 3 / bxsc[17] return tmp def fourfactors(self): return pd.DataFrame( [self.eFGperc(), self.TOVperc(), self.ORBperc(), self.FTr()], index=[' eFG%', ' TOV%', ' ORB%', ' FT/FGA'], columns=list(self.game.bxscr[0])) def shooting(self): asts = [[0, 0], [0, 0]] for ix, rec in enumerate(self.game.gn.record): if 'MK' in rec and 'AST' in rec: asts[rec['MK'][1] - 2][rec['MK'][2]] += 1 asts[0][0] = asts[0][0] / (self.bxs.tdbxs[0][0]['team'][0] - self.bxs.tdbxs[0][0]['team'][3]) asts[0][1] = asts[0][1] / (self.bxs.tdbxs[1][0]['team'][0] - self.bxs.tdbxs[1][0]['team'][3]) asts[1][0] = asts[1][0] / self.bxs.tdbxs[0][0]['team'][ 3] if self.bxs.tdbxs[0][0]['team'][3] else -1 asts[1][1] = asts[1][1] / self.bxs.tdbxs[1][0]['team'][ 3] if self.bxs.tdbxs[1][0]['team'][3] else -1 return pd.DataFrame([ self.twoPtperc(), self.twoPtprop(), self.twoPtPTsperc(), asts[0], self.threePtperc(), self.threePtprop(), self.threePtPTsperc(), asts[1], self.FTperc(), self.FTprop(), self.FTPtPTsperc() ], index=[ ' 2PT %', ' 2PT FGA%', ' 2PT PTS%', ' 2PT ASTed%', ' 3PT %', ' 3PT FGA%', ' 3PT PTS%', ' 3PT ASTed%', ' FT %', ' FTA/FGA', ' FT PTS%' ], columns=list(self.game.bxscr[0])) def distance(self, rec): return math.sqrt(rec['C'][0]**2 + rec['C'][1]**2) / 10 def game_counter(self): tovpts, orbpts, paintpts, leadmax, longestrun = [0, 0], [0, 0], [0, 0], [ 0, 0 ], [0, 0] zoomtov, zoomorb, leaderchange, tie, run = 0, 0, 0, 0, 0 bptov, bporb, leadtm, runningtm = -1, -1, -1, -1 # ==================== 投篮分布数据 ==================== # 0客队1主队 0失手1命中 0 0~5 1 5~10 2 10~15 3 15~20 4 20~3PT 5 ~25 6 25~30 7 30~35 8 35~40 9 >40 10 限制区 11 paint限制区外 12 mid range shots = np.zeros((2, 3, len(self.dist))) for ix, rec in enumerate(self.game.gn.record): if 'MK' in rec or 'MS' in rec: GoM = 0 if 'MS' in rec else 1 item = 'MS' if 'MS' in rec else 'MK' if rec[item][1] > 1: d = self.distance(rec) # print(d, rec) # ==================== paint得分 ==================== if rec[item][1] > 1 and -80 <= rec['C'][0] <= 80 and rec[ 'C'][1] < 140: if GoM: paintpts[rec['MK'][2]] += rec['MK'][1] # if rec['MK'][2] == 1: # print(rec) if d <= 4: xx = 10 else: xx = 11 shots[rec[item][2], GoM, xx] += 1 if 'AST' in rec: shots[rec[item][2], 2, xx] += 1 else: if rec[item][1] < 3: shots[rec[item][2], GoM, 12] += 1 if 'AST' in rec: shots[rec[item][2], 2, 12] += 1 else: if rec['C'][0] <= -200 and rec['C'][ 1] <= 100: # left corner 3pt xx = 13 elif rec['C'][0] >= 200 and rec['C'][ 1] <= 100: # right corner 3pt xx = 14 else: xx = 15 shots[rec[item][2], GoM, xx] += 1 if 'AST' in rec: shots[rec[item][2], 2, xx] += 1 # ==================== 按距离得分统计 ==================== if d <= 5: xx = 0 elif d <= 10: xx = 1 elif d <= 15: xx = 2 elif d <= 20: xx = 3 elif rec[item][1] < 3: xx = 4 elif d <= 25: xx = 5 elif d <= 30: xx = 6 elif d <= 35: xx = 7 elif d <= 40: xx = 8 else: xx = 9 shots[rec[item][2], GoM, xx] += 1 if 'AST' in rec: shots[rec[item][2], 2, xx] += 1 ads = [[], []] for i in range(len(self.dist)): for tm in range(2): pre = [shots[tm][1][i], shots[tm][0][i] + shots[tm][1][i]] # FG/FGA tail = [ shots[tm][1][i] / self.bxs.tdbxs[tm][0]['team'][0], (shots[tm][0][i] + shots[tm][1][i]) / self.bxs.tdbxs[tm][0]['team'][1], shots[tm][1][i] * (3 if 5 <= i <= 9 or i > 12 else 2) / self.bxs.tdbxs[tm][0]['team'][17] ] # 区域命中比例、出手比例、得分比例 if shots[tm][1][i]: ads[tm].append(pre + [ shots[tm][1][i] / (shots[tm][0][i] + shots[tm][1][i]), shots[tm][2][i] / shots[tm][1][i] ] + tail) else: if shots[tm][0][i] + shots[tm][1][i]: ads[tm].append(pre + [ shots[tm][1][i] / (shots[tm][0][i] + shots[tm][1][i]), -1 ] + tail) else: ads[tm].append(pre + [-1, -1] + tail) ads = [ pd.DataFrame( x, index=self.dist, columns=['FG', 'FGA', '%', 'ASTed%', 'FG%', 'FGA%', 'PTS%']) for x in ads ] # ==================== 基础对比数据 ==================== for ix, rec in enumerate(self.record): # ==================== 交替领先、平分、连续得分 ==================== if 'MK' in rec: if rec['S'][0] != rec['S'][1]: li = 0 if rec['S'][0] > rec['S'][1] else 1 if li != leadtm: if leadtm != -1: leaderchange += 1 leadtm = li else: if self.record[ix - 1]['S'][0] != self.record[ix - 1]['S'][1]: tie += 1 li = rec['MK'][2] if li == runningtm: run += rec['MK'][1] else: if runningtm == -1: runningtm = li run += rec['MK'][1] else: if longestrun[li] < run: longestrun[li] = run runningtm = li run = rec['MK'][1] # ==================== 最大领先 ==================== li = 0 if rec['S'][0] > rec['S'][1] else 1 if rec['S'][li] != rec['S'][ li - 1] and rec['S'][li] - rec['S'][li - 1] > leadmax[li]: leadmax[li] = rec['S'][li] - rec['S'][li - 1] # ==================== 跨节 ==================== if len(rec) == 4 or (ix > 0 and rec['Q'] != self.record[ix - 1]['Q']): zoomtov, zoomorb = 0, 0 bptov, bporb = -1, -1 # ==================== 利用失误得分 ==================== if zoomtov: if 'MK' in rec and rec['M'] != 'technical': if rec['MK'][-1] == bptov: tovpts[bptov] += rec['MK'][1] # print(rec) else: if rec['M'] != 'technical': print('失误得分存疑', self.game.gm, rec) if rec['BP'] != bptov: zoomtov = 0 bptov = -1 if 'TOV' in rec: bptov = rec['BP'] zoomtov = 1 # ==================== 二次进攻 ==================== if zoomorb: if 'MK' in rec: if rec['MK'][-1] == bporb: # print(rec) orbpts[bporb] += rec['MK'][1] else: if rec['M'] != 'technical': print('二次进攻得分存疑', self.game.gm, rec) if rec['BP'] != bporb: zoomorb = 0 bporb = -1 if 'ORB' in rec and (rec['ORB'] != 'Team' or ('MS' in self.record[ix - 1] and self.record[ix - 1]['MS'][1] > 1) or ('MS' in self.record[ix - 1] and self.record[ix - 1]['D'][1] == self.record[ix - 1]['D'][0])): bporb = rec['BP'] zoomorb = 1 # print(self.game.gm, tovpts[0], orbpts[0], paintpts[0], tovpts[1], orbpts[1], paintpts[1]) # ==================== 汇总数据 ==================== return pd.DataFrame( [[ self.bxs.tdbxs[0][0]['team'][-3], self.bxs.tdbxs[1][0]['team'][-3] ], tovpts, [ tovpts[0] / self.bxs.tdbxs[0][0]['team'][-4], tovpts[1] / self.bxs.tdbxs[1][0]['team'][-4] ], orbpts, [ orbpts[0] / self.bxs.tdbxs[0][0]['team'][-4], orbpts[1] / self.bxs.tdbxs[1][0]['team'][-4] ], paintpts, [ paintpts[0] / self.bxs.tdbxs[0][0]['team'][-4], paintpts[1] / self.bxs.tdbxs[1][0]['team'][-4] ], leadmax, [ leadmax[0] / self.bxs.tdbxs[0][0]['team'][-4], leadmax[1] / self.bxs.tdbxs[1][0]['team'][-4] ], longestrun, [ longestrun[0] / self.bxs.tdbxs[0][0]['team'][-4], longestrun[1] / self.bxs.tdbxs[1][0]['team'][-4] ], [leaderchange, leaderchange], [tie, tie]], index=[ ' pace', ' pts off tovs', ' pts% off tovs', ' 2nd chance pts', ' 2nd chance pts%', ' pts in the paint', ' pts% in the paint', ' biggest lead', ' biggest lead pts%', ' longest run', ' longest run pts%', ' lead changes', ' times tied' ], columns=list(self.game.bxscr[0])), ads