Skip to content

Commit

Permalink
Use the new match data in match history
Browse files Browse the repository at this point in the history
Stop passing in the UI object
Adjust match data to work with match history

Signed-off-by: Ethan Henderson <[email protected]>
  • Loading branch information
zbee committed Oct 13, 2023
1 parent 19698d9 commit d09d78e
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 591 deletions.
1 change: 1 addition & 0 deletions hinter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import hinter.users
from hinter.ui.menu import UIMenus
from hinter.background.match_data import MatchData as MatchData
from hinter.background.match_data import GameReturn as GameData
from hinter.match_breakdown import MatchBreakdown as MatchBreakdown

# TODO: Move MatchHistory here
Expand Down
94 changes: 72 additions & 22 deletions hinter/background/match_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import hinter


# Does not support Arena
class GameReturn(TypedDict, total=False):
match_id: Required[int]
map_id: Required[int]
Expand All @@ -28,7 +27,7 @@ class GameReturn(TypedDict, total=False):
teams_bans: Required[list[list[str]]] # List of lists as it's split by team from here on
teams_background_colors: Required[list[list[int]]]
players_summoner_spells: Required[list[list[list[str]]]]
players_roles: Required[list[list[cassiopeia.data.Lane]]]
players_roles: Required[list[list[str]]]
players_kdas: Required[list[list[str]]]
players_k_d_as: Required[list[list[str]]]
players_kps: Required[list[list[str]]]
Expand All @@ -50,9 +49,9 @@ class GameReturn(TypedDict, total=False):
team_kills: int
team_damage: int
outcome: str
background_color: list[float]
background_color: list[int]
summoner_spells: list[str]
role: cassiopeia.data.Lane
role: str
kda: str
k_d_a: str
damage: str
Expand All @@ -73,7 +72,6 @@ class GameReturn(TypedDict, total=False):
class MatchData:
# Static data
_ = None
naught = 0.000000001

# Public data
match: GameReturn
Expand All @@ -95,6 +93,7 @@ class MatchData:
_players_cs_per_min_values: Union[list[list[str]], None]
_players_secondary_rune_trees_values: Union[list[list[str]], None]
_players_runes_values: Union[list[list[list[str]]], None]

# endregion Data generated by their superseding properties

def __init__(self, game: int, user: str = None):
Expand Down Expand Up @@ -354,13 +353,17 @@ def _teams_outcomes(self) -> list[str]:
teams_outcomes[team] = 'Defeat'
background_colors[team] = hinter.data.constants.MATCH_COLOR_LOSS

self._teams_background_colors_values = background_colors
return teams_outcomes

# noinspection DuplicatedCode
@cached_property
def _teams_bans(self) -> list[list[str]]:
teams_bans = [[], []]

if self._queue == 'Arena' or self._queue == 'ARAM':
return [[''], ['']]

