-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSaltyParser.py
149 lines (127 loc) · 5.84 KB
/
SaltyParser.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
146
147
148
149
import webbrowser
from tabulate import tabulate
class SaltyJsonParser():
def __init__(self, json_dict):
self.json_dict = json_dict
self.remaining = self.json_dict["remaining"]
self.alert = self.json_dict["alert"]
self.start_time = 0
def get_p1name(self):
return self.json_dict['p1name']
def get_p2name(self):
return self.json_dict['p2name']
def get_p1total(self):
p1total = self.json_dict['p1total']
return int(p1total.replace(',', ''))
def get_p2total(self):
p2total = self.json_dict['p2total']
return int(p2total.replace(',', ''))
def get_gamestate(self):
json_status = self.json_dict["status"]
if json_status not in ['open', 'locked', '1', '2']:
print(f"Traditional gamestate not found. Gamestate = {json_status}")
return json_status
def set_p1winstatus(self):
if self.get_gamestate() == "1":
return 1
else:
return 0
def set_p2winstatus(self):
if self.get_gamestate() == "2":
return 1
else:
return 0
def is_exhib(self):
"""
Determine if the current mode is exhibition mode based on alert or remaining messages.
Returns:
bool: True if the mode is exhibition, otherwise False.
"""
return (
self.alert == "Exhibition mode start!" or
self.remaining.endswith("exhibition matches left!") or
self.remaining.startswith("Matchmaking mode will be activated after the next")
)
def is_tourney(self):
"""
Determine if the current game is in tournament mode.
Returns:
int: 1 if the game is in tournament mode, 0 otherwise.
"""
return int(any([
self.alert == "Tournament mode start!",
self.remaining.endswith("in the bracket!"),
self.remaining.startswith("FINAL ROUND!"),
not self.remaining.endswith("next tournament!") and not self.remaining.startswith(
"Tournament mode will be activated after the next")
]))
def get_tourney_remaining(self):
if self.get_matches_remaining() != 1:
self.tourney_remaining = self.get_matches_remaining() - 1
elif self.get_matches_remaining() == 1:
self.tourney_remaining = self.get_matches_remaining()
else:
self.tourney_remaining = 0
return self.tourney_remaining
def get_matches_remaining(self):
"""
Determine the number of matches remaining based on the 'remaining' attribute.
Returns:
int: The number of matches remaining or 1 for known lines.
"""
known_lines = [
"Tournament mode will be activated after the next",
"Matchmaking mode will be activated after the next",
"FINAL ROUND!",
]
for known_line in known_lines:
if self.remaining.startswith(known_line):
return 1
remaining_value = self.remaining.split(' ', 1)[0]
if remaining_value.isdigit():
return int(remaining_value)
else:
print(f"Couldn't retrieve number of matches from: {self.remaining}")
def get_p1odds(self):
if self.get_p1total() > self.get_p2total():
return round(self.get_p1total() / self.get_p2total(), 1)
elif self.get_p1total() < self.get_p2total():
return float(1)
def get_p2odds(self):
if self.get_p1total() > self.get_p2total():
return float(1)
elif self.get_p1total() < self.get_p2total():
return round(self.get_p2total() / self.get_p1total(), 1)
def get_gamemode(self):
if self.is_exhib() is True:
return 'Exhibition'
elif self.is_tourney() == 1:
return 'Tournament'
elif (self.is_exhib() is False) and (self.is_tourney() == 0):
return 'Matchmaking'
else:
print(f"Unable to parse Game Mode. {self.json_dict}")
return 'Unknown'
def gamemode_printer(self, p1name, p2name, p1DB_odds, p2DB_odds, p1DB_ratings, p2DB_ratings, p1DB_streak,
p2DB_streak, p1_probability, balance):
table = [[p1name, p1DB_ratings.mu, p1DB_ratings.sigma, p1DB_streak, p1DB_odds],
[p2name, p2DB_ratings.mu, p2DB_ratings.sigma, p2DB_streak, p2DB_odds]]
if self.get_gamemode() == "Tournament":
print(
f"Currently in {self.get_gamemode()} with {self.get_tourney_remaining()} matches remaining. Game state is {self.get_gamestate()}.")
if self.get_gamestate() == "open":
print(tabulate(table, headers=["Fighter", "Skill", "Variation", "Streak", "Odds Avg"],
colalign=("center",), tablefmt="grid", stralign="center", numalign="center"))
print(f"Player 1 chance to win: {round(100 * p1_probability, 2)}%")
print(f"Current Balance is: ${balance:,}")
elif self.get_gamemode() == "Matchmaking":
print(
f"Currently in {self.get_gamemode()} with {self.get_matches_remaining()} matches remaining. Game state is {self.get_gamestate()}.")
if self.get_gamestate() == "open":
print(tabulate(table, headers=["Fighter", "Skill", "Variation", "Streak", "Odds Avg"],
colalign=("center",), tablefmt="grid", stralign="center", numalign="center"))
print(f"Player 1 chance to win: {round(100 * p1_probability, 2)}%")
print(f"Current Balance is: ${balance:,}")
elif self.get_gamemode() == "Exhibition":
print(
f"No bets are placed, and nothing is recorded in Exhibitions. {self.get_matches_remaining()} matches remaining. Game state is {self.get_gamestate()}")