Skip to content

Commit 4c4b005

Browse files
committed
Add rank display
1 parent 8eade94 commit 4c4b005

51 files changed

Lines changed: 448 additions & 103 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/dota_notes/data/states/game_state.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,12 @@ def enrich_players_with_stratz_info(self, json):
157157
if f"p{player.steam_id}" in json["data"]:
158158
extra_info = json["data"][f"p{player.steam_id}"]
159159

160+
if ("performance" in extra_info and extra_info["performance"] is not None
161+
and "rank" in extra_info["performance"] and extra_info["performance"]["rank"] is not None
162+
and isinstance(extra_info["performance"]["rank"], int)):
163+
player.medal = extra_info["performance"]["rank"]
164+
else:
165+
player.medal = 0
160166
if "matchCount" in extra_info and extra_info["matchCount"] is not None:
161167
player.match_count = extra_info["matchCount"]
162168
if "steamAccount" in extra_info and extra_info["steamAccount"] is not None:

src/dota_notes/data/states/player_state.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ class PlayerState(QObject):
66
steam_id = 0
77
avatar = ""
88
account_level = None
9+
medal = None
910
country_code = ""
1011
name = ""
1112
pro_name = None
@@ -21,10 +22,9 @@ class PlayerState(QObject):
2122
destroys_items = False
2223
note = ""
2324

24-
ATTRIBUTES_FOR_COPY = ["steam_id", "avatar", "account_level", "country_code",
25+
ATTRIBUTES_FOR_COPY = ["steam_id", "avatar", "account_level", "medal", "country_code",
2526
"pro_name", "custom_name", "match_count", "smurf", "smurf_stratz",
26-
"is_racist",
27-
"is_sexist", "is_toxic", "is_feeder", "gives_up", "destroys_items", "note"]
27+
"is_racist", "is_sexist", "is_toxic", "is_feeder", "gives_up", "destroys_items", "note"]
2828

