41 lines
1.4 KiB
Python
41 lines
1.4 KiB
Python
import simpful
|
|
|
|
def kategoryzuj_strzaly(ilosc_strzalow):
|
|
FS = FuzzySystem()
|
|
TLV = AutoTriangle(3, terms=['mało', 'średnio', 'dużo'], universe_of_discourse=[0, 25])
|
|
FS.add_linguistic_variable("strzaly", TLV)
|
|
|
|
shots1 = TriangleFuzzySet(0, 0, 6, term='mało')
|
|
shots2 = TriangleFuzzySet(6, 12, 18, term='średnio')
|
|
shots3 = TriangleFuzzySet(12, 25, 25, term='dużo')
|
|
FS.add_linguistic_variable("bilans", LinguisticVariable([shots1, shots2, shots3], universe_of_discourse=[0, 25]))
|
|
|
|
FS.add_rules(["IF strzaly IS mało THEN bilans IS mało",
|
|
"IF strzaly IS średnio THEN bilans IS średnio",
|
|
"IF strzaly IS dużo THEN bilans IS dużo"])
|
|
|
|
FS.set_variable("strzaly", ilosc_strzalow)
|
|
bilans = FS.inference()
|
|
if bilans['bilans'] >= 12:
|
|
return 2
|
|
elif bilans['bilans'] <= 6:
|
|
return 0
|
|
else:
|
|
return 1
|
|
|
|
|
|
def kategorie_strzalow(druzyna, sezon, data, df):
|
|
ostatnie_spotkania = last5Matches(sezon, druzyna, data, df)
|
|
|
|
shots = []
|
|
for index, spotkanie in ostatnie_spotkania.iterrows():
|
|
if spotkanie['home_team'] == druzyna:
|
|
ilosc_strzalow = spotkanie['home_shots']
|
|
else:
|
|
ilosc_strzalow = spotkanie['away_shots']
|
|
|
|
kategoria = kategoryzuj_strzaly(ilosc_strzalow)
|
|
shots.append(kategoria)
|
|
ostatnie_spotkania['cat_shots'] = shots
|
|
|
|
return ostatnie_spotkania |