forked from s452662/SystemyRozmyte
207 lines
6.3 KiB
Python
207 lines
6.3 KiB
Python
from data_filters import *
|
|
import pandas as pd
|
|
|
|
|
|
def categorize_shots(shots):
|
|
if shots >= 12:
|
|
return 2
|
|
elif shots <= 6:
|
|
return 0
|
|
else:
|
|
return 1
|
|
|
|
def categorize_passes(pass_count):
|
|
if pass_count < 400:
|
|
return 0 #słabo
|
|
elif 400 <= pass_count <= 500:
|
|
return 1 #średnio
|
|
else:
|
|
return 2 #dużo
|
|
|
|
def categorize_possesion(shots):
|
|
if shots >= 56:
|
|
return 2
|
|
elif shots <= 40:
|
|
return 0
|
|
else:
|
|
return 1
|
|
|
|
def categorize_points(data, row, teamHome, matches_type):
|
|
if teamHome:
|
|
data_5 = matches_type(row['season'], row['home_team'], row['date'], data)[0]
|
|
points = calculatePoints(data_5,row['home_team'])
|
|
else:
|
|
data_5 = matches_type(row['season'], row['away_team'], row['date'], data)[0]
|
|
points = calculatePoints(data_5,row['away_team'])
|
|
if points <=1:
|
|
return 0
|
|
elif points >=2:
|
|
return 2
|
|
else:
|
|
return 1
|
|
|
|
def categorize_points_Btw(data, row, teamHome, matches_type):
|
|
if teamHome:
|
|
data_5 = matches_type(row['home_team'], row['away_team'], row['date'], data)[0]
|
|
points = calculatePoints(data_5,row['home_team'])
|
|
else:
|
|
data_5 = matches_type(row['home_team'], row['away_team'], row['date'], data)[0]
|
|
points = calculatePoints(data_5,row['away_team'])
|
|
if points <=1:
|
|
return 0
|
|
elif points >=2:
|
|
return 2
|
|
else:
|
|
return 1
|
|
|
|
|
|
|
|
|
|
def get_method(data, home_away, method, matches_type):
|
|
values = []
|
|
for index, row in data.iterrows():
|
|
values.append(method(data, row, home_away, matches_type))
|
|
return values
|
|
|
|
|
|
def get_points_home(data):
|
|
points = []
|
|
for index, row in data.iterrows():
|
|
points.append(categorize_points(data, row, True))
|
|
return points
|
|
|
|
|
|
|
|
|
|
def get_points_away(data):
|
|
points = []
|
|
for index, row in data.iterrows():
|
|
points.append(categorize_points(data, row, False))
|
|
return points
|
|
|
|
|
|
|
|
def categorize_diff(data, row, teamHome, matches_type):
|
|
if teamHome:
|
|
data_5 = matches_type(row['season'], row['home_team'], row['date'], data)[0]
|
|
diff = calculateGoalDifference(data_5,row['home_team'])
|
|
else:
|
|
data_5 = matches_type(row['season'], row['away_team'], row['date'], data)[0]
|
|
diff = calculateGoalDifference(data_5,row['away_team'])
|
|
if diff <=0:
|
|
return 0
|
|
else:
|
|
return 1
|
|
|
|
def categorize_diff_Btw(data, row, teamHome, matches_type):
|
|
if teamHome:
|
|
data_5 = matches_type(row['home_team'], row['away_team'], row['date'], data)[0]
|
|
diff = calculateGoalDifference(data_5,row['home_team'])
|
|
else:
|
|
data_5 = matches_type(row['home_team'], row['away_team'], row['date'], data)[0]
|
|
diff = calculateGoalDifference(data_5,row['away_team'])
|
|
if diff <=0:
|
|
return 0
|
|
else:
|
|
return 1
|
|
|
|
|
|
def categorize_diff(data, row, teamHome, matches_type):
|
|
if teamHome:
|
|
data_5 = matches_type(row['season'], row['home_team'], row['date'], data)[0]
|
|
diff = calculateGoalDifference(data_5,row['home_team'])
|
|
else:
|
|
data_5 = matches_type(row['season'], row['away_team'], row['date'], data)[0]
|
|
diff = calculateGoalDifference(data_5,row['away_team'])
|
|
if diff <=0:
|
|
return 0
|
|
else:
|
|
return 1
|
|
|
|
# def categorize_aggression(data, row, teamHome, matches_type):
|
|
# if teamHome:
|
|
# data_5 = matches_type(row['season'], row['home_team'], row['date'], data)
|
|
# diff = calculateAggression(data_5,row['home_team'])
|
|
# else:
|
|
# data_5 = matches_type(row['season'], row['away_team'], row['date'], data)
|
|
# diff = calculateAggression(data_5,row['away_team'])
|
|
# return diff
|
|
# # if diff <=0:
|
|
# # return 0
|
|
# # else:
|
|
# # return 1
|
|
def get_diff_home(data):
|
|
points = []
|
|
for index, row in data.iterrows():
|
|
points.append(categorize_diff(data, row, True))
|
|
return points
|
|
|
|
|
|
|
|
|
|
def get_diff_away(data):
|
|
points = []
|
|
for index, row in data.iterrows():
|
|
points.append(categorize_diff(data, row, False))
|
|
return points
|
|
|
|
|
|
|
|
|
|
def add_column(data_frame, transform_function, new_column, existing_column=None):
|
|
if existing_column != None:
|
|
new_column_values = data_frame[existing_column].apply(transform_function)
|
|
data_frame[new_column] = new_column_values
|
|
else:
|
|
new_column_values = transform_function
|
|
data_frame[new_column] = new_column_values
|
|
return data_frame
|
|
|
|
def get_result_list(df, home_team):
|
|
results = []
|
|
for score in df['result_full']:
|
|
results.append(getResult(score,home_team))
|
|
return results
|
|
|
|
def getColumnMethod(data, home_away, column, matches_type):
|
|
values = []
|
|
for index, row in data.iterrows():
|
|
values.append(getColumnByMatches(data, row, home_away, matches_type,column))
|
|
return values
|
|
|
|
def getColumnMethod5Btw(data, home_away, column, matches_type):
|
|
values = []
|
|
for index, row in data.iterrows():
|
|
values.append(getColumnByMatches5Btw(data, row, home_away, matches_type,column))
|
|
return values
|
|
|
|
def getFuzzyMethod(data, method, home_away, frist_column, second_column):
|
|
values = []
|
|
for index, row in data.iterrows():
|
|
values.append(getFuzzyByMatches(method, row, home_away, frist_column, second_column))
|
|
return values
|
|
|
|
def getColumnByMatches(data, row, teamHome, matches_type, column):
|
|
if teamHome:
|
|
data_5, end = matches_type(row['season'], row['home_team'], row['date'], data)
|
|
result = calculateColumn(data_5, row['home_team'], column)
|
|
else:
|
|
data_5, end = matches_type(row['season'], row['away_team'], row['date'], data)
|
|
result = calculateColumn(data_5, row['away_team'], column)
|
|
return result
|
|
|
|
def getColumnByMatches5Btw(data, row, teamHome, matches_type, column):
|
|
if teamHome:
|
|
data_5, end = last5MatchesBtwTeams(row['home_team'], row['away_team'], row['date'], data)
|
|
result = calculateColumn(data_5, row['home_team'], column)
|
|
else:
|
|
data_5, end = matches_type(row['home_team'], row['away_team'], row['date'], data)
|
|
result = calculateColumn(data_5, row['away_team'], column)
|
|
return result
|
|
|
|
def getFuzzyByMatches(method, row, teamHome, frist_column, second_column):
|
|
if teamHome:
|
|
result = method(row[frist_column], row[second_column])
|
|
else:
|
|
result = method(row[frist_column], row[second_column])
|
|
return result |