Exemplo n.º 1
0
 def update_pts(self, lst, rec, r):  # 更新得分类数据
     pt = lst[1]
     ix = 17
     if lst[0] not in self.qtr_stats[
             lst[2]] or lst[0] not in self.plyrs_oncourt[
                 lst[2]]:  # 若球员不在场,则此时刻所有得分同时作用于下场和上场球员(下场球员的遗留影响、上场球员已在场上)
         # print(self.gm, rec, r)
         if lst[0] not in self.plyrs_mp:
             self.plyrs_mp[lst[0]] = MPTime(rec['T'])
         try:
             assert rec['T'] == r['T']
         except:
             print(self.gm, rec, r)
             raise KeyError
         if lst[0] not in self.qtr_stats[lst[2]]:
             self.qtr_stats[lst[2]][lst[0]] = [
                 np.zeros((self.num_items, )),
                 [
                     np.zeros((self.num_items, )),
                     np.zeros((self.num_items, ))
                 ]
             ]
         self.qtr_stats[lst[2]][lst[0]][1][0][ix] += pt
     self.qtr_stats[lst[2]][lst[0]][0][ix] += pt
     self.qtr_stats[lst[2]]['team'][ix] += pt
     for tm in range(2):
         for pm in self.plyrs_oncourt[tm]:
             self.qtr_stats[tm][pm][1][0 if tm == lst[2] else 1][ix] += pt
Exemplo n.º 2
0
    def singleplayer(self, pm):
        player = Player(pm, self.RoP)
        if not player.exists or isinstance(player.data, list):
            return '', ''
        pres = {}  # 球员结果
        atds = 0  # 总人数
        for ss, yy in player.yieldSeasons():
            yy = yy.replace('-', '_' + yy[:2] if yy[2:4] != '99' else '_20')
            try:
                sf = self.seasonfile(yy)
            except:
                continue
            sgn = sf.shape[0]
            ig = 0
            for game in player.yieldGames(ss):
                gm, wol, diff = game['Date' if self.RoP == 'regular' else 'Playoffs'],\
                                game['WoL'][0], int(game['WoL'][3:-1])
                while sf['gm'][ig] != gm and ig < sgn - 1:
                    ig += 1
                gb = sf.loc[ig]
                refs, atd, tog = gb['Referees'].split(', '),\
                                 gb['Attendance'] if gb['Attendance'] != -1 else 0, gb['Time of Game']
                if atd:
                    atds += atd  # 球馆观众人数
                tog = MPTime(tog, reverse=False) if tog else MPTime(
                    '0:00.0', reverse=False)
                if refs[0]:
                    for r in refs:  # 执法裁判
                        if r not in pres:
                            pres[r] = [
                                0, 0, 0, 0,
                                MPTime('0:00.0', reverse=False)
                            ]  # 胜率、胜场数、总场数、分差、比赛时长
                        if wol == 'W':
                            pres[r][1] += 1
                        pres[r][2] += 1
                        pres[r][3] += diff
                        pres[r][4] += tog

        for i in pres:
            pres[i][0] = '%.1f%%' % (pres[i][1] / pres[i][2] * 100)
            pres[i][4] = pres[i][4].average(pres[i][2])
            pres[i][3] = '%.1f' % (pres[i][3] / pres[i][2])
        return sorted(pres.items(), key=lambda x: x[1][1],
                      reverse=True), atds / player.games
Exemplo n.º 3
0
def new_player(pm, ss):
    if pm not in plyrs:  # 新建球员统计
        plyrs[pm] = [[
            0,
            MPTime('0:00.0'), 0, {
                'TOV': [0, 0]
            }, 0, [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], {}
        ],
                     [
                         0,
                         MPTime('0:00.0'), 0, {
                             'TOV': [0, 0]
                         }, 0, [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], {}
                     ]]
    if ss not in plyrs[pm][i][-1]:  # 新建球员赛季统计
        plyrs[pm][i][-1][ss] = [
            0,
            MPTime('0:00.0'), 0, {
                'TOV': [0, 0]
            }, 0, [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]
        ]
