loading

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.5015594644766146","path":"main.py","file":{"path":"main.py","content":{"asEncoding":{"base64":"IyAtKi0gY29kaW5nOiB1dGYtOCAtKi0KIiIiCkFuYWx5emUgTkJBIHBsYXlvZmZzIGZpcnN0IHJvdW5kIGRhdGEgKDIwMDh+MjAxOCkKQ29weXJpZ2h0IGJ5IEphcnZ1cyBDaGVuIC8gaHR0cHM6Ly9qYXJ2dXMubmV0CiIiIgoKaW1wb3J0IG51bXB5IGFzIG5wCmltcG9ydCBwaWNrbGUKCiMgcGFyYW1ldGVycwp3b3JsZCA9ICfopb8nICAgICAgICAgICAgIyAn5p2xJyBvciAn6KW/JwpmaXJzdF9ob21lID0gNCAgICAgICAgICAjIOezu+WIl+izveesrOS4gOaIsO+8jOeUseesrOW5vumghuS9jeeCuuS4u+WgtApnYW1lX3JvdW5kID0gNSAgICAgICAgICAjIOezu+WIl+izveesrOW5vuaIsO+8jDF+NwpsYXN0X3Jlc3VsdCA9ICdob21lJyAgICAjIOS4iuS4gOWgtOe1kOaenO+8jCdob21lJyBvciAnYXdheScKaGlnaF9zY29yZSA9IDMgICAgICAgICAgIyDpq5jpoIbkvY0oMX405ZCNKeWkp+avlOWIhgpsb3dfc2NvcmUgPSAxICAgICAgICAgICAjIOS9jumghuS9jSg1fjjlkI0p5aSn5q+U5YiGCgojIGltcG9ydCBkYXRhCndpdGggb3BlbignLi9tYXRjaF9saXN0LmRhdGEnLCAncmInKSBhcyBmcDoKICAgIG1hdGNoX2xpc3QgPSBwaWNrbGUubG9hZChmcCkKCiMgbWFpbgptYXRjaF9kaWN0ID0ge30KZm9yIG1hdGNoIGluIG1hdGNoX2xpc3Q6CgogICAgaWYgbm90IG1hdGNoWzBdWyd5ZWFyJ10gaW4gbWF0Y2hfZGljdDoKICAgICAgICBtYXRjaF9kaWN0W21hdGNoWzBdWyd5ZWFyJ11dID0ge30KCiAgICBpZiBtYXRjaFswXVsnd29ybGQ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GFbJ3dpbiddID09ICdob21lJzoKICAgICAgICAgICAgICAgICAgICBob21lX3dpbl9jb3VudCA9IGhvbWVfd2luX2NvdW50ICsgMQogICAgICAgICAgICAgICAgICAgIGhvbWVfd2luX3Njb3JlLmFwcGVuZCggZGF0YVsnaG9tZV9taW51c19hd2F5J10gKQogICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgaWYgZGF0YVsnd2luJ10gPT0gJ2F3YXknOgogICAgICAgICAgICAgICAgICAgIGF3YXlfd2luX2NvdW50ID0gYXdheV93aW5fY291bnQgKyAxCiAgICAgICAgICAgICAgICAgICAgYXdheV93aW5fc2NvcmUuYXBwZW5kKCAtZGF0YVsnaG9tZV9taW51c19hd2F5J10gKQogICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICB3aW5fbGlzdC5hcHBlbmQoZGF0YVsnaG9tZV9taW51c19hd2F5J10pCiAgICAgICAgICAgICAgICB5ZWFyX2xpc3QuYXBwZW5kKGRhdGFbJ3llYXInXSkKCmlmIGxlbihob21lX3dpbl9zY29yZSkgPiAwOgogICAgaG9tZV93aW5fYXZnID0gbnAucm91bmQobnAubWVhbihob21lX3dpbl9zY29yZSksIDEpCmVsc2U6CiAgICBob21lX3dpbl9hdmcgPSAwCmlmIGxlbihhd2F5X3dpbl9zY29yZSkgPiAwOgogICAgYXdheV93aW5fYXZnID0gbnAucm91bmQobnAubWVhbihhd2F5X3dpbl9zY29yZSksIDEpCmVsc2U6CiAgICBhd2F5X3dpbl9hdmcgPSAwCgpwcmludCgpCnByaW50KCdJZiBHYW1lJyxnYW1lX3JvdW5kLTEsICd3aW5uZXIgaXMnLCBsYXN0X3Jlc3VsdCwgJywgdGhlbiBHYW1lJywgZ2FtZV9yb3VuZCkKcHJpbnQoJ0hvbWU6JywgaG9tZV93aW5fY291bnQsICcsIGF2ZyBzY29yZTonLCBob21lX3dpbl9hdmcpCnByaW50KCdBd2F5OicsIGF3YXlfd2luX2NvdW50LCAnLCBhdmcgc2NvcmU6JywgYXdheV93aW5fYXZnKQpwcmludCgnWWVhcjonLCB5ZWFyX2xpc3QpCnByaW50KCdIb21lLUF3YXk6Jywgd2luX2xpc3QpCgpob21lX3dpbl9jb3VudCA9IDAKYXdheV93aW5fY291bnQgPSAwCmhvbWVfd2luX3Njb3JlID0gW10KYXdheV93aW5fc2NvcmUgPSBbXQp3aW5fbGlzdCA9IFtdCnllYXJfbGlzdCA9IFtdCgpmb3Iga2V5LCBtYXRjaCBpbiBtYXRjaF9kaWN0Lml0ZW1zKCk6CiAgICAKICAgIGlmIGZpcnN0X2hvbWUgaW4gbWF0Y2ggYW5kIGxlbihtYXRjaFtmaXJzdF9ob21lXSkgPiBnYW1lX3JvdW5kOgogICAgICAgIGlmIG1hdGNoW2ZpcnN0X2hvbWVdW2dhbWVfcm91bmQtMl1bJ2ZpcnN0X2F3YXlfYmlnX3Njb3JlJ10gPT0gbG93X3Njb3JlIGFuZCBtYXRjaFtmaXJzdF9ob21lXVtnYW1lX3JvdW5kLTJdWydmaXJzdF9ob21lX2JpZ19zY29yZSddID09IGhpZ2hfc2NvcmUgOgogICAgICAgIAogICAgICAgICAgICBpZiBsZW4obWF0Y2hbZmlyc3RfaG9tZV0pID49IGdhbWVfcm91bmQ6CiAgICAgICAgICAgIAogICAgICAgICAgICAgICAgZGF0YSA9IG1hdGNoW2ZpcnN0X2hvbWVdW2dhbWVfcm91bmQtMV0KICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgaWYgZGF0YVsnd2luJ10gPT0gJ2hvbWUnOgogICAgICAgICAgICAgICAgICAgIGhvbWVfd2luX2NvdW50ID0gaG9tZV93aW5fY291bnQgKyAxCiAgICAgICAgICAgICAgICAgICAgaG9tZV93aW5fc2NvcmUuYXBwZW5kKCBkYXRhWydob21lX21pbnVzX2F3YXknXSApCiAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICBpZiBkYXRhWyd3aW4nXSA9PSAnYXdheSc6CiAgICAgICAgICAgICAgICAgICAgYXdheV93aW5fY291bnQgPSBhd2F5X3dpbl9jb3VudCArIDEKICAgICAgICAgICAgICAgICAgICBhd2F5X3dpbl9zY29yZS5hcHBlbmQoIC1kYXRhWydob21lX21pbnVzX2F3YXknXSApCiAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgIHdpbl9saXN0LmFwcGVuZChkYXRhWydob21lX21pbnVzX2F3YXknXSkKICAgICAgICAgICAgICAgIHllYXJfbGlzdC5hcHBlbmQoZGF0YVsneWVhciddKQoKaWYgbGVuKGhvbWVfd2luX3Njb3JlKSA+IDA6CiAgICBob21lX3dpbl9hdmcgPSBucC5yb3VuZChucC5tZWFuKGhvbWVfd2luX3Njb3JlKSwgMSkKZWxzZToKICAgIGhvbWVfd2luX2F2ZyA9IDAKaWYgbGVuKGF3YXlfd2luX3Njb3JlKSA+IDA6CiAgICBhd2F5X3dpbl9hdmcgPSBucC5yb3VuZChucC5tZWFuKGF3YXlfd2luX3Njb3JlKSwgMSkKZWxzZToKICAgIGF3YXlfd2luX2F2ZyA9IDAKCnByaW50KCkKcHJpbnQoJ0lmIHRoZSBiaWcgc2NvcmUgaXMnLCBoaWdoX3Njb3JlLCAnLScsIGxvd19zY29yZSwgJywgdGhlbiBHYW1lJywgZ2FtZV9yb3VuZCkKcHJpbnQoJ0hvbWU6JywgaG9tZV93aW5fY291bnQsICcsIGF2ZyBzY29yZTonLCBob21lX3dpbl9hdmcpCnByaW50KCdBd2F5OicsIGF3YXlfd2luX2NvdW50LCAnLCBhdmcgc2NvcmU6JywgYXdheV93aW5fYXZnKQpwcmludCgnWWVhcjonLCB5ZWFyX2xpc3QpCnByaW50KCdIb21lLUF3YXk6Jywgd2luX2xpc3Qp"},"asBuffer":null},"loaded":true}}
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# -*- 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 = 4          # 系列賽第一戰,由第幾順位為主場
game_round = 5          # 系列賽第幾戰,1~7
last_result = 'home'    # 上一場結果,'home' or 'away'
high_score = 3          # 高順位(1~4名)大比分
low_score = 1           # 低順位(5~8名)大比分

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

