forked from ho-dev/HattrickOrganizer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreateRequiredLineupJson.py
145 lines (125 loc) · 4.88 KB
/
createRequiredLineupJson.py
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
from enum import Enum
import json
class Position(Enum):
GK = 100
WBr = 101
CDr = 102
CD = 103
CDl = 104
WBl = 105
WIr = 106
IMr = 107
IM = 108
IMl = 109
WIl = 110
FWr = 111
FW = 112
FWl = 113
class MatchOrder(Enum):
NORMAL = 0
OFFENSIVE = 1
DEFENSIVE = 2
TOWARDS_MIDDLE = 3
TOWARDS_WING = 4
class Attitute(Enum):
NORMAL = "normal"
PIC = "playitcool"
MOTS = "matchoftheseason"
class Tactic(Enum):
NORMAL = "normal"
PRESSING = "pressing"
CA = "counter-attacks"
AIM = "attackinthemiddle"
AOW = "attackonwings"
PC = "playcreatively"
LS = "longshots"
class bcolors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
def validateLineup(requiredLineup):
for position, order, bPresent in requiredLineup:
if bPresent:
if position == Position.GK:
assert order == MatchOrder.NORMAL, f"{position} can't receive {order} order"
elif position in [Position.WBr, Position.WBl, Position.WIr, Position.WIl]:
assert order != MatchOrder.TOWARDS_WING, f"{position} can't receive {order} order"
elif position in [Position.CDr, Position.CDl]:
assert order in [MatchOrder.NORMAL, MatchOrder.TOWARDS_WING,
MatchOrder.OFFENSIVE], f"{position} can't receive {order} order"
elif position == Position.CD:
assert order in [MatchOrder.NORMAL, MatchOrder.OFFENSIVE], f"{position} can't receive {order} order"
elif position in [Position.IMr, Position.IMl]:
assert order != MatchOrder.TOWARDS_MIDDLE, f"{position} can't receive {order} order"
elif position == Position.IM:
assert order in [MatchOrder.NORMAL, MatchOrder.OFFENSIVE,
MatchOrder.DEFENSIVE], f"{position} can't receive {order} order"
elif position in [Position.FWl, Position.FWr]:
assert order in [MatchOrder.NORMAL, MatchOrder.TOWARDS_WING,
MatchOrder.DEFENSIVE], f"{position} can't receive {order} order"
elif position == Position.FW:
assert order in [MatchOrder.NORMAL, MatchOrder.DEFENSIVE], f"{position} can't receive {order} order"
else:
raise ValueError(f"position {position} is not yet handled")
def validate_answer(_answer):
try:
_answer = _answer.lower()
except:
print("Answer was not understood")
return None
if (_answer == 'y') or (_answer == "yes"):
return "yes"
elif (_answer == 'no') or (_answer == 'no'):
return "no"
else:
print("Answer was not understood")
return None
def createJson(lineupName, requiredLineup, attitude, tactic, bPRODUCTION, bServerUP):
attitude, tactic = attitude.value, tactic.value
validateLineup(requiredLineup)
json_data = {}
lineup = {}
for position, order, bPresent in requiredLineup:
if bPresent:
lineup[str(position.value)] = order.value
if bServerUP:
serverStatus = "up"
else:
serverStatus = "down"
json_data["server_status"] = serverStatus
json_data["lineupName"] = lineupName
json_data["lineup"] = lineup
json_data["attitude"] = attitude
json_data["tactic"] = tactic
path = r"D:\TEMP\feedback.json"
answer = None
if not bPRODUCTION:
while (answer != "yes" and answer != "no"):
answer = input("Pushing to " + bcolors.OKGREEN + "TEST" + bcolors.ENDC + ", do you want to continue, (y)es / (n)o ? ")
answer = validate_answer(answer)
else:
while (answer != "yes" and answer != "no"):
answer = input("Pushing to " + bcolors.WARNING + "PRODUCTION" + bcolors.ENDC + ", do you want to continue, (y)es / (n)o ? ")
answer = validate_answer(answer)
if answer == "yes":
if bPRODUCTION:
path = r"docs/feedback.json"
with open(path, "w") as write_file:
json.dump(json_data, write_file, indent=4)
#single GK ================================================================================
lineupName = "GK"
attitude = Attitute.NORMAL
tactic = Tactic.NORMAL
requiredLineup = []
requiredLineup.append((Position.GK, MatchOrder.NORMAL, True))
# ================================================================================
# requiredLineup.append((Position.CD, MatchOrder.NORMAL, True)) // "CDc-Normal"
# requiredLineup.append((Position.WBr, MatchOrder.DEFENSIVE, False))
# requiredLineup.append((Position.WIl, MatchOrder.TOWARDS_MIDDLE, False))
# requiredLineup.append((Position.FWl, MatchOrder.TOWARDS_WING, False))
createJson(lineupName, requiredLineup, attitude, tactic, bPRODUCTION=True, bServerUP=True)