Exemplo n.º 4
0
 def swt(
     self,
     new,
     t=0
 ):  # 节内发生换人,初始化新上场球员数据,更新场上阵容    t = 0 节中换人  1 节中换人且最后一条记录未转换球权(202012220BRK {'Q': 2, 'T': '28:03.0', 'MS': ['jordade01', 1, 1], 'D': [2, 2], 'M': '', 'BP': 1, 'S': [49, 77]})
     ix = 19
     for tm in range(2):
         on_pms = set(new['R'][tm]) - set(self.plyrs_oncourt[tm])
         off_pms = set(self.plyrs_oncourt[tm]) - set(new['R'][tm])
         # 上场球员:记录上场时刻,初始化数据统计格式
         for on_pm in on_pms:
             if on_pm not in self.plyrs_mp:
                 self.plyrs_mp[on_pm] = MPTime(new['T'])
             if on_pm not in self.qtr_stats[tm]:
                 self.qtr_stats[tm][on_pm] = [
                     np.zeros((self.num_items, )),
                     [
                         np.zeros((self.num_items, )),
                         np.zeros((self.num_items, ))
                     ]
                 ]
             # if t:    # 节中换上场球员pace修正
             self.qtr_stats[tm][on_pm][0][18] += 0.5
             self.qtr_stats[tm][on_pm][1][0][18] += 0.5
             self.qtr_stats[tm][on_pm][1][1][18] += 0.5
         # 下场球员:累计上场时间
         for off_pm in off_pms:
             assert off_pm in self.plyrs_mp
             self.qtr_stats[tm][off_pm][0][ix] += (
                 MPTime(new['T']) - self.plyrs_mp[off_pm]).secs()
             self.plyrs_mp.pop(off_pm)
             # if off_pm == 'wiggian01':
             #     print(self.qtr_stats[0]['wiggian01'])
             if t:  # 节中换下场球员pace修正
                 self.qtr_stats[tm][off_pm][0][18] -= 0.5
                 self.qtr_stats[tm][off_pm][1][0][18] -= 0.5
                 self.qtr_stats[tm][off_pm][1][1][18] -= 0.5
                 # print(off_pm, self.qtr_stats[tm][off_pm][0][18])
     self.plyrs_oncourt = new['R']
Exemplo n.º 5
0
def splitLineups(lines5):
    print(list(lines5[0])[0], '...', list(lines5[0])[-1])
    print(list(lines5[1])[0], '...', list(lines5[1])[-1])
    lines_all = [[{}, {}], [{}, {}], [{}, {}],
                 [{}, {}]]  # 0一人组合1二人组合2三人组合3四人组合 0常规赛1季后赛
    for season in range(2002, 2021):
        ss = '%d_%d' % (season, season + 1)
        print(ss)
        for i in range(2):
            lines1234 = [{}, {}, {}, {}]  # 单赛季按球队 0一人组合1二人组合2三人组合3四人组合
            for tm in lines5[i][ss]:
                # 球队lineups初始化
                for ix in range(4):
                    if tm not in lines1234[ix]:
                        lines1234[ix][tm] = {}
                    lines_all[ix][i][ss] = {}
                line5_tm = lines5[i][ss][tm]  # 单队5人lineups
                # print(tm, len(line5_tm))
                for L in line5_tm:
                    pms = L.split(' ')  # 遍历每组5人组合
                    # print(pms)
                    pms1234 = [[], [], [], []]  # 0一人组合1二人组合2三人组合3四人组合
                    for c in range(1, 5):  # 按照每组5人组合,使用(排列)组合方法穷尽所有1-4人的搭配
                        for iter in itertools.combinations(pms, c):
                            pms1234[c - 1].append(list(iter))
                    for ix, combs_i in enumerate(
                            pms1234):  # 遍历1-4人的所有搭配,累加时间和正负值
                        for combs in combs_i:
                            combstr = ' '.join(sorted(combs))
                            if combstr not in lines1234[ix][tm]:  # 每种组合初始化
                                lines1234[ix][tm][combstr] = [
                                    MPTime('0:00.0'), 0
                                ]
                            lines1234[ix][tm][combstr][0] += line5_tm[L][0]
                            lines1234[ix][tm][combstr][1] += line5_tm[L][1]
            for ix in range(4):
                for tm in lines1234[ix]:
                    lines_sorted = {}
                    for k in sorted(lines1234[ix][tm],
                                    key=lines1234[ix][tm].__getitem__,
                                    reverse=True):  # 字典按值排序
                        lines_sorted[k] = lines1234[ix][tm][k]
                    lines_all[ix][i][ss][tm] = lines_sorted

    for ix in range(4):
        writeToPickle(
            'D:/sunyiwu/stat/data/Lineups/anaSeason%dLineups.pickle' %
            (ix + 1), lines_all[ix])
