82 lines
2.4 KiB
Python
82 lines
2.4 KiB
Python
import pandas as pd
|
|
from simpful import *
|
|
|
|
def generateTrainingData(dataframe):
|
|
columns = ['season','date','home_team','away_team','result_full','home_passes','away_passes',
|
|
'home_possession','away_possession','home_shots','away_shots']
|
|
return dataframe[columns]
|
|
|
|
|
|
def generateFuzzyLogicData(dataframe):
|
|
columns = ['season','date','home_team','away_team','result_full','c_home_passes','c_away_passes',
|
|
'c_home_possession','c_away_possession','c_home_shots','c_away_shots','c_home_form','c_away_form',
|
|
'c_home_diff', 'c_away_diff']
|
|
return dataframe[columns]
|
|
|
|
def last5Matches(season, teamA, data, df):
|
|
# Wybierz rekordy dla danej pary drużyn i sezonu
|
|
subset = df[((df['season'] == season) & ((df['home_team'] == teamA) | (df['away_team'] == teamA)))]
|
|
|
|
# Filtruj dane, aby zawierały te przed daną datą
|
|
before_given_date = subset[pd.to_datetime(subset['date']) < pd.to_datetime(data)]
|
|
|
|
# Posortuj wg daty w odwrotnej kolejności
|
|
before_given_date = before_given_date.sort_values(by='date', ascending=False)
|
|
|
|
# Wybierz 5 ostatnich przed daną datą
|
|
last_before_date = before_given_date.head(5)
|
|
|
|
return last_before_date
|
|
|
|
|
|
|
|
|
|
def getResult(score,teamHome):
|
|
x,y = score.split('-')
|
|
x = int(x)
|
|
y = int(y)
|
|
|
|
if (x > y and teamHome == True) or (x < y and teamHome == False):
|
|
return "win"
|
|
elif x == y:
|
|
return "draw"
|
|
else:
|
|
return "loss"
|
|
|
|
|
|
def calculatePoints(matches, team):
|
|
points = 0
|
|
for index, row in matches.iterrows():
|
|
if team == row['home_team']:
|
|
teamHome = True
|
|
else:
|
|
teamHome = False
|
|
x = getResult(row['result_full'], teamHome)
|
|
#print(x)
|
|
if x == "win":
|
|
points = points + 3
|
|
elif x == "draw":
|
|
points = points + 1
|
|
if matches.shape[0] != 0:
|
|
points_avg = points / matches.shape[0]
|
|
else:
|
|
points_avg = 0
|
|
return points_avg
|
|
|
|
|
|
def calculateGoalDifference(matches, team):
|
|
goal_diff = 0
|
|
for index, row in matches.iterrows():
|
|
if team == row['home_team']:
|
|
teamHome = True
|
|
else:
|
|
teamHome = False
|
|
x,y = row['result_full'].split('-')
|
|
x = int(x)
|
|
y = int(y)
|
|
if teamHome:
|
|
goal_diff = goal_diff + (x-y)
|
|
else:
|
|
goal_diff = goal_diff + (y-x)
|
|
return goal_diff
|