-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplayer.py
More file actions
71 lines (61 loc) · 3.06 KB
/
player.py
File metadata and controls
71 lines (61 loc) · 3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import random
from typing import Dict, List
from zone import Zone
class Player:
def __init__(self, name, team, features , role , position: Zone, current_position : Zone, ballposition: bool):
self.name = name
self.role = role
self.features = features
self.position = position
self.current_position = current_position
self.team = team
self.ballposition = ballposition
normalized_data = self.load_and_normalize_data_from_json()
self.attributes_score = self.compute_attributes_score_from_data(normalized_data)
def check_null_values(self, features: List[str]):
for i in features:
if i not in self.features:
self.features[i] = random.randint(20, 45)
def load_and_normalize_data_from_json(self):
normalized_data = {}
# if self.role != "G":
self.check_null_values(['attack',
'creativity',
'defending',
'tactical',
'technical'])
normalized_data['attack'] = float(self.features['attack'])/100
normalized_data['creativity'] = float(self.features['creativity'])/100
normalized_data['defending'] = float(self.features['defending'])/100
normalized_data['tactical'] = float(self.features['tactical'])/100
normalized_data['technical'] = float(self.features['technical'])/100
if self.role == 'G':
self.check_null_values([
'aerial',
'anticipation',
'ballDistribution',
'saves',
'tactical'])
normalized_data['aerial'] = float(self.features['aerial'])/100
normalized_data['anticipation'] = float(self.features['anticipation'])/100
normalized_data['ballDistribution'] = float(self.features['ballDistribution'])/100
normalized_data['saves'] = float(self.features['saves'])/100
normalized_data['tactical'] = float(self.features['tactical'])/100
return normalized_data
def compute_attributes_score_from_data(self, data: Dict[str, float]):
attributes_score = {}
if self.role != "G":
attributes_score['Pass'] = data['tactical'] * data['technical'] * data['creativity']
attributes_score['Shoot'] = data['attack'] * data['technical']
attributes_score['Entry'] = data['defending'] * data['technical']
# attributes_score['Entry'] = 0
attributes_score['Move'] = data['tactical'] * data['technical']
attributes_score['Intercept'] = data['defending'] * data['tactical'] * data['creativity']
else:
attributes_score['Defend'] = sum(data.values()) / len(data)
attributes_score['Pass'] = data['tactical'] * data['ballDistribution']
attributes_score['Shoot'] = 0.05
attributes_score['Entry'] = 0.05
attributes_score['Move'] = 0
attributes_score['Intercept'] = 0.1
return attributes_score