Exemplo n.º 6
0
 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
Exemplo n.º 7
0
                  (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, ))]
                 ]  # 0时间 1+/- 2详细数据   0本队数据1对手数据
             if ix == 0:
                 tt = '0:00.0'
                 stats = np.zeros((21, ))
                 s = [0, 0]
             else:
                 try:
                     assert r['T'] != tt or (ix > 0 and
                                             r['Q'] != rot[ix - 1]['Q'])
                 except:
                     print(gm, tt, r)
                     print(rot[ix - 1])
                 if set(r['R'][RoH]) != set(rot[ix - 1]['R'][RoH]):
Exemplo n.º 8
0
 print('防守篮板/总篮板占比', lg_drbp)
 print('联盟运动战单打能力', lg_factor)
 print('bbr复杂pace估计', lg_pace)
 print('传统pace估计',
       (lg_stats[1] - lg_stats[9] + lg_stats[15] + 0.44 * lg_stats[7]) /
       lg_games / 2)
 lgsum, lgames, lgmax, lgmin = 0, 0, [0, []], [30, []]
 for pm in tqdm(pms):
     if ss in enforce['Turnover'][pm][i][-1]:
         pmdir = playerMarkToDir(pm, RoF[i])
         if pmdir:
             plyr = Player(pm, RoF[i])
             ssgms = plyr.getSeason(ss)
             num_games = ssgms.shape[0]
             if num_games >= games_td[i]:
                 mpsum, scoresum = MPTime('0:00'), 0
                 for g in range(num_games):
                     sgm = ssgms[g:g + 1]
                     mp = MPTime(sgm['MP'].values[0])
                     if mp.mf() != 0:
                         # ================ 球员单场数据准备 ================
                         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(
Exemplo n.º 9
0
tar_item = 1    # 0抢断1失误
sentence = "'TOV' in rec and rec['plyr'] != 'Team' and rec['plyr'] != ''" if tar_item else "'TOV' in rec and 'STL' in rec"


def new_player(pm, ss):
    if pm not in plyrs:  # 新建球员统计
        plyrs[pm] = [[0, MPTime('0:00.0'), 0, {'TOV': [0, 0]}, 0, [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], {}],
                     [0, MPTime('0:00.0'), 0, {'TOV': [0, 0]}, 0, [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], {}]]
    if ss not in plyrs[pm][i][-1]:  # 新建球员赛季统计
        plyrs[pm][i][-1][ss] = [0, MPTime('0:00.0'), 0, {'TOV': [0, 0]}, 0, [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]


for season in range(2000, 2001):
    count_games = [0, 0]  # 0reg1plf
    count_item = np.zeros((2, 3, 9))  # 0reg1plf    0客场球队1主场球队2总    0总1第一节2第二节3第三节4第四节5f加时6s加时7t加时8f加时
    count_time = [[[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')],
                   [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)
Exemplo n.º 10
0
 # 0命中率1投中2出手3罚球命中率4罚球投中5罚球出手6两分命中率7两分投中8两分出手9三分命中率10三分投中11三分出手
 # 12助攻两分13助攻三分14盖帽15总得分16负责得分17eFG%18TS%
 for season in tqdm(range(1996, 2020)):
     ss = '%d_%d' % (season, season + 1)
     # print('starting to analysing season %s:' % ss)
     gms = os.listdir('D:/sunyiwu/stat/data/seasons/%s/%s/' %
                      (ss, regularOrPlayoffs[i]))
     for gm in gms:
         count_games += 1
         game = Game(gm[:-7], regularOrPlayoffs[i])
         record = LoadPickle(
             gameMarkToDir(gm[:-7], regularOrPlayoffs[i], tp=3))
         # _, _, _, record = game.game_scanner(gm[:-7])
         lastqtr = record[-1]['Q']  # 最后一节节次
         assert lastqtr > 2
         lastsec = MPTime('%d:00.0' % (48 + 5 * (lastqtr - 3)))  # 本场最后时刻
         ix = -1  # 从后往前遍历比赛过程
         for qtr in range(lastqtr -
                          2):  # 从最后时刻开始统计(若有加时则依次从后往前统计每节次最后时刻至第四节为止)
             if qtr > 0:
                 lastsec = lastsec - MPTime('5:00.0')  # 本节最后时刻
             timetd = lastsec - MPTime(lastSecs)  # 统计时间范围
             while record[ix]['Q'] > lastqtr - qtr:
                 ix -= 1
             ft = [-1, -1, -1]
             ftt = [-1, -1]
             ftplus = [-1, -1, -1, -1,
                       '']  # 第4个元素用于判断罚球方与运动战投篮出手方是否一致,第5个元素用于记录罚球人
             while MPTime(record[ix]['T']
                          ) >= timetd and record[ix]['Q'] == lastqtr - qtr:
                 tmp = record[ix]
Exemplo n.º 11
0
 def default_mp(self, now):
     for tm in range(2):
         for pm in self.plyrs_oncourt[tm]:
             self.plyrs_mp[pm] = MPTime(now)
Exemplo n.º 12
0
    def qtr_end(self, qtr, new, end=0):  # 一节结束,整理本节数据(更新所有上过场球员的数据,包括基础和进阶)
        # 更新打至节末的球员的上场时间
        endt = MPTime(new['T']) if qtr < 4 else MPTime(
            '%d:00.0' % (48 if qtr == 4 else 48 + 5 * (qtr - 4)))
        for tm in range(2):
            for off_pm in self.plyrs_oncourt[tm]:
                # print(qtr, off_pm)
                # print(new)
                assert off_pm in self.plyrs_mp
                self.qtr_stats[tm][off_pm][0][19] += (
                    endt - self.plyrs_mp[off_pm]).secs()
        # 更新本节出场球员其它数据
        periods = [0, qtr]
        if qtr < 5:
            periods.append(9 if qtr < 3 else 10)
        for n in periods:
            self.qtr_end_pm(n, self.tdbxs, self.qtr_stats)
        # 待完成:更新单节进阶数据

        if not end:
            # 更新新的一节上场球员及上场时间点
            self.plyrs_oncourt = new['R']
            self.qtr_stats = [{}, {}]
            self.default_qtr()
            self.plyrs_mp = {}
            self.default_mp(new['T'])
        if end:
            # 计算各项命中率
            for tm in range(2):
                for qtr in range(11):
                    for pm in self.tdbxs[tm][qtr]:
                        if pm == 'team':
                            self.cal_perc(self.tdbxs[tm][qtr][pm])
                        else:
                            self.cal_perc(self.tdbxs[tm][qtr][pm][0])
                            self.cal_perc(self.tdbxs[tm][qtr][pm][1][0])
                            self.cal_perc(self.tdbxs[tm][qtr][pm][1][1])
        if end and 0:
            print('客队')
            for i in self.tdbxs[0][0]:
                if i == 'team':
                    print(i, list(self.tdbxs[0][0][i]))
                else:
                    print(i, list(self.tdbxs[0][0][i][0]))
            print('主队')
            for i in self.tdbxs[1][0]:
                if i == 'team':
                    print(i, list(self.tdbxs[1][0][i]))
                else:
                    print(i, list(self.tdbxs[1][0][i][0]))
            print(self.tdbxs[0][0]['team'])
            print(self.tdbxs[1][0]['team'])
            # 0FG 1FGA 2FG% 33P 43PA 53P% 6FT 7FTA 8FT% 9ORB 10DRB 11TRB 12AST 13STL 14BLK 15TOV 16PF 17PTS 18BP 19MP 20+/-
            for pm in self.tdbxs[0][0]:
                if pm != 'team':
                    pmself = self.tdbxs[0][0][pm][0]  # 球员自身数据
                    pmtm = self.tdbxs[0][0][pm][1][0]  # 球员在场期间本队数据
                    pmop = self.tdbxs[0][0][pm][1][1]  # 球员在场期间敌队数据
                    astp = pmself[12] / (
                        pmtm[0] - pmself[0]) if pmtm[0] - pmself[0] else float(
                            'nan')  # 助攻率
                    ast2to = pmself[12] / pmself[15] if pmself[15] else float(
                        'nan')  # 助攻失误比
                    drbp = pmself[10] / (
                        pmtm[10] + pmop[9]) if pmtm[10] + pmop[9] else float(
                            'nan')  # 防守篮板率
                    orbp = pmself[9] / (
                        pmtm[9] + pmop[10]) if pmtm[9] + pmop[10] else float(
                            'nan')  # 进攻篮板率
                    trbp = (pmself[9] + pmself[10]) / (
                        pmtm[10] + pmop[9] + pmtm[9] + pmop[10]
                    ) if pmtm[10] + pmop[9] + pmtm[9] + pmop[10] else float(
                        'nan')  # 总篮板率
                    print(pm, astp, ast2to, orbp, drbp, trbp)
Exemplo n.º 13
0
 print('联盟进攻效率(分/回合)', lg_vop)
 print('防守篮板/总篮板占比', lg_drbp)
 print('联盟运动战单打能力', lg_factor)
 lgsum, lgames, lgmax, lgmin = 0, 0, [0, []], [30, []]
 for pm in pms:
     pmdir = playerMarkToDir(pm, RoF[i], tp=1)
     if pmdir:
         cr = LoadPickle(pmdir)
         if ss in cr['Season'].values and ss in plyr_ss[pm]:
             cr_a = cr[cr['Season'] == ss][:1]
             cr_s = cr[cr['Season'] == ss][1:]
             num_games = cr_a['G']
             num_games = int(num_games.values[0][:-3])
             if num_games >= games_td[i] or int(
                     cr_s['MP'].values[0].split(':')[0]) > 1600:
                 mp = MPTime(cr_a['MP'].values[0])
                 pts = float(cr_a['PTS'])
                 fta = float(cr_a['FTA'])
                 ft = float(cr_a['FT'])
                 fga = float(cr_a['FGA'])
                 fg = float(cr_a['FG'])
                 tpa = float(cr_a['3PA'])
                 tp = float(cr_a['3P'])
                 bga = fga - tpa
                 bg = fg - tp
                 fmiss = fta - ft
                 tmiss = tpa - tp
                 bmiss = bga - bg
                 drb = float(cr_a['DRB'])
                 orb = float(cr_a['ORB'])
                 trb = float(cr_a['TRB'])
Exemplo n.º 14
0
 def ave_and_sum(self, tmp, type=2):  # type=0:计算总和 1:计算均值 2:计算均值和总和
     if isinstance(tmp, list):
         tmp = pd.DataFrame(tmp,
                            columns=regular_items_en.keys()
                            if not self.RoP else playoff_items_en.keys())
     if type:
         ave = []
     sumn = []
     for k in tmp.columns:
         if k == 'G':  # 首列
             if type:
                 ave.append('%d场平均' % tmp.shape[0])
             sumn.append('%d场总和' % tmp.shape[0])
         elif k in ['Playoffs', 'Date', 'Age', 'Tm', 'Opp', 'Series', 'G#']:
             if type:
                 ave.append('/')
             sumn.append('/')
         elif k == 'RoH':  # 统计主客场数量
             try:
                 at = np.sum(tmp[k] == '@')
             except:
                 at = 0
             if type:
                 ave.append('%dR/%dH' % (at, tmp.shape[0] - at))
             sumn.append('%dR/%dH' % (at, tmp.shape[0] - at))
         elif k == 'WoL':  # 统计几胜几负
             origin = WinLoseCounter(False)
             for i in tmp[k]:
                 origin += WinLoseCounter(True, strwl=i)
             if type:
                 ave.append(origin.average())
             sumn.append(origin)
         elif k == 'GS':  # 统计首发次数
             cs = tmp[k].value_counts()
             if cs.empty:
                 if type:
                     ave.append('')
                 sumn.append('')
             else:
                 try:
                     s = np.sum(tmp[k] == '1')
                 except:
                     s = 0
                 if type:
                     ave.append('%d/%d' % (s, tmp.shape[0]))
                 sumn.append('%d/%d' % (s, tmp.shape[0]))
         elif k == 'MP':  # 时间加和与平均
             sum_time = MPTime('0:00.0', reverse=False)
             for i in tmp[k]:
                 if isinstance(i, str):
                     sum_time += MPTime(i, reverse=False)
             if type:
                 ave.append(sum_time.average(tmp.shape[0]))
             sumn.append(sum_time.strtime[:-2])
         elif '%' in k:  # 命中率单独计算
             goal = tmp[[k[:-1], k[:-1] + 'A']]
             goal = goal.dropna(axis=0, how='any')
             goal = goal.astype('float').sum(axis=0)
             p = goal[k[:-1]] / goal[k[:-1] +
                                     'A'] if goal[k[:-1] +
                                                  'A'] else float('nan')
             if not math.isnan(p):
                 p = '%.3f' % p
                 if p != '1.000':
                     p = p[1:]
             else:
                 p = ''
             if type:
                 ave.append(p)
             sumn.append(p)
         else:
             tmp_sg = tmp[k][tmp[k].notna()]
             # tmp_sg = tmp_sg[tmp_sg != '']
             if not tmp_sg.empty:
                 if type:
                     # print(tmp_sg)
                     try:
                         a = '%.1f' % tmp_sg.astype('float').mean()
                     except:
                         tmp_sg = tmp_sg[tmp_sg != '']
                         a = '%.1f' % tmp_sg.astype('float').mean()
                 # 除比赛评分以外其他求和结果均为整数
                 s = '%.1f' % tmp_sg.astype('float').sum(
                 ) if k == 'GmSc' else int(tmp_sg.astype('int').sum())
                 if k == '+/-':  # 正负值加+号
                     if type and s != 0 and a[0] != '-':
                         a = '+' + a
                     if s > 0:
                         s = '+%d' % s
                 if s == 'nan':
                     if type:
                         a = ''
                     s = ''
             else:
                 a, s = '', ''
             if type:
                 ave.append(a)
             sumn.append(s)
     if type == 0:
         return [sumn]
     elif type == 1:
         return [ave]
     else:
         return [ave, sumn]
Exemplo n.º 15
0
 def time(self):  # 当前时间(本节倒计时)
     return MPTime(self.play[0])
Exemplo n.º 16
0
    if ss not in plyrs[pm][i][-1]:  # 新建球员赛季统计
        plyrs[pm][i][-1][ss] = [
            0,
            MPTime('0:00.0'), 0, {
                'TOV': [0, 0]
            }, 0, [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]
        ]


for season in range(1996, 2020):
    count_games = [0, 0]  # 0reg1plf
    count_item = np.zeros(
        (2, 3,
         9))  # 0reg1plf    0客场球队1主场球队2总    0总1第一节2第二节3第三节4第四节5f加时6s加时7t加时8f加时
    count_time = [[[
        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'),