Changes
This commit is contained in:
parent
5dc90d347e
commit
bb11bc87cc
@ -12,6 +12,8 @@ class calculating:
|
||||
for key in tableDict:
|
||||
numMatch = tableDict[key][1]
|
||||
points = tableDict[key][7]
|
||||
goals = tableDict[key][6]
|
||||
goals = round(goals/numMatch, 2)
|
||||
val = round(points/numMatch, 2)
|
||||
del tableDict[key][1]
|
||||
del tableDict[key][1]
|
||||
@ -19,6 +21,8 @@ class calculating:
|
||||
del tableDict[key][1]
|
||||
del tableDict[key][1]
|
||||
del tableDict[key][2]
|
||||
del tableDict[key][1]
|
||||
tableDict[key].append(goals)
|
||||
tableDict[key].append(val)
|
||||
self.tableDict = tableDict
|
||||
|
||||
@ -28,13 +32,13 @@ class calculating:
|
||||
valueDict = self.valueDict
|
||||
prevPlaceDict = self.prevPlaceDict
|
||||
for key in tableDict:
|
||||
for ke in valueDict:
|
||||
if re.match(key,ke):
|
||||
tableDict[key].append(valueDict[ke])
|
||||
# for ke in valueDict:
|
||||
# if re.match(key,ke):
|
||||
# tableDict[key].append(valueDict[ke])
|
||||
for ke in prevPlaceDict:
|
||||
if re.match(key,ke):
|
||||
tableDict[key].append(prevPlaceDict[ke])
|
||||
if len(tableDict[key]) == 4:
|
||||
if len(tableDict[key]) == 3:
|
||||
tableDict[key].append(15)
|
||||
self.tableDict = tableDict
|
||||
|
||||
|
76
main.py
76
main.py
@ -2,47 +2,56 @@ import numpy as np
|
||||
import skfuzzy as fuzz
|
||||
from skfuzzy import control as ctrl
|
||||
from calculating import calculating
|
||||
import collections
|
||||
|
||||
prevPlace = ctrl.Antecedent(np.arange(0, 17, 1), 'prevPlace')
|
||||
teamValue = ctrl.Antecedent(np.arange(0, 31, 1), 'teamValue')
|
||||
currentPlace = ctrl.Antecedent(np.arange(0, 17, 1), 'currentPlace')
|
||||
points = ctrl.Antecedent(np.arange(0, 4, 1), 'points')
|
||||
goals = ctrl.Antecedent(np.arange(-26, 26, 1), 'goals')
|
||||
points = ctrl.Antecedent(np.arange(0, 2.3, 0.1), 'points')
|
||||
goals = ctrl.Antecedent(np.arange(-2.0, 2.0, 0.2), 'goals')
|
||||
|
||||
place = ctrl.Consequent(np.arange(0, 100, 1), 'place')
|
||||
|
||||
# prevPlace.automf(3)
|
||||
# teamValue.automf(5)
|
||||
place.automf(3)
|
||||
prevPlace['Low'] = fuzz.trimf(prevPlace.universe, [10,16,16])
|
||||
prevPlace['Medium'] = fuzz.trimf(prevPlace.universe, [4,8,12])
|
||||
prevPlace['High'] = fuzz.trimf(prevPlace.universe, [0,0,6])
|
||||
place.automf(5)
|
||||
prevPlace['Low'] = fuzz.trimf(prevPlace.universe, [12,16,16])
|
||||
prevPlace['Medium'] = fuzz.trimf(prevPlace.universe, [5,8,12])
|
||||
prevPlace['High'] = fuzz.trimf(prevPlace.universe, [0,0,5])
|
||||
|
||||
teamValue['Low'] = fuzz.trimf(teamValue.universe, [0,0,10])
|
||||
teamValue['Medium'] = fuzz.trimf(teamValue.universe, [8,12,16])
|
||||
teamValue['High'] = fuzz.trimf(teamValue.universe, [15,30,30])
|
||||
|
||||
currentPlace['Low'] = fuzz.trimf(currentPlace.universe, [10,16,16])
|
||||
currentPlace['Medium'] = fuzz.trimf(currentPlace.universe, [4,8,12])
|
||||
currentPlace['High'] = fuzz.trimf(currentPlace.universe, [0,0,6])
|
||||
currentPlace['Low'] = fuzz.trimf(currentPlace.universe, [12,16,16])
|
||||
currentPlace['Medium'] = fuzz.trimf(currentPlace.universe, [5,8,12])
|
||||
currentPlace['High'] = fuzz.trimf(currentPlace.universe, [0,0,5])
|
||||
|
||||
points['Low'] = fuzz.trimf(points.universe, [0,0, 1.0])
|
||||
points['Medium'] = fuzz.trimf(points.universe, [1.0,1.4, 1.8])
|
||||
points['High'] = fuzz.trimf(points.universe, [1.8,3,3])
|
||||
points['Low'] = fuzz.trimf(points.universe, [0,0, 1.2])
|
||||
points['Medium'] = fuzz.trimf(points.universe, [1.0,1.4, 1.7])
|
||||
points['High'] = fuzz.trimf(points.universe, [1.7,2.2,2.2])
|
||||
|
||||
goals['Low'] = fuzz.trimf(goals.universe, [-15,-15,-5])
|
||||
goals['Medium'] = fuzz.trimf(goals.universe, [-5,0,5])
|
||||
goals['High'] = fuzz.trimf(goals.universe, [5,15,15])
|
||||
goals['Low'] = fuzz.trimf(goals.universe, [-2,-2,-0.8])
|
||||
goals['Medium'] = fuzz.trimf(goals.universe, [-1.0,0,1])
|
||||
goals['High'] = fuzz.trimf(goals.universe, [0.8,2.0,2.0])
|
||||
|
||||
prevPlace.view()
|
||||
# teamValue.view()
|
||||
rule1 = ctrl.Rule(prevPlace['Low'] | currentPlace['Low'] | points['Low'], place['poor'])
|
||||
rule2 = ctrl.Rule(points['Medium'] | currentPlace['Medium'] | goals['Medium'] | prevPlace['Medium'], place['average'])
|
||||
rule3 = ctrl.Rule(teamValue['High'] | goals['High'] | prevPlace['High'], place['good'])
|
||||
rule4 = ctrl.Rule(teamValue['High'] | points['High'], place['good'])
|
||||
rule5 = ctrl.Rule(goals['High'] | currentPlace['High'], place['good'])
|
||||
|
||||
placeCtrl = ctrl.ControlSystem([rule1, rule2, rule3, rule4, rule5])
|
||||
|
||||
points.view()
|
||||
|
||||
rule1 = ctrl.Rule(prevPlace['Low'] | currentPlace['Low'] | points['Low'] | goals['Low'], place['poor'])
|
||||
rule2 = ctrl.Rule(prevPlace['Medium'] | currentPlace['Medium'] | points['Medium'] | goals['Medium'], place['average'])
|
||||
rule3 = ctrl.Rule((currentPlace['High']) | (points['High'] | goals['High']), place['good'])
|
||||
# rule4 = ctrl.Rule(prevPlace['High'], place['good'])
|
||||
# rule4 = ctrl.Rule(prevPlace['Medium'] | currentPlace['High'] | goals['High'], place['decent'])
|
||||
# rule5 = ctrl.Rule(prevPlace['High'] | currentPlace['Medium'], place['good'])
|
||||
# rule6 = ctrl.Rule(goals['Low'] | prevPlace['High'] | points['Medium'], place['average'])
|
||||
# rule7 = ctrl.Rule(prevPlace['High'] | currentPlace['Medium'], place['decent'])
|
||||
# rule5 = ctrl.Rule(currentPlace['High'] & points['High'], place['good'])
|
||||
|
||||
|
||||
|
||||
placeCtrl = ctrl.ControlSystem([rule1, rule2, rule3])
|
||||
calPlace = ctrl.ControlSystemSimulation(placeCtrl)
|
||||
|
||||
|
||||
@ -50,20 +59,27 @@ calPlace = ctrl.ControlSystemSimulation(placeCtrl)
|
||||
calculate = calculating()
|
||||
calculate.cleanTeamParameters()
|
||||
dict = calculate.joinDict()
|
||||
|
||||
teamsPlace = {}
|
||||
for key in dict:
|
||||
print(key + " = " + str(dict[key]))
|
||||
print(key + " = " + str(dict[key]))
|
||||
calPlace.input['currentPlace'] = dict[key][0]
|
||||
calPlace.input['goals'] = dict[key][1]
|
||||
calPlace.input['points'] = dict[key][2]
|
||||
calPlace.input['teamValue'] = dict[key][3]
|
||||
calPlace.input['prevPlace'] = dict[key][4]
|
||||
calPlace.input['prevPlace'] = dict[key][3]
|
||||
# calPlace.input['prevPlace'] = dict[key][4]
|
||||
|
||||
calPlace.compute()
|
||||
print(calPlace.output['place'])
|
||||
# place.view(sim=calPlace)
|
||||
|
||||
# print(calPlace.output['place'])
|
||||
teamsPlace[key] = calPlace.output['place']
|
||||
place.view(sim=calPlace)
|
||||
|
||||
|
||||
sorted_x = sorted(teamsPlace.items(), key=lambda kv: kv[1])
|
||||
sorted_dict = collections.OrderedDict(sorted_x)
|
||||
listReversed = list(reversed(sorted_dict))
|
||||
print()
|
||||
print("Results:")
|
||||
for item in reversed(sorted_dict):
|
||||
print(item + " = " + str(sorted_dict[item]))
|
||||
|
||||
|
||||
|
79
scrap.py
79
scrap.py
@ -1,21 +1,29 @@
|
||||
import requests
|
||||
import re
|
||||
from bs4 import BeautifulSoup
|
||||
from collections import OrderedDict
|
||||
|
||||
class scrap:
|
||||
|
||||
def fetch_data(self, url):
|
||||
# Sezon 18/19 kolejka 10
|
||||
# https://www.transfermarkt.pl/ekstraklasa/formtabelle/wettbewerb/PL1?saison_id=2018&min=1&max=10
|
||||
# Kolejka 15
|
||||
# https: // www.transfermarkt.pl / ekstraklasa / formtabelle / wettbewerb / PL1?saison_id = 2018 & min = 1 & max = 15
|
||||
# Kolejka 20
|
||||
# https: // www.transfermarkt.pl / ekstraklasa / formtabelle / wettbewerb / PL1?saison_id = 2018 & min = 1 & max = 20
|
||||
# wartość klubów
|
||||
# https: // www.transfermarkt.pl / pko - ekstraklasa / marktwerteverein / wettbewerb / PL1 / plus /?stichtag = 2018 - 10 - 01
|
||||
# Poprzedni sezon
|
||||
# https://www.transfermarkt.pl/pko-ekstraklasa/tabelle/wettbewerb/PL1?saison_id=2017
|
||||
def scrapTeamValue(self):
|
||||
url = 'https://www.transfermarkt.pl/pko-ekstraklasa/marktwerteverein/wettbewerb/PL1/plus/?stichtag=2018-10-01'
|
||||
headers = {'User-Agent': 'Mozilla/5.0'}
|
||||
req = requests.get(url, headers=headers)
|
||||
soup = BeautifulSoup(req.text, 'html.parser')
|
||||
body = soup.body
|
||||
return body
|
||||
|
||||
def scrapTeamValue(self):
|
||||
body = self.fetch_data('https://www.transfermarkt.pl/pko-ekstraklasa/marktwerteverein/wettbewerb/PL1/stichtag//plus/1')
|
||||
table = body.find('table', {'class': 'items'})
|
||||
bodyTable = table.find('tbody')
|
||||
values = bodyTable.findAll('td', {'class': 'rechts hauptlink'})
|
||||
values = bodyTable.findAll('td', {'class': 'rechts'})
|
||||
teamValues = []
|
||||
teams = []
|
||||
for value in values:
|
||||
@ -28,38 +36,44 @@ class scrap:
|
||||
num = value.text.replace(',','.')
|
||||
num = re.match(r'[0-9]+[.][0-9]+',num)
|
||||
teamValues.append(float(num.group()))
|
||||
teams = list(OrderedDict.fromkeys(teams))
|
||||
dictTeams = {}
|
||||
i=0
|
||||
for team in teams:
|
||||
dictTeams[team] = teamValues[i]
|
||||
i += 1
|
||||
|
||||
i += 2
|
||||
return dictTeams
|
||||
|
||||
def scrapTeamsTable(self):
|
||||
body = self.fetch_data('https://www.transfermarkt.pl/pko-ekstraklasa/tabelle/wettbewerb/PL1?saison_id=2019')
|
||||
table = body.find('div', {'class': 'responsive-table'})
|
||||
bodyTable = table.find('tbody')
|
||||
trTable = bodyTable.findAll('tr')
|
||||
url = 'https://www.transfermarkt.pl/ekstraklasa/formtabelle/wettbewerb/PL1?saison_id=2017&min=1&max=10'
|
||||
headers = {'User-Agent': 'Mozilla/5.0'}
|
||||
req = requests.get(url, headers=headers)
|
||||
soup = BeautifulSoup(req.text, 'html.parser')
|
||||
body = soup.body
|
||||
body = body.find('div', {'class': 'large-8 columns'})
|
||||
table = body.findAll('div', {'class': 'responsive-table'})
|
||||
i = 1
|
||||
listTeams = []
|
||||
listProperities = []
|
||||
for item in trTable:
|
||||
item = item.text.replace(u'\xa0', '')
|
||||
teamProperities = re.split('\n', item)
|
||||
tab = []
|
||||
|
||||
for x in teamProperities:
|
||||
match = re.match(r'-?[0-9]+', x)
|
||||
if match:
|
||||
tab.append(float(match.group()))
|
||||
|
||||
match = re.match(r'\D+$', x)
|
||||
if match:
|
||||
teamName = match.group().rstrip()
|
||||
|
||||
listTeams.append(teamName)
|
||||
listProperities.append(tab)
|
||||
for x in table:
|
||||
x = x.find('tbody')
|
||||
trTable = x.findAll('tr')
|
||||
for item in trTable:
|
||||
item = item.text.replace(u'\xa0', '')
|
||||
teamProperities = re.split('\n', item)
|
||||
tab = []
|
||||
for x in teamProperities:
|
||||
match = re.match(r'-?[0-9]+', x)
|
||||
if match:
|
||||
tab.append(float(match.group()))
|
||||
|
||||
match = re.match(r'\D+$', x)
|
||||
if match:
|
||||
teamName = match.group().rstrip()
|
||||
tab[0] = i
|
||||
i+=1
|
||||
listTeams.append(teamName)
|
||||
listProperities.append(tab)
|
||||
dictTeams = {}
|
||||
i=0
|
||||
for team in listTeams:
|
||||
@ -69,7 +83,11 @@ class scrap:
|
||||
return dictTeams
|
||||
|
||||
def scrapPreviousPlace(self):
|
||||
body = self.fetch_data('https://www.transfermarkt.pl/pko-ekstraklasa/tabelle/wettbewerb/PL1?saison_id=2018')
|
||||
url = 'https://www.transfermarkt.pl/pko-ekstraklasa/tabelle/wettbewerb/PL1?saison_id=2016'
|
||||
headers = {'User-Agent': 'Mozilla/5.0'}
|
||||
req = requests.get(url, headers=headers)
|
||||
soup = BeautifulSoup(req.text, 'html.parser')
|
||||
body = soup.body
|
||||
table = body.findAll('div', {'class': 'responsive-table'})
|
||||
listTeams = []
|
||||
i = 0
|
||||
@ -84,6 +102,5 @@ class scrap:
|
||||
for team in listTeams:
|
||||
dictTeams[team] = i
|
||||
i += 1
|
||||
|
||||
return dictTeams
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user