2929
def copy_from(self, from_object):
3030
"""Copy attributes from another object into this
@@ -55,6 +55,8 @@ def enrich_with_stratz_account_info(self, account):
5555
self.name = account["name"]
5656
else:
5757
self.name = "< HIDDEN ACCOUNT >"
58+
if "isAnonymous" in account and isinstance(account["isAnonymous"], bool) and account["isAnonymous"]:
59+
self.medal = 0
5860

5961
if "proSteamAccount" in account and account["proSteamAccount"] is not None:
6062
pro_steam_account = account["proSteamAccount"]

src/dota_notes/helpers.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ def get_steam_live_game_stats(api_key, server_id):
2222
print(f"Error occurred while fetching data: {e}")
2323
return None
2424

25+
2526
def exec_stratz_graphql_query(token: str, query: str):
2627
"""Execute a graphql query on stratz endpoint.
2728
@@ -62,9 +63,13 @@ def stratz_get_players_info(token: str, players: list[int]):
6263
full_query = f"""fragment playerProfile on PlayerType {{
6364
steamAccountId
6465
matchCount
66+
performance {{
67+
rank
68+
}}
6569
steamAccount {{
6670
avatar
6771
name
72+
isAnonymous
6873
dotaAccountLevel
6974
smurfFlag
7075
countryCode
@@ -147,6 +152,7 @@ def stratz_get_live_game(token: str, match_id: int):
147152
}}
148153
countryCode
149154
name
155+
isAnonymous
150156
}}
151157
}}
152158
}}

src/dota_notes/ui/app_qt.py

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,24 @@
1818

1919

2020
class QtApp:
21-
"""Qt application process"""
21+
"""Qt application process
22+
23+
Attributes
24+
dota_notes: link to the main object of the application
25+
app: QT app
26+
window: QT Main window of the application
27+
last_selected_index: index of the last selected player
28+
last_selected_player: data of the last selected player
29+
"""
2230

2331
def __init__(self, dota_notes):
2432
self.dota_notes = dota_notes
2533

2634
# Build Qt app components
2735
self.app = QApplication(sys.argv)
2836
self.window = MainWindow()
29-
self.lastSelectedIndex = 0
30-
self.lastSelectedState = None
37+
self.last_selected_index = 0
38+
self.last_selected_player = None
3139

3240
# Connect actions
3341
self.window.actionSettings.triggered.connect(self.on_open_settings)
@@ -60,6 +68,7 @@ def __init__(self, dota_notes):
6068
self.window.show()
6169

6270
def run(self):
71+
"""Start the QT application, enter the event loop and add a periodic dequeue of messages"""
6372
timer = QTimer()
6473
timer.timeout.connect(self.process_queues)
6574
timer.start(100)
@@ -68,6 +77,7 @@ def run(self):
6877
return return_code
6978

7079
def process_queues(self):
80+
"""Periodic process that checks message queues and process necessary jobs"""
7181
while not self.dota_notes.message_queue_qt.empty():
7282
message = self.dota_notes.message_queue_qt.get(block=False)
7383
if isinstance(message, MessageGSI):
@@ -90,6 +100,7 @@ def process_queues(self):
90100
self.window.draw_status_message("No game found for player " + self.window.inputSteamId.text())
91101

92102
def on_open_settings(self):
103+
"""User opens the settings panel"""
93104
settings = self.dota_notes.settings
94105
self.window.comboBoxSettingsMode.setCurrentText(settings.software_mode)
95106
self.window.lineEditStratzToken.setText(settings.stratz_token)
@@ -99,6 +110,7 @@ def on_open_settings(self):
99110
self.window.centralStackedWidget.setCurrentIndex(1)
100111

101112
def on_settings_save(self):
113+
"""User saves settings modifications"""
102114
settings = self.dota_notes.settings
103115
settings.software_mode = self.window.comboBoxSettingsMode.currentText()
104116
settings.stratz_token = self.window.lineEditStratzToken.text()
@@ -111,30 +123,36 @@ def on_settings_save(self):
111123
self.window.centralStackedWidget.setCurrentIndex(0)
112124

113125
def on_settings_cancel(self):
126+
"""User cancels settings modifications"""
114127
self.window.centralStackedWidget.setCurrentIndex(0)
115128

116129
def on_connect_client(self):
130+
"""User clicks on connect button"""
117131
self.window.buttonConnect.setVisible(False)
118132
message = MessageConnect(self.dota_notes.settings.steam_user, self.dota_notes.settings.steam_password)
119133
self.dota_notes.message_queue_dota.put(message)
120134

121135
def on_disconnect_client(self):
136+
"""User clicks on disconnect button"""
122137
message = MessageDisconnect()
123138
self.dota_notes.message_queue_dota.put(message)
124139

125140
def on_label_click(self, label_name, label_text):
141+
"""User clicks on a specific label"""
126142
row = 0
127143
for char in label_name:
128144
if char.isdigit():
129145
row = int(char)
130146
self.on_select_player(row)
131147

132148
def on_select_player(self, player_slot):
133-
self.lastSelectedIndex = player_slot
134-
self.lastSelectedState = self.dota_notes.state.players[player_slot]
135-
self.window.draw_details_with_player(self.lastSelectedState)
149+
"""User select a player to have info off"""
150+
self.last_selected_index = player_slot
151+
self.last_selected_player = self.dota_notes.state.players[player_slot]
152+
self.window.draw_details_with_player(self.last_selected_player)
136153

137154
def on_steam_live(self):
155+
"""Look for a live game a player is in"""
138156
steam_id = self.window.inputSteamId.text()
139157
if self.is_valid_search(steam_id):
140158
steam_id = SteamID(steam_id)
@@ -204,13 +222,14 @@ def on_stratz_info(self):
204222
if json is not None:
205223
self.dota_notes.state.enrich_players_with_stratz_info(json)
206224
self.window.draw_match_with_state(self.dota_notes.state)
207-
self.on_select_player(self.lastSelectedIndex)
225+
self.on_select_player(self.last_selected_index)
208226
self.window.draw_status_message("Updated player with Stratz info.")
209227
else:
210228
self.window.draw_status_message("Error while fetching player info from Stratz.")
211229

212230
def on_save_player_details(self):
213-
player_state = self.lastSelectedState
231+
"""User press 'save' on the player detail page"""
232+
player_state = self.last_selected_player
214233
player_state.custom_name = self.window.inputDetailsCustomName.text()
215234
player_state.smurf = self.window.comboBoxDetailsSmurf.currentText()
216235
player_state.is_racist = self.window.checkBoxDetailsRacist.isChecked()
@@ -220,7 +239,7 @@ def on_save_player_details(self):
220239
player_state.gives_up = self.window.checkBoxDetailsGivesUp.isChecked()
221240
player_state.destroys_items = self.window.checkBoxDetailsDestroysItems.isChecked()
222241
player_state.note = self.window.inputDetailsNote.toPlainText()
223-
self.window.draw_match_player(self.lastSelectedIndex, player_state)
242+
self.window.draw_match_player(self.last_selected_index, player_state)
224243
with Session(self.dota_notes.database.engine) as session:
225244
player_info = session.get(PlayerEntity, str(player_state.steam_id))
226245
if player_info is None:
30 KB
22.1 KB
25 KB
26 KB
27.3 KB
28.8 KB

0 commit comments

Comments
 (0)