107 lines
2.8 KiB
Python
107 lines
2.8 KiB
Python
import pandas as pd
|
|
from simpful import *
|
|
|
|
df = pd.read_csv('df_full_premierleague.csv')
|
|
|
|
|
|
# Ostatnie 5 spotkań
|
|
#Forma: 0-6 punktow = słaba, średnia 6-10, dobra 10-15 punktow
|
|
#Bilans bramek ujemny dodatni
|
|
#Strzały 6- mało pomiędzy średnio 12 - dużo
|
|
#Posiadanie piłki słabe 30-40, średnie = 40-55, dobre = 56-64
|
|
#Podania ponizej 300-400 słabo powyżej 500 dużo
|
|
|
|
|
|
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 last5Matches(sezon, druzynaA, data, df):
|
|
# Wybierz rekordy dla danej pary drużyn i sezonu
|
|
subset = df[((df['season'] == sezon) & ((df['home_team'] == druzynaA) | (df['away_team'] == druzynaA)))]
|
|
|
|
# Filtruj dane, aby zawierały te przed daną datą
|
|
przed_dana_data = subset[pd.to_datetime(subset['date']) < pd.to_datetime(data)]
|
|
|
|
# Posortuj wg daty w odwrotnej kolejności
|
|
przed_dana_data = przed_dana_data.sort_values(by='date', ascending=False)
|
|
|
|
# Wybierz 5 ostatnich przed daną datą
|
|
ostatnie_przed_data = przed_dana_data.head(5)
|
|
|
|
return ostatnie_przed_data
|
|
|
|
|
|
|
|
|
|
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
|
|
return points
|
|
|
|
|
|
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
|
|
|
|
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
|
|
|
|
wynik = last5Matches('10/11', 'Stoke City', '2010-10-02', df)
|
|
#print(wynik.to_markdown())
|
|
print(wynik)
|
|
#wynik = last5Matches('10/11', 'Blackburn Rovers', '2010-10-02', df)
|
|
#print(wynik.to_markdown())
|
|
#print(wynik)
|
|
|
|
print(calculatePoints(wynik,'Stoke City'))
|
|
print(calculateGoalDifference(wynik, 'Stoke City'))
|
|
|
|
df = generateTrainingData(df)
|
|
print(df)
|
|
|
|
|