SystemyRozmyte/rules.py

122 lines
3.2 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)
points = calculatePoints(data_5,row['home_team'])
else:
data_5 = matches_type(row['season'], row['away_team'], row['date'], data)
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)
diff = calculateGoalDifference(data_5,row['home_team'])
else:
data_5 = matches_type(row['season'], row['away_team'], row['date'], data)
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