for ban in self._match.blue_team.bans:
if ban is None:
teams_bans[self.blue_team].append(
Expand Down Expand Up @@ -417,6 +420,13 @@ def _players_summoner_spells(self) -> list[list[list[str]]]:

for team, players in enumerate(self._players):
for player in players:
if self._queue == 'Arena':
players_summoner_spells[team].append([
hinter.UI.filler_image,
hinter.UI.filler_image,
])
continue

players_summoner_spells[team].append([
hinter.UI.load_image(
f'spell-{player.summoner_spell_d.name}',
Expand All @@ -436,7 +446,15 @@ def _players_summoner_spells(self) -> list[list[list[str]]]:

# noinspection DuplicatedCode
@cached_property
def _players_roles(self) -> list[list[cassiopeia.data.Lane]]:
def _players_roles(self) -> list[list[str]]:
renaming_roles = {
cassiopeia.data.Lane.top_lane: 'Top',
cassiopeia.data.Lane.jungle: 'Jungle',
cassiopeia.data.Lane.mid_lane: 'Mid',
cassiopeia.data.Lane.bot_lane: 'Bot',
cassiopeia.data.Lane.utility: 'Support',
}

champion_order = [[], []]
players_roles = [
[self._, self._, self._, self._, self._],
Expand All @@ -450,6 +468,14 @@ def _players_roles(self) -> list[list[cassiopeia.data.Lane]]:
for player in players:
champion_order[team].append(player.champion.id)

# Short-circuit for Arena and ARAM
if self._queue == 'Arena' or self._queue == 'ARAM':
for team, players in enumerate(self._players):
for key, _ in enumerate(players):
# noinspection PyTypeChecker
players_roles[team][key] = ''
return players_roles

# Then get the roles for each champion on blue team
blue_team_roles = cassiopeia_role_identification.get_team_roles(
self._match.blue_team,
Expand All @@ -458,7 +484,7 @@ def _players_roles(self) -> list[list[cassiopeia.data.Lane]]:
for position, champion in blue_team_roles.items():
order = champion_order[self.blue_team].index(champion.id)
lane = cassiopeia.data.Lane.from_match_naming_scheme(position.name.upper())
players_roles[self.blue_team][order] = lane
players_roles[self.blue_team][order] = renaming_roles[lane]

# Do the sam for red team
red_team_roles = cassiopeia_role_identification.get_team_roles(
Expand All @@ -468,7 +494,7 @@ def _players_roles(self) -> list[list[cassiopeia.data.Lane]]:
for position, champion in red_team_roles.items():
order = champion_order[self.red_team].index(champion.id)
lane = cassiopeia.data.Lane.from_match_naming_scheme(position.name.upper())
players_roles[self.red_team][order] = lane
players_roles[self.red_team][order] = renaming_roles[lane]

return players_roles

Expand All @@ -486,14 +512,22 @@ def _players_kdas(self) -> list[list[str]]:

for team, players in enumerate(self._players):
for player in players:
kda = (player.stats.kills + player.stats.assists) / (player.stats.deaths + self.naught)
if player.stats.deaths == 0:
kda = player.stats.kills + player.stats.assists
else:
kda = (player.stats.kills + player.stats.assists) / player.stats.deaths
players_kdas[team].append(
f'{kda:.1f}'
)

players_k_d_as[team].append(
f'{player.stats.kills} / {player.stats.deaths} / {player.stats.assists}'
)
kp = int(round((player.stats.kills + player.stats.assists) / (teams_kills[team] + self.naught), 0))

if teams_kills[team] == 0:
kp = 0
else:
kp = int(round((player.stats.kills + player.stats.assists) / teams_kills[team], 0))
players_kps[team].append(f'{kp}%')

self._players_k_d_as_values = players_k_d_as
Expand Down Expand Up @@ -531,13 +565,21 @@ def _players_damage(self) -> list[list[str]]:
for team, players in enumerate(self._players):
for player in players:
players_damage[team].append(f'{player.stats.total_damage_dealt_to_champions:,} Dmg')
damage_of_team = int(round(
player.stats.total_damage_dealt_to_champions / (teams_damage[team] + self.naught),
0))

if teams_damage[team] == 0:
damage_of_team = 0
else:
damage_of_team = int(round(
player.stats.total_damage_dealt_to_champions / teams_damage[team],
0))
players_damage_of_team[team].append(f'{damage_of_team:,}%')
damage_per_min = int(round(
player.stats.total_damage_dealt_to_champions / (self._match_minutes + self.naught),
0))

if self._match_minutes == 0:
damage_per_min = player.stats.total_damage_dealt_to_champions
else:
damage_per_min = int(round(
player.stats.total_damage_dealt_to_champions / self._match_minutes,
0))
players_damage_per_min[team].append(f'{damage_per_min:,} Dmg/min')

self._players_damage_of_team_values = players_damage
Expand Down Expand Up @@ -569,7 +611,11 @@ def _players_vision(self) -> list[list[str]]:
for team, players in enumerate(self._players):
for player in players:
players_vision[team].append(f'{player.stats.vision_score} Vis')
vision_per_min = int(round(player.stats.vision_score / (self._match_minutes + self.naught), 0))

if self._match_minutes == 0:
vision_per_min = player.stats.vision_score
else:
vision_per_min = int(round(player.stats.vision_score / self._match_minutes, 0))
players_vision_per_min[team].append(f'{vision_per_min:,} Vis/min')

self._players_vision_per_min_values = players_vision_per_min
Expand All @@ -592,7 +638,11 @@ def _players_cs(self) -> list[list[str]]:
for team, players in enumerate(self._players):
for player in players:
players_cs[team].append(f'{player.stats.total_minions_killed} CS')
cs_per_min = round(player.stats.total_minions_killed / (self._match_minutes + self.naught), 1)

if self._match_minutes == 0:
cs_per_min = player.stats.total_minions_killed
else:
cs_per_min = round(player.stats.total_minions_killed / self._match_minutes, 1)
players_cs_per_min[team].append(f'{cs_per_min} CS/min')

self._players_cs_per_min_values = players_cs_per_min
Expand Down Expand Up @@ -677,7 +727,7 @@ def _players_key_runes(self) -> Union[list[list[str]], None]:
]
]

if self._queue == 'ARENA':
if self._queue == 'Arena':
return None

for team, players in enumerate(self._players):
Expand Down Expand Up @@ -714,8 +764,8 @@ def _players_key_runes(self) -> Union[list[list[str]], None]:
hinter.UI.load_image(
f'rune-{rune.path.name}',
hinter.data.constants.IMAGE_TYPE_PIL,
rune.path.image,
size=hinter.data.constants.ICON_SIZE_RUNE,
rune.path,
size=hinter.data.constants.ICON_SIZE_SECONDARY_RUNE,
))

self._players_secondary_rune_trees_values = players_secondary_rune_trees
Expand All @@ -724,7 +774,7 @@ def _players_key_runes(self) -> Union[list[list[str]], None]:

@cached_property
def _players_secondary_rune_trees(self) -> Union[list[list[str]], None]:
if self._queue == 'ARENA':
if self._queue == 'Arena':
return None

if self._players_secondary_rune_trees_values is None:
Expand Down
2 changes: 1 addition & 1 deletion hinter/match_history/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def show_match_screen(self, render: bool = True):
with hinter.imgui.table_row(tag='match_history-friends-ref'):
hinter.imgui.add_spacer()

MatchDisplay.show_friends_played_with(self.ui, 'cached')
MatchDisplay.show_friends_played_with('cached')
# endregion Left Bar

# region Center (Match History container)
Expand Down
Loading

0 comments on commit d09d78e

Please sign in to comment.