# main
match_dict = {}
for match in match_list:

    if not match[0]['year'] in match_dict:
        match_dict[match[0]['year']] = {}

    if match[0]['world'] == world:
        if not str(match[0]['first_home']) in match_dict[match[0]['year']]:
            match_dict[match[0]['year']][str(match[0]['first_home'])] = []            
        match_dict[match[0]['year']][str(match[0]['first_home'])].extend(match)
   
home_win_count = 0
away_win_count = 0
home_win_score = []
away_win_score = []
win_list = []
year_list = []
first_home = str(first_home)

for key, match in match_dict.items():
    
    if first_home in match and len(match[first_home]) > game_round:
        if match[first_home][game_round-2]['win'] == last_result:
#        if match[first_home][0]['win'] == 'home' and match[team][1]['win'] == 'home':
        
            if len(match[first_home]) >= game_round:
            
                data = match[first_home][game_round-1]
                
                if data['win'] == 'home':
                    home_win_count = home_win_count + 1
                    home_win_score.append( data['home_minus_away'] )
                    
                if data['win'] == 'away':
                    away_win_count = away_win_count + 1
                    away_win_score.append( -data['home_minus_away'] )
                
                win_list.append(data['home_minus_away'])
                year_list.append(data['year'])

if len(home_win_score) > 0:
    home_win_avg = np.round(np.mean(home_win_score), 1)
