loading
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# -*- coding: utf-8 -*-
"""
Analyze NBA playoffs first round data (2008~2018)
Copyright by Jarvus Chen / https://jarvus.net
"""

import numpy as np
import pickle

# parameters
world = '東'        # '東' or '西'
first_home = 2      # 系列賽第一戰,由第幾順位為主場
game_round = 5      # 系列賽第幾戰,1~7

# import data
with open('./match_list.data', 'rb') as fp:
    match_list = pickle.load(fp)

# main
home_win_count = 0
away_win_count = 0
home_win_score = []
away_win_score = []
win_list = []
year_list = []
 
for match in match_list:

    if len(match) >= game_round:
        
        if match[game_round-1]['world'] == world and match[game_round-1]['first_home'] == first_home:
        
            if match[game_round-1]['win'] == 'home':
                home_win_count = home_win_count + 1
                home_win_score.append( match[game_round-1]['home_minus_away'] )
                
            if match[game_round-1]['win'] == 'away':
                away_win_count = away_win_count + 1
                away_win_score.append( -match[game_round-1]['home_minus_away'] )
            
            win_list.append(match[game_round-1]['home_minus_away'])
            year_list.append(match[game_round-1]['year'])
            
home_win_avg = np.round(np.mean(home_win_score), 1)
away_win_avg = np.round(np.mean(away_win_score), 1)

print('Home:', home_win_count, ',avg score:', home_win_avg)
print('Away:', away_win_count, ',avg score:', away_win_avg)
print('Year:', year_list)
print('Home-Away:', win_list)