-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpast_k_results.py
56 lines (49 loc) · 1.84 KB
/
past_k_results.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
51
52
53
54
55
56
from load_data import FootballData
import datetime
def average(numbers_list):
if numbers_list is not None:
return float(sum(numbers_list)) / len(numbers_list)
else:
return None
class PastKResults:
def __init__(self, season, K=4):
self.football_data = FootballData()
self.season_data = self.football_data.seasons_data[season]
self.K = K
def get_past_K_games_results(self, team, game_date):
k = 0
K_last_full_time_results = []
for item in self.season_data:
if game_date > item[1]:
if item[2] == team:
k = k + 1
if item[6] == 'H':
K_last_full_time_results.append(3)
elif item[6] == 'A':
K_last_full_time_results.append(1)
else:
K_last_full_time_results.append(2)
if item[3] == team:
k = k + 1
if item[6] == 'A':
K_last_full_time_results.append(3)
elif item[6] == 'H':
K_last_full_time_results.append(1)
else:
K_last_full_time_results.append(2)
if k >= self.K:
return K_last_full_time_results
return None
def get_past_K_avg_results(self, team, game_date):
past_K_games = self.get_past_K_games_results(team, game_date)
return average(past_K_games)
# ----------------------------------
# my own tests
# season14 = PastKResults('D2014')
# print(season14.get_past_K_games_results("Bayern-Munich", datetime.date(2015, 2, 14)))
# print(season14.get_past_K_avg_results("Bayern Munich", datetime.date(2015, 2, 14)))
#
# print(pastk)
# print(pastkboth)
# print(pastkavg)
# ----------------------------