else:
    home_win_avg = 0
if len(away_win_score) > 0:
    away_win_avg = np.round(np.mean(away_win_score), 1)
else:
    away_win_avg = 0

print()
print('If Game',game_round-1, 'winner is', last_result, ', then Game', game_round)
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)

home_win_count = 0
away_win_count = 0
home_win_score = []
away_win_score = []
win_list = []
year_list = []

for key, match in match_dict.items():
    
    if first_home in match and len(match[first_home]) > game_round:
        if match[first_home][game_round-2]['first_away_big_score'] == low_score and match[first_home][game_round-2]['first_home_big_score'] == high_score :
        
            if len(match[first_home]) >= game_round:
            
                data = match[first_home][game_round-1]
                
                if data['win'] == 'home':
                    home_win_count = home_win_count + 1
                    home_win_score.append( data['home_minus_away'] )
                    
                if data['win'] == 'away':
                    away_win_count = away_win_count + 1
                    away_win_score.append( -data['home_minus_away'] )
                
                win_list.append(data['home_minus_away'])
                year_list.append(data['year'])

if len(home_win_score) > 0:
    home_win_avg = np.round(np.mean(home_win_score), 1)
else:
    home_win_avg = 0
if len(away_win_score) > 0:
    away_win_avg = np.round(np.mean(away_win_score), 1)
else:
    away_win_avg = 0

print()
print('If the big score is', high_score, '-', low_score, ', then Game', game_round)
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)