TeamRating/main.py

86 lines
3.1 KiB
Python

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, 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(5)
prevPlace['Low'] = fuzz.trimf(prevPlace.universe, [12,16,16])
prevPlace['Medium'] = fuzz.trimf(prevPlace.universe, [5,8,13])
prevPlace['High'] = fuzz.trimf(prevPlace.universe, [0,0,6])
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, [12,16,16])
currentPlace['Medium'] = fuzz.trimf(currentPlace.universe, [5,8,13])
currentPlace['High'] = fuzz.trimf(currentPlace.universe, [0,0,6])
points['Low'] = fuzz.trimf(points.universe, [0,0, 1.2])
points['Medium'] = fuzz.trimf(points.universe, [1.0,1.4, 1.8])
points['High'] = fuzz.trimf(points.universe, [1.7,2.2,2.2])
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])
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)
calculate = calculating()
calculate.cleanTeamParameters()
dict = calculate.joinDict()
teamsPlace = {}
for key in dict:
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['prevPlace'] = dict[key][3]
# calPlace.input['prevPlace'] = dict[key][4]
calPlace.compute()
# 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]))