forked from ho-dev/HattrickOrganizer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateRequiredLineupJson.py
More file actions
85 lines (65 loc) · 2.9 KB
/
createRequiredLineupJson.py
File metadata and controls
85 lines (65 loc) · 2.9 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
72
73
74
75
76
77
78
79
80
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): #TODO: put correct data
NORMAL = 0
OFFENSIVE = 1
DEFENSIVE = 2
TOWARDS_MIDDLE = 3
TOWARDS_WING = 4
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 createJson(lineupName, requiredLineup, attitude, tactic):
validateLineup(requiredLineup)
json_data = {}
lineup = {}
for position, order, bPresent in requiredLineup:
if bPresent:
lineup[str(position.value)] = order.value
json_data["lineupName"] = lineupName
json_data["lineup"] = lineup
json_data["attitude"] = attitude
json_data["tatic"] = tactic
# with open(r"D:\TEMP\feedback.json", "w") as write_file:
# json.dump(json_data, write_file, indent=4)
with open(r"docs/feedback.json", "w") as write_file:
json.dump(json_data, write_file, indent=4)
requiredLineup = []
requiredLineup.append((Position.GK, MatchOrder.NORMAL, True))
requiredLineup.append((Position.WBr, MatchOrder.DEFENSIVE, False))
requiredLineup.append((Position.WIl, MatchOrder.TOWARDS_MIDDLE, False))
requiredLineup.append((Position.FWl, MatchOrder.TOWARDS_WING, False))
createJson("GK", requiredLineup, "Normal", "Normal")