Skip to content

Commit

Permalink
Base of new, more structured game data handling
Browse files Browse the repository at this point in the history
Signed-off-by: Ethan Henderson <ethan@zbee.codes>
  • Loading branch information
zbee committed Oct 11, 2023
1 parent 7b2f81f commit 22908ef
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 11 deletions.
14 changes: 13 additions & 1 deletion hinter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,34 @@
import cassiopeia_diskstore # Required for building to executable
from dotenv import load_dotenv

# noinspection PyUnresolvedReferences
import dearpygui.dearpygui as imgui # For all the modules to use

# noinspection PyUnresolvedReferences
import hinter.settings
# noinspection PyUnresolvedReferences
import hinter.struct.User as User
# noinspection PyUnresolvedReferences
import hinter.struct.PlayerPlayedWith as PlayerPlayedWith
# noinspection PyUnresolvedReferences
import hinter.struct.PlayersPlayedWith as PlayersPlayedWith
# noinspection PyUnresolvedReferences
import hinter.data
# noinspection PyUnresolvedReferences
import hinter.background.dataloader as DataLoader
# noinspection PyUnresolvedReferences
import hinter.ui
# noinspection PyUnresolvedReferences
import hinter.ui.progress as Progress
from hinter.ui.functionality import UIFunctionality
# noinspection PyUnresolvedReferences
import hinter.ui.popups as Popups
import hinter.users
from hinter.ui.menu import UIMenus
from hinter.match_breakdown import MatchBreakdown as MatchBreakdown
# noinspection PyUnresolvedReferences
from hinter.background.match_data import MatchData as MatchData
# noinspection PyUnresolvedReferences
from hinter.match_breakdown import MatchBreakdown as MatchBreakdown

# TODO: Move MatchHistory here

Expand Down
91 changes: 91 additions & 0 deletions hinter/background/match_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
from typing import TypedDict, Required, Union

import cassiopeia

import hinter


# Does not support Arena
class GameReturn(TypedDict, total=False):
match_id: Required[int]
map_id: Required[int]
queue: Required[str]
match_duration: Required[str]
# region For individual match views
players: Required[list[list[cassiopeia.core.match.Participant]]]
teams_kills: Required[list[int]]
teams_damage: Required[list[int]]
teams_outcomes: Required[list[str]]
teams_background_colors: Required[list[list[float]]] # List of lists as it's split by team
players_summoner_spells: Required[list[list[str]]]
players_roles: Required[list[list[str]]]
players_kdas: Required[list[list[str]]]
players_k_d_as: Required[list[list[str]]]
players_damage: Required[list[list[int]]]
players_damage_of_team: Required[list[list[int]]]
players_damage_per_min: Required[list[list[int]]]
players_vision: Required[list[list[int]]]
players_vision_per_min: Required[list[list[float]]]
players_kp: Required[list[list[float]]]
players_cs: Required[list[list[int]]]
players_cs_per_min: Required[list[list[float]]]
players_items: Required[list[list[list[dict]]]]
players_key_runes: Required[list[list[dict]]]
players_secondary_runes: Required[list[list[dict]]]
players_runes: Required[list[list[list[dict]]]]
# endregion For individual match views
# region For Match History
player: cassiopeia.core.match.Participant
team: str
team_kills: int
team_damage: int
outcome: str
background_color: list[float]
summoner_spells: list[str]
role: str
kda: str
k_d_a: str
damage: int
damage_of_team: int
damage_per_min: int
vision: int
vision_per_min: float
kp: float
cs: int
cs_per_min: float
items: list[dict]
key_rune: dict
secondary_rune: dict
runes: list[dict]
# endregion For Match History


class MatchData:
game: Union[GameReturn, None]
_match: cassiopeia.core.match.Match

def __init__(self, game: int, user: str = None):
self.game = None
self._match = hinter.cassiopeia.get_match(game, hinter.settings.region)

self._format_game()

if user is not None:
self._format_game_for(user)

def _format_game(self) -> None:
self.game = GameReturn(
match_id=self._match_id,
map_id=self._map_id,
)

def _format_game_for(self, user) -> None:
pass

@property
def _match_id(self) -> int:
return int(self._match.id)

@property
def _map_id(self) -> int:
return self._match.map.id
11 changes: 6 additions & 5 deletions hinter/match_history/display_matches.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,12 @@ def display_match(table, ui, render, game, row_count):
hinter.imgui.add_spacer(height=5)

# Selectable to be able to click row
hinter.imgui.add_selectable(
span_columns=True,
height=115,
callback=lambda: hinter.MatchBreakdown(game["match_id"]),
)
if game['queue'] != 'Arena':
hinter.imgui.add_selectable(
span_columns=True,
height=115,
callback=lambda: hinter.MatchBreakdown(game["match_id"]),
)

hinter.imgui.set_table_row_color(
table=table,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


# noinspection DuplicatedCode
class MatchData(MatchHistory):
class HistoryData(MatchHistory):
game: dict
champ_icons: list
player: cassiopeia.core.match.Participant
Expand Down Expand Up @@ -63,6 +63,8 @@ def load_matches(self, render: bool = True):
MatchDisplay.add_row_handlers('match_history')
MatchDisplay.show_friends_played_with(self.ui, self.players_played_with)

# TODO: Move the actual data getting and formatting to background.match_data

def _assemble_basic_match_info(self, match: cassiopeia.Match):
self.game = {
'match_id': match.id,
Expand Down Expand Up @@ -164,7 +166,7 @@ def _calculate_match_data(self, match: cassiopeia.Match):
match_minutes = round(match_minutes, 2)

# Calculate when the match happened
now = datetime.datetime.utcnow()
now = datetime.datetime.now()
now = pytz.utc.localize(now)
match_time = datetime.datetime.fromisoformat(
str(match.creation)
Expand Down Expand Up @@ -201,7 +203,10 @@ def _calculate_match_data(self, match: cassiopeia.Match):
position: cassiopeia.data.Position = cassiopeia.data.Position.none
if match.map.id == hinter.data.constants.SUMMONERS_RIFT_MAP_ID:
# Determine role of player
role = str(player.stats.role)
if hasattr(player.stats, 'role'):
role = str(player.stats.role)
else:
role = str(player.role)
lane = str(player.lane)

cassiopeia.core.Items(region=hinter.settings.region)
Expand Down
4 changes: 2 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import hinter
# noinspection PyPep8Naming
import hinter.match_history.match_data as MatchData
import hinter.match_history.history_data as History


def continue_drawing(ui, render):
hinter.Menu = hinter.UIMenus(ui)
hinter.UI = ui
MatchData.MatchData(ui, render)
History.HistoryData(ui, render)


hinter.UI = hinter.UIFunctionality(continue_drawing)
Expand Down

0 comments on commit 22908ef

Please sign in to comment.