Module valolyticspy.models.match

Expand source code
import sys
sys.path.append("")

from valolyticspy.dtos.riot.enums import MatchRegion
from typing import List, Union, Dict, Optional
from datetime import datetime
from enum import Enum
from valolyticspy.services.dto_loader import ValorantDTO
from valolyticspy.dtos.valorant_api.map import Map
from valolyticspy.dtos.valorant_api.agent import Agent, Ability
from valolyticspy.dtos.valorant_api.weapon import Weapon
from valolyticspy.dtos.valorant_api.gear import Gear
from valolyticspy.dtos.valorant_api.ceremony import Ceremony
from valolyticspy.dtos.valorant_api.competitive_tier import Tier
from valolyticspy.dtos.valorant_api.player_card import PlayerCard
from valolyticspy.dtos.valorant_api.player_title import PlayerTitle
from valolyticspy.services.helper.map_from_mapId import get_map_from_mapId
from valolyticspy.services.helper.competitive_tier_from_tier import get_competitive_tier_from_tier
from valolyticspy.services.helper.ceremony_from_roundCeremony import get_ceremony_from_roundCeremony
from valolyticspy.dtos.riot.match import MatchInfoDto, AbilityCastsDto, TeamDto, PlayerDto, FinishingDamageDto, PlayerLocationsDto, KillDto, DamageDto, EconomyDto, PlayerRoundStatsDto, RoundResultDto, MatchDto, PlayerStatsDto as NormalPlayerStatsDto
from valolyticspy.dtos.valolytics.playerstats import SideStatsDto, PlayerStatsDto

from enum import Enum

class Side(Enum):
    """
    Enum representing the sides in a match.

    Attributes:
        ATTACK (str): Represents the attacking side.
        DEFENSE (str): Represents the defending side.
    """
    ATTACK = "Attack"
    DEFENSE = "Defense"

from enum import Enum

class TeamId(Enum):
    """
    Enum representing the team ID.

    Attributes:
        RED (str): The team ID for the red team.
        BLUE (str): The team ID for the blue team.
    """
    RED = "Red"
    BLUE = "Blue"

class MatchInfoModel(MatchInfoDto):
    """
    Represents a model for match information.

    Attributes:
        gameStart (datetime): The start time of the game.
        map (Map): The map on which the game was played.
    """

    gameStart: datetime
    map: Map

    @classmethod
    def from_dto(cls, dto: MatchInfoDto) -> "MatchInfoModel":
        """
        Creates a MatchInfoModel instance from a MatchInfoDto instance.

        Args:
            dto (MatchInfoDto): The MatchInfoDto instance to convert.

        Returns:
            MatchInfoModel: The converted MatchInfoModel instance.
        """
        return cls(
            **dto.model_dump(),
            gameStart=datetime.fromtimestamp(dto.gameStartMillis // 1000),
            map=get_map_from_mapId(dto.mapId)
        )

class AbilityCastsModel(AbilityCastsDto):
    """A model representing the ability casts in a match."""

    def __getitem__(self, key:str) -> int:
        """Get the number of casts for a specific ability.

        Args:
            key (str): The key representing the ability.

        Returns:
            int: The number of casts for the specified ability.
        """
        return getattr(self, f"{key.lower()}Casts")

class TeamModel(TeamDto):
    """
    Represents a team model.

    Attributes:
        teamId (int): The ID of the team.
    """

    @classmethod
    def from_dto(cls, dto:TeamDto) -> "TeamModel":
        """
        Creates a TeamModel instance from a TeamDto instance.

        Args:
            dto (TeamDto): The TeamDto instance.

        Returns:
            TeamModel: The created TeamModel instance.
        """
        return cls(**dto.model_dump())

    def side(self, roundNum:int) -> Side:
        """
        Determines the side of the team based on the round number.

        Args:
            roundNum (int): The round number.

        Returns:
            Side: The side of the team.
        """
        if(roundNum < 12 or (roundNum >= 24 and roundNum % 2 == 0)):
            return Side.ATTACK if self.teamId == TeamId.RED.value else Side.DEFENSE
        else:
            return Side.DEFENSE if self.teamId == TeamId.RED.value else Side.ATTACK

class PlayerModel(PlayerDto):
    """
    Represents a player in the game.

    Attributes:
        agent (Optional[Agent]): The agent chosen by the player.
        competitiveTier (Tier): The competitive tier of the player.
        playerCard (PlayerCard): The player's selected card.
        playerTitle (Optional[PlayerTitle]): The player's selected title.
        team (Optional[TeamModel]): The team the player belongs to.
        stats (Optional[Union[SideStatsDto, NormalPlayerStatsDto]]): The player's statistics.

    Methods:
        from_dto(cls, dto: PlayerDto, team: TeamModel, playerStats: PlayerStatsDto = None) -> PlayerModel:
            Creates a PlayerModel instance from a PlayerDto object.
        __hash__(self) -> int:
            Returns the hash value of the PlayerModel instance.
    """

    agent: Optional[Agent] = None
    competitiveTier: Tier
    playerCard: PlayerCard
    playerTitle: Optional[PlayerTitle] = None
    team: Optional[TeamModel] = None
    stats: Optional[Union[SideStatsDto, NormalPlayerStatsDto]] = None

    @classmethod
    def from_dto(cls, dto: PlayerDto, team: TeamModel, playerStats: PlayerStatsDto = None) -> "PlayerModel":
        """
        Converts a PlayerDto object to a PlayerModel object.

        Args:
            dto (PlayerDto): The PlayerDto object to convert.
            team (TeamModel): The TeamModel object to associate with the player.
            playerStats (PlayerStatsDto, optional): The PlayerStatsDto object to use for player stats. Defaults to None.

        Returns:
            PlayerModel: The converted PlayerModel object.
        """
        dumped_model = dto.model_dump()
        dumped_model.pop("competitiveTier")
        dumped_model.pop("playerCard")
        dumped_model.pop("playerTitle")
        dumped_model.pop("stats")
        return cls(
            **dumped_model,
            agent=ValorantDTO.AGENTS[dto.characterId.lower()] if dto.characterId != None else None,
            competitiveTier=get_competitive_tier_from_tier(dto.competitiveTier),
            playerCard=ValorantDTO.PLAYER_CARDS[dto.playerCard],
            playerTitle=ValorantDTO.PLAYER_TITLES[dto.playerTitle] if dto.playerTitle != "" else None,
            team=team,
            stats=playerStats.side if playerStats != None else dto.stats
        )

    def __hash__(self) -> int:
            """
            Returns the hash value of the object based on its 'puuid' attribute.

            Returns:
                int: The hash value of the object.
            """
            return hash(self.puuid)

class FinishingDamageModel(FinishingDamageDto):
    """
    Represents a model for finishing damage in a match.

    Attributes:
        damageItem (Optional[Union[Ability, Weapon, str]]): The damage item associated with the finishing damage.
    """

    damageItem: Optional[Union[Ability, Weapon, str]] = None

    @classmethod
    def from_dto(cls, dto: FinishingDamageDto, damageItem: Union[Ability, Weapon, str]) -> "FinishingDamageModel":
        """
        Creates a `FinishingDamageModel` instance from a `FinishingDamageDto` object.

        Args:
            cls: The class object.
            dto: The `FinishingDamageDto` object containing the data.
            damageItem: The damage item associated with the finishing damage.

        Returns:
            A new instance of `FinishingDamageModel` with the data from the `FinishingDamageDto` object.
        """
        dumped_model = dto.model_dump()
        dumped_model.pop("damageItem")
        return cls(
            **dumped_model,
            damageItem=damageItem
        )

class KillModel(KillDto):
    """
    Represents a kill event in a match.

    Attributes:
        killer (PlayerModel): The player who performed the kill.
        victim (PlayerModel): The player who was killed.
        assistants (List[PlayerModel]): The players who assisted in the kill.
        playerLocations (Dict[str, PlayerLocationsDto]): The locations of the players involved in the kill.
        finishingDamage (FinishingDamageModel): The finishing damage information for the kill.
    """

    killer: PlayerModel
    victim: PlayerModel
    assistants: List[PlayerModel]
    playerLocations: Dict[str, PlayerLocationsDto]
    finishingDamage: FinishingDamageModel

    @classmethod
    def from_dto(cls, dto: KillDto, killer: PlayerModel, victim: PlayerModel, assistants: List[PlayerModel], finishingDamage: FinishingDamageModel) -> "KillModel":
        """
        Creates a KillModel instance from a KillDto and related objects.

        Args:
            dto (KillDto): The KillDto object containing the kill information.
            killer (PlayerModel): The player who performed the kill.
            victim (PlayerModel): The player who was killed.
            assistants (List[PlayerModel]): The players who assisted in the kill.
            finishingDamage (FinishingDamageModel): The finishing damage information for the kill.

        Returns:
            KillModel: The created KillModel instance.
        """
        dumped_model = dto.model_dump()
        dumped_model.pop("killer")
        dumped_model.pop("victim")
        dumped_model.pop("assistants")
        dumped_model.pop("playerLocations")
        dumped_model.pop("finishingDamage")
        return cls(
            **dumped_model,
            killer=killer,
            victim=victim,
            assistants=assistants,
            playerLocations={player_location.puuid: player_location for player_location in dto.playerLocations},
            finishingDamage=finishingDamage
        )

class DamageModel(DamageDto):
    """
    Represents a damage model in the game.
    
    Attributes:
        receiver (PlayerModel): The player who received the damage.
    """
    receiver: PlayerModel

    @classmethod
    def from_dto(cls, dto: DamageDto, receiver: PlayerModel) -> "DamageModel":
        """
        Creates a DamageModel instance from a DamageDto object and a receiver PlayerModel.
        
        Args:
            dto (DamageDto): The DamageDto object containing the damage information.
            receiver (PlayerModel): The PlayerModel object representing the receiver of the damage.
        
        Returns:
            DamageModel: The created DamageModel instance.
        """
        dumped_model = dto.model_dump()
        dumped_model.pop("receiver")
        return cls(
            **dumped_model,
            receiver=receiver
        )

class EconomyModel(EconomyDto):
    """
    Represents an economy model in the game.
    
    Attributes:
        weapon (Optional[Weapon]): The weapon equipped by the player. Defaults to None.
        armor (Optional[Gear]): The armor equipped by the player. Defaults to None.
    """
    weapon: Optional[Weapon] = None
    armor: Optional[Gear] = None

    @classmethod
    def from_dto(cls, dto: EconomyDto) -> "EconomyModel":
        """
        Creates an instance of EconomyModel from an EconomyDto object.
        
        Args:
            dto (EconomyDto): The EconomyDto object to create the EconomyModel from.
        
        Returns:
            EconomyModel: The created EconomyModel instance.
        """
        dumped_model = dto.model_dump()
        dumped_model.pop("weapon")
        dumped_model.pop("armor")
        return cls(
            **dumped_model,
            weapon=ValorantDTO.WEAPONS[dto.weapon.lower()] if dto.weapon != "" else None,
            armor=ValorantDTO.GEAR[dto.armor.lower()] if dto.armor != "" else None
        )

class PlayerRoundStatsModel(PlayerRoundStatsDto):
    """
    Represents the model for player round statistics.

    Attributes:
        player (PlayerModel): The player associated with the round statistics.
        kills (List[KillModel]): The list of kills made by the player.
        damage (List[DamageModel]): The list of damage inflicted by the player.
        economy (EconomyModel): The economy information of the player.

    Methods:
        from_dto(cls, dto: PlayerRoundStatsDto, player: PlayerModel, kills: List[KillModel], damage: List[DamageModel]) -> PlayerRoundStatsModel:
            Creates a new instance of PlayerRoundStatsModel from the provided DTO and related models.
    """
    player: PlayerModel
    kills: List[KillModel]
    damage: List[DamageModel]
    economy: EconomyModel

    @classmethod
    def from_dto(cls, dto: PlayerRoundStatsDto, player: PlayerModel, kills: List[KillModel], damage: List[DamageModel]) -> "PlayerRoundStatsModel":
        """
        Converts a PlayerRoundStatsDto object to a PlayerRoundStatsModel object.

        Args:
            dto (PlayerRoundStatsDto): The PlayerRoundStatsDto object to convert.
            player (PlayerModel): The PlayerModel object associated with the stats.
            kills (List[KillModel]): A list of KillModel objects representing the kills made by the player.
            damage (List[DamageModel]): A list of DamageModel objects representing the damage dealt by the player.

        Returns:
            PlayerRoundStatsModel: The converted PlayerRoundStatsModel object.
        """
        dumped_model = dto.model_dump()
        dumped_model.pop("kills")
        dumped_model.pop("damage")
        dumped_model.pop("economy")
        return cls(
            **dumped_model,
            player=player,
            kills=kills,
            damage=damage,
            economy=EconomyModel.from_dto(dto.economy)
        )

class RoundResultModel(RoundResultDto):
    """
    Represents a round result in a match.

    Attributes:
        roundCeremony (Optional[Ceremony]): The ceremony associated with the round.
        winningTeam (TeamModel): The winning team of the round.
        bombPlanter (Optional[PlayerModel]): The player who planted the bomb.
        isBombPlantAfterRoundEnd (Optional[bool]): Whether the bomb was planted after the round ended.
        bombDefuser (Optional[PlayerModel]): The player who defused the bomb.
        plantPlayerLocations (Optional[Dict[str, PlayerLocationsDto]]): The locations of players who planted the bomb.
        defusePlayerLocations (Optional[Dict[str, PlayerLocationsDto]]): The locations of players who defused the bomb.
        playerStats (Dict[str, PlayerRoundStatsModel]): The statistics of players in the round.
        kills (List[KillModel]): The kills that occurred in the round.
    """

    roundCeremony: Optional[Ceremony] = None
    winningTeam: TeamModel
    bombPlanter: Optional[PlayerModel] = None
    isBombPlantAfterRoundEnd: Optional[bool] = None
    bombDefuser: Optional[PlayerModel] = None
    plantPlayerLocations: Optional[Dict[str, PlayerLocationsDto]] = None
    defusePlayerLocations: Optional[Dict[str, PlayerLocationsDto]] = None
    playerStats: Dict[str, PlayerRoundStatsModel]
    kills: List[KillModel]

    @classmethod
    def from_dto(cls, dto: RoundResultDto, winningTeam: TeamModel, bombPlanter: PlayerModel, bombDefuser: PlayerModel, playerStats: Dict[str, PlayerRoundStatsModel], kills: List[KillModel]) -> "RoundResultModel":
        """
        Converts a RoundResultDto object into a RoundResultModel object.

        Args:
            dto (RoundResultDto): The RoundResultDto object to convert.
            winningTeam (TeamModel): The winning team of the round.
            bombPlanter (PlayerModel): The player who planted the bomb.
            bombDefuser (PlayerModel): The player who defused the bomb.
            playerStats (Dict[str, PlayerRoundStatsModel]): A dictionary of player round statistics.
            kills (List[KillModel]): A list of kill events.

        Returns:
            RoundResultModel: The converted RoundResultModel object.
        """
        dumped_model = dto.model_dump()
        dumped_model.pop("roundCeremony")
        dumped_model.pop("winningTeam")
        dumped_model.pop("bombPlanter")
        dumped_model.pop("bombDefuser")
        dumped_model.pop("plantPlayerLocations")
        dumped_model.pop("defusePlayerLocations")
        dumped_model.pop("playerStats")

        match dto.roundResult:
            case "Eliminated": isBombPlantAfterRoundEnd = True if dto.plantRoundTime > kills[-1].timeSinceRoundStartMillis else False
            case "Round timer expired": isBombPlantAfterRoundEnd = True if dto.plantRoundTime > 100*1000 else False
            case _: isBombPlantAfterRoundEnd = None

        return cls(
            **dumped_model,
            roundCeremony=get_ceremony_from_roundCeremony(dto.roundCeremony),
            winningTeam=winningTeam,
            bombPlanter=bombPlanter,
            isBombPlantAfterRoundEnd=isBombPlantAfterRoundEnd,
            bombDefuser=bombDefuser,
            plantPlayerLocations={player_location.puuid: player_location for player_location in dto.plantPlayerLocations} if dto.plantPlayerLocations != None else None,
            defusePlayerLocations={player_location.puuid: player_location for player_location in dto.defusePlayerLocations} if dto.defusePlayerLocations != None else None,
            playerStats=playerStats,
            kills=kills
        )

class MatchModel(MatchDto):
    """
    Represents a match in the ValolyticsPy application.

    Attributes:
        matchInfo (MatchInfoModel): Information about the match.
        teams (Dict[str, TeamModel]): A dictionary of teams in the match, where the key is the team ID and the value is the TeamModel object.
        players (Dict[str, PlayerModel]): A dictionary of players in the match, where the key is the player's PUUID and the value is the PlayerModel object.
        observers (Optional[Dict[str, PlayerModel]]): A dictionary of observers in the match, where the key is the observer's PUUID and the value is the PlayerModel object. Defaults to None.
        roundResults (List[RoundResultModel]): A list of round results in the match.
        raw_dto (Optional[MatchDto]): The raw MatchDto object used to initialize the MatchModel. Defaults to None.

    Methods:
        __init__(self, data: MatchDto, valolytics_client=None, region: MatchRegion=None): Initializes a MatchModel object.
        get_puuids_from_team(self, team: TeamModel) -> List[str]: Returns a list of PUUIDs from a specific team.
        get_team_by_puuids(self, puuids: List[str]) -> TeamModel: Returns the team that contains any of the given PUUIDs.
    """
    matchInfo: MatchInfoModel
    teams: Dict[str, TeamModel]
    players: Dict[str, PlayerModel]
    observers: Optional[Dict[str, PlayerModel]] = None
    roundResults: List[RoundResultModel]
    raw_dto: Optional[MatchDto] = None

    def __init__(self, data: MatchDto, valolytics_client=None, region: MatchRegion=None):
        """
        Initializes a MatchModel object.

        Args:
            data (MatchDto): The MatchDto object containing the match data.
            valolytics_client (optional): The Valolytics client object used to fetch player stats. Defaults to None.
            region (optional): The region of the match. Defaults to None.
        """
        teams: Dict[str, TeamModel] = {team.teamId: TeamModel.from_dto(team) for team in data.teams}
        players: Dict[str, PlayerModel] = {}
        observers: Dict[str, PlayerModel] = {}
        if valolytics_client != None and region != None:
            playerStats: Dict[str, PlayerStatsDto] = valolytics_client.get_playerstats_by_match_id(data.matchInfo.matchId, region)
        for player in data.players:
            if player.teamId != "Neutral":
                if valolytics_client != None and region != None:
                    players[player.puuid] = PlayerModel.from_dto(player, teams[player.teamId], playerStats[player.puuid])
                else:
                    players[player.puuid] = PlayerModel.from_dto(player, teams[player.teamId])
            else:
                observers[player.puuid] = PlayerModel.from_dto(player, None)

        ordered_kills: List[KillModel] = []
        rounds: List[RoundResultModel] = []
        for round in data.roundResults:
            winningTeam: TeamModel = teams[round.winningTeam] if round.winningTeam != None else None
            bombPlanter: PlayerModel = players[round.bombPlanter] if round.bombPlanter != None else None
            bombDefuser: PlayerModel = players[round.bombDefuser] if round.bombDefuser != None else None
            
            player_stats: Dict[str, PlayerRoundStatsModel] = {}
            for player in round.playerStats:

                kills: List[KillModel] = []
                for kill in player.kills:
                    killer = players[kill.killer]
                    victim = players[kill.victim]
                    assistants: List[PlayerModel] = []

                    for assist in kill.assistants:
                        assistants.append(players[assist])

                    damageItem: Union[Weapon, Ability, str] = None

                    if (kill.finishingDamage.damageType == "Weapon"):
                        try:
                            damageItem = ValorantDTO.WEAPONS[kill.finishingDamage.damageItem.lower()]
                        except:
                            damageItem = kill.finishingDamage.damageItem
                    elif (kill.finishingDamage.damageType == "Ability"):
                        damageItemStr = kill.finishingDamage.damageItem if kill.finishingDamage.damageItem != "GrenadeAbility" else "Grenade"
                        
                        for ability in players[kill.killer].agent.abilities:
                            if ability.slot == damageItemStr:
                                damageItem = ability
                                break
                    elif (kill.finishingDamage.damageType == ""):
                        kill.finishingDamage.damageType = "Bomb"
                        damageItem = ""

                    kills.append(KillModel.from_dto(kill, killer, victim, assistants, FinishingDamageModel.from_dto(kill.finishingDamage, damageItem)))
                    ordered_kills.extend(kills)

                damages: List[DamageModel] = []
                for damage in player.damage:
                    damages.append(DamageModel.from_dto(damage, players[damage.receiver]))

                player_stats[player.puuid] = PlayerRoundStatsModel.from_dto(player, players[player.puuid], kills, damages)

            ordered_kills.sort(key=lambda kill: kill.timeSinceRoundStartMillis)
            rounds.append(RoundResultModel.from_dto(round, winningTeam, bombPlanter, bombDefuser, player_stats, ordered_kills))
            players

        super().__init__(
            matchInfo=MatchInfoModel.from_dto(data.matchInfo),
            teams=teams,
            players=players,
            coaches=data.coaches,
            roundResults=rounds
        )
        self.observers = observers,
        self.raw_dto = data

    def get_puuids_from_team(self, team: TeamModel) -> List[str]:
        """
        Returns a list of PUUIDs from a specific team.

        Args:
            team (TeamModel): The team to get the PUUIDs from.

        Returns:
            List[str]: A list of PUUIDs from the specified team.
        """
        puuids: List[str] = []
        for player in self.players.values():
            if player.team == team:
                puuids.append(player.puuid)
        return puuids

    def get_team_by_puuids(self, puuids: List[str]) -> TeamModel:
        """
        Returns the team that contains any of the given PUUIDs.

        Args:
            puuids (List[str]): The list of PUUIDs to check.

        Returns:
            TeamModel: The team that contains any of the given PUUIDs.
        """
        any_in_team_red = any(element in set(self.get_puuids_from_team(self.teams[TeamId.RED.value])) for element in puuids)
        any_in_team_blue = any(element in set(self.get_puuids_from_team(self.teams[TeamId.BLUE.value])) for element in puuids)

        if any_in_team_red and not any_in_team_blue:
            return self.teams[TeamId.RED.value]
        elif any_in_team_blue and not any_in_team_red:
            return self.teams[TeamId.BLUE.value]

Classes

class AbilityCastsModel (**data: Any)

A model representing the ability casts in a match.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Expand source code
class AbilityCastsModel(AbilityCastsDto):
    """A model representing the ability casts in a match."""

    def __getitem__(self, key:str) -> int:
        """Get the number of casts for a specific ability.

        Args:
            key (str): The key representing the ability.

        Returns:
            int: The number of casts for the specified ability.
        """
        return getattr(self, f"{key.lower()}Casts")

Ancestors

Class variables

var model_computed_fields
var model_config
var model_fields
class DamageModel (**data: Any)

Represents a damage model in the game.

Attributes

receiver : PlayerModel
The player who received the damage.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Expand source code
class DamageModel(DamageDto):
    """
    Represents a damage model in the game.
    
    Attributes:
        receiver (PlayerModel): The player who received the damage.
    """
    receiver: PlayerModel

    @classmethod
    def from_dto(cls, dto: DamageDto, receiver: PlayerModel) -> "DamageModel":
        """
        Creates a DamageModel instance from a DamageDto object and a receiver PlayerModel.
        
        Args:
            dto (DamageDto): The DamageDto object containing the damage information.
            receiver (PlayerModel): The PlayerModel object representing the receiver of the damage.
        
        Returns:
            DamageModel: The created DamageModel instance.
        """
        dumped_model = dto.model_dump()
        dumped_model.pop("receiver")
        return cls(
            **dumped_model,
            receiver=receiver
        )

Ancestors

Class variables

var model_computed_fields
var model_config
var model_fields
var receiverPlayerModel

Static methods

def from_dto(dto: DamageDto, receiver: PlayerModel) ‑> DamageModel

Creates a DamageModel instance from a DamageDto object and a receiver PlayerModel.

Args

dto : DamageDto
The DamageDto object containing the damage information.
receiver : PlayerModel
The PlayerModel object representing the receiver of the damage.

Returns

DamageModel
The created DamageModel instance.
Expand source code
@classmethod
def from_dto(cls, dto: DamageDto, receiver: PlayerModel) -> "DamageModel":
    """
    Creates a DamageModel instance from a DamageDto object and a receiver PlayerModel.
    
    Args:
        dto (DamageDto): The DamageDto object containing the damage information.
        receiver (PlayerModel): The PlayerModel object representing the receiver of the damage.
    
    Returns:
        DamageModel: The created DamageModel instance.
    """
    dumped_model = dto.model_dump()
    dumped_model.pop("receiver")
    return cls(
        **dumped_model,
        receiver=receiver
    )
class EconomyModel (**data: Any)

Represents an economy model in the game.

Attributes

weapon : Optional[Weapon]
The weapon equipped by the player. Defaults to None.
armor : Optional[Gear]
The armor equipped by the player. Defaults to None.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Expand source code
class EconomyModel(EconomyDto):
    """
    Represents an economy model in the game.
    
    Attributes:
        weapon (Optional[Weapon]): The weapon equipped by the player. Defaults to None.
        armor (Optional[Gear]): The armor equipped by the player. Defaults to None.
    """
    weapon: Optional[Weapon] = None
    armor: Optional[Gear] = None

    @classmethod
    def from_dto(cls, dto: EconomyDto) -> "EconomyModel":
        """
        Creates an instance of EconomyModel from an EconomyDto object.
        
        Args:
            dto (EconomyDto): The EconomyDto object to create the EconomyModel from.
        
        Returns:
            EconomyModel: The created EconomyModel instance.
        """
        dumped_model = dto.model_dump()
        dumped_model.pop("weapon")
        dumped_model.pop("armor")
        return cls(
            **dumped_model,
            weapon=ValorantDTO.WEAPONS[dto.weapon.lower()] if dto.weapon != "" else None,
            armor=ValorantDTO.GEAR[dto.armor.lower()] if dto.armor != "" else None
        )

Ancestors

Class variables

var armor : Optional[Gear]
var model_computed_fields
var model_config
var model_fields
var weapon : Optional[Weapon]

Static methods

def from_dto(dto: EconomyDto) ‑> EconomyModel

Creates an instance of EconomyModel from an EconomyDto object.

Args

dto : EconomyDto
The EconomyDto object to create the EconomyModel from.

Returns

EconomyModel
The created EconomyModel instance.
Expand source code
@classmethod
def from_dto(cls, dto: EconomyDto) -> "EconomyModel":
    """
    Creates an instance of EconomyModel from an EconomyDto object.
    
    Args:
        dto (EconomyDto): The EconomyDto object to create the EconomyModel from.
    
    Returns:
        EconomyModel: The created EconomyModel instance.
    """
    dumped_model = dto.model_dump()
    dumped_model.pop("weapon")
    dumped_model.pop("armor")
    return cls(
        **dumped_model,
        weapon=ValorantDTO.WEAPONS[dto.weapon.lower()] if dto.weapon != "" else None,
        armor=ValorantDTO.GEAR[dto.armor.lower()] if dto.armor != "" else None
    )
class FinishingDamageModel (**data: Any)

Represents a model for finishing damage in a match.

Attributes

damageItem : Optional[Union[Ability, Weapon, str]]
The damage item associated with the finishing damage.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Expand source code
class FinishingDamageModel(FinishingDamageDto):
    """
    Represents a model for finishing damage in a match.

    Attributes:
        damageItem (Optional[Union[Ability, Weapon, str]]): The damage item associated with the finishing damage.
    """

    damageItem: Optional[Union[Ability, Weapon, str]] = None

    @classmethod
    def from_dto(cls, dto: FinishingDamageDto, damageItem: Union[Ability, Weapon, str]) -> "FinishingDamageModel":
        """
        Creates a `FinishingDamageModel` instance from a `FinishingDamageDto` object.

        Args:
            cls: The class object.
            dto: The `FinishingDamageDto` object containing the data.
            damageItem: The damage item associated with the finishing damage.

        Returns:
            A new instance of `FinishingDamageModel` with the data from the `FinishingDamageDto` object.
        """
        dumped_model = dto.model_dump()
        dumped_model.pop("damageItem")
        return cls(
            **dumped_model,
            damageItem=damageItem
        )

Ancestors

Class variables

var damageItem : Union[AbilityWeapon, str, ForwardRef(None)]
var model_computed_fields
var model_config
var model_fields

Static methods

def from_dto(dto: FinishingDamageDto, damageItem: Union[AbilityWeapon, str]) ‑> FinishingDamageModel

Creates a FinishingDamageModel instance from a FinishingDamageDto object.

Args

cls
The class object.
dto
The FinishingDamageDto object containing the data.
damageItem
The damage item associated with the finishing damage.

Returns

A new instance of FinishingDamageModel with the data from the FinishingDamageDto object.

Expand source code
@classmethod
def from_dto(cls, dto: FinishingDamageDto, damageItem: Union[Ability, Weapon, str]) -> "FinishingDamageModel":
    """
    Creates a `FinishingDamageModel` instance from a `FinishingDamageDto` object.

    Args:
        cls: The class object.
        dto: The `FinishingDamageDto` object containing the data.
        damageItem: The damage item associated with the finishing damage.

    Returns:
        A new instance of `FinishingDamageModel` with the data from the `FinishingDamageDto` object.
    """
    dumped_model = dto.model_dump()
    dumped_model.pop("damageItem")
    return cls(
        **dumped_model,
        damageItem=damageItem
    )
class KillModel (**data: Any)

Represents a kill event in a match.

Attributes

killer : PlayerModel
The player who performed the kill.
victim : PlayerModel
The player who was killed.
assistants : List[PlayerModel]
The players who assisted in the kill.
playerLocations : Dict[str, PlayerLocationsDto]
The locations of the players involved in the kill.
finishingDamage : FinishingDamageModel
The finishing damage information for the kill.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Expand source code
class KillModel(KillDto):
    """
    Represents a kill event in a match.

    Attributes:
        killer (PlayerModel): The player who performed the kill.
        victim (PlayerModel): The player who was killed.
        assistants (List[PlayerModel]): The players who assisted in the kill.
        playerLocations (Dict[str, PlayerLocationsDto]): The locations of the players involved in the kill.
        finishingDamage (FinishingDamageModel): The finishing damage information for the kill.
    """

    killer: PlayerModel
    victim: PlayerModel
    assistants: List[PlayerModel]
    playerLocations: Dict[str, PlayerLocationsDto]
    finishingDamage: FinishingDamageModel

    @classmethod
    def from_dto(cls, dto: KillDto, killer: PlayerModel, victim: PlayerModel, assistants: List[PlayerModel], finishingDamage: FinishingDamageModel) -> "KillModel":
        """
        Creates a KillModel instance from a KillDto and related objects.

        Args:
            dto (KillDto): The KillDto object containing the kill information.
            killer (PlayerModel): The player who performed the kill.
            victim (PlayerModel): The player who was killed.
            assistants (List[PlayerModel]): The players who assisted in the kill.
            finishingDamage (FinishingDamageModel): The finishing damage information for the kill.

        Returns:
            KillModel: The created KillModel instance.
        """
        dumped_model = dto.model_dump()
        dumped_model.pop("killer")
        dumped_model.pop("victim")
        dumped_model.pop("assistants")
        dumped_model.pop("playerLocations")
        dumped_model.pop("finishingDamage")
        return cls(
            **dumped_model,
            killer=killer,
            victim=victim,
            assistants=assistants,
            playerLocations={player_location.puuid: player_location for player_location in dto.playerLocations},
            finishingDamage=finishingDamage
        )

Ancestors

Class variables

var assistants : List[PlayerModel]
var finishingDamageFinishingDamageModel
var killerPlayerModel
var model_computed_fields
var model_config
var model_fields
var playerLocations : Dict[str, PlayerLocationsDto]
var victimPlayerModel

Static methods

def from_dto(dto: KillDto, killer: PlayerModel, victim: PlayerModel, assistants: List[PlayerModel], finishingDamage: FinishingDamageModel) ‑> KillModel

Creates a KillModel instance from a KillDto and related objects.

Args

dto : KillDto
The KillDto object containing the kill information.
killer : PlayerModel
The player who performed the kill.
victim : PlayerModel
The player who was killed.
assistants : List[PlayerModel]
The players who assisted in the kill.
finishingDamage : FinishingDamageModel
The finishing damage information for the kill.

Returns

KillModel
The created KillModel instance.
Expand source code
@classmethod
def from_dto(cls, dto: KillDto, killer: PlayerModel, victim: PlayerModel, assistants: List[PlayerModel], finishingDamage: FinishingDamageModel) -> "KillModel":
    """
    Creates a KillModel instance from a KillDto and related objects.

    Args:
        dto (KillDto): The KillDto object containing the kill information.
        killer (PlayerModel): The player who performed the kill.
        victim (PlayerModel): The player who was killed.
        assistants (List[PlayerModel]): The players who assisted in the kill.
        finishingDamage (FinishingDamageModel): The finishing damage information for the kill.

    Returns:
        KillModel: The created KillModel instance.
    """
    dumped_model = dto.model_dump()
    dumped_model.pop("killer")
    dumped_model.pop("victim")
    dumped_model.pop("assistants")
    dumped_model.pop("playerLocations")
    dumped_model.pop("finishingDamage")
    return cls(
        **dumped_model,
        killer=killer,
        victim=victim,
        assistants=assistants,
        playerLocations={player_location.puuid: player_location for player_location in dto.playerLocations},
        finishingDamage=finishingDamage
    )
class MatchInfoModel (**data: Any)

Represents a model for match information.

Attributes

gameStart : datetime
The start time of the game.
map : Map
The map on which the game was played.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Expand source code
class MatchInfoModel(MatchInfoDto):
    """
    Represents a model for match information.

    Attributes:
        gameStart (datetime): The start time of the game.
        map (Map): The map on which the game was played.
    """

    gameStart: datetime
    map: Map

    @classmethod
    def from_dto(cls, dto: MatchInfoDto) -> "MatchInfoModel":
        """
        Creates a MatchInfoModel instance from a MatchInfoDto instance.

        Args:
            dto (MatchInfoDto): The MatchInfoDto instance to convert.

        Returns:
            MatchInfoModel: The converted MatchInfoModel instance.
        """
        return cls(
            **dto.model_dump(),
            gameStart=datetime.fromtimestamp(dto.gameStartMillis // 1000),
            map=get_map_from_mapId(dto.mapId)
        )

Ancestors

Class variables

var gameStart : datetime.datetime
var mapMap
var model_computed_fields
var model_config
var model_fields

Static methods

def from_dto(dto: MatchInfoDto) ‑> MatchInfoModel

Creates a MatchInfoModel instance from a MatchInfoDto instance.

Args

dto : MatchInfoDto
The MatchInfoDto instance to convert.

Returns

MatchInfoModel
The converted MatchInfoModel instance.
Expand source code
@classmethod
def from_dto(cls, dto: MatchInfoDto) -> "MatchInfoModel":
    """
    Creates a MatchInfoModel instance from a MatchInfoDto instance.

    Args:
        dto (MatchInfoDto): The MatchInfoDto instance to convert.

    Returns:
        MatchInfoModel: The converted MatchInfoModel instance.
    """
    return cls(
        **dto.model_dump(),
        gameStart=datetime.fromtimestamp(dto.gameStartMillis // 1000),
        map=get_map_from_mapId(dto.mapId)
    )
class MatchModel (data: MatchDto, valolytics_client=None, region: MatchRegion = None)

Represents a match in the ValolyticsPy application.

Attributes

matchInfo : MatchInfoModel
Information about the match.
teams : Dict[str, TeamModel]
A dictionary of teams in the match, where the key is the team ID and the value is the TeamModel object.
players : Dict[str, PlayerModel]
A dictionary of players in the match, where the key is the player's PUUID and the value is the PlayerModel object.
observers : Optional[Dict[str, PlayerModel]]
A dictionary of observers in the match, where the key is the observer's PUUID and the value is the PlayerModel object. Defaults to None.
roundResults : List[RoundResultModel]
A list of round results in the match.
raw_dto : Optional[MatchDto]
The raw MatchDto object used to initialize the MatchModel. Defaults to None.

Methods

init(self, data: MatchDto, valolytics_client=None, region: MatchRegion=None): Initializes a MatchModel object. get_puuids_from_team(self, team: TeamModel) -> List[str]: Returns a list of PUUIDs from a specific team. get_team_by_puuids(self, puuids: List[str]) -> TeamModel: Returns the team that contains any of the given PUUIDs.

Initializes a MatchModel object.

Args

data : MatchDto
The MatchDto object containing the match data.
valolytics_client : optional
The Valolytics client object used to fetch player stats. Defaults to None.
region : optional
The region of the match. Defaults to None.
Expand source code
class MatchModel(MatchDto):
    """
    Represents a match in the ValolyticsPy application.

    Attributes:
        matchInfo (MatchInfoModel): Information about the match.
        teams (Dict[str, TeamModel]): A dictionary of teams in the match, where the key is the team ID and the value is the TeamModel object.
        players (Dict[str, PlayerModel]): A dictionary of players in the match, where the key is the player's PUUID and the value is the PlayerModel object.
        observers (Optional[Dict[str, PlayerModel]]): A dictionary of observers in the match, where the key is the observer's PUUID and the value is the PlayerModel object. Defaults to None.
        roundResults (List[RoundResultModel]): A list of round results in the match.
        raw_dto (Optional[MatchDto]): The raw MatchDto object used to initialize the MatchModel. Defaults to None.

    Methods:
        __init__(self, data: MatchDto, valolytics_client=None, region: MatchRegion=None): Initializes a MatchModel object.
        get_puuids_from_team(self, team: TeamModel) -> List[str]: Returns a list of PUUIDs from a specific team.
        get_team_by_puuids(self, puuids: List[str]) -> TeamModel: Returns the team that contains any of the given PUUIDs.
    """
    matchInfo: MatchInfoModel
    teams: Dict[str, TeamModel]
    players: Dict[str, PlayerModel]
    observers: Optional[Dict[str, PlayerModel]] = None
    roundResults: List[RoundResultModel]
    raw_dto: Optional[MatchDto] = None

    def __init__(self, data: MatchDto, valolytics_client=None, region: MatchRegion=None):
        """
        Initializes a MatchModel object.

        Args:
            data (MatchDto): The MatchDto object containing the match data.
            valolytics_client (optional): The Valolytics client object used to fetch player stats. Defaults to None.
            region (optional): The region of the match. Defaults to None.
        """
        teams: Dict[str, TeamModel] = {team.teamId: TeamModel.from_dto(team) for team in data.teams}
        players: Dict[str, PlayerModel] = {}
        observers: Dict[str, PlayerModel] = {}
        if valolytics_client != None and region != None:
            playerStats: Dict[str, PlayerStatsDto] = valolytics_client.get_playerstats_by_match_id(data.matchInfo.matchId, region)
        for player in data.players:
            if player.teamId != "Neutral":
                if valolytics_client != None and region != None:
                    players[player.puuid] = PlayerModel.from_dto(player, teams[player.teamId], playerStats[player.puuid])
                else:
                    players[player.puuid] = PlayerModel.from_dto(player, teams[player.teamId])
            else:
                observers[player.puuid] = PlayerModel.from_dto(player, None)

        ordered_kills: List[KillModel] = []
        rounds: List[RoundResultModel] = []
        for round in data.roundResults:
            winningTeam: TeamModel = teams[round.winningTeam] if round.winningTeam != None else None
            bombPlanter: PlayerModel = players[round.bombPlanter] if round.bombPlanter != None else None
            bombDefuser: PlayerModel = players[round.bombDefuser] if round.bombDefuser != None else None
            
            player_stats: Dict[str, PlayerRoundStatsModel] = {}
            for player in round.playerStats:

                kills: List[KillModel] = []
                for kill in player.kills:
                    killer = players[kill.killer]
                    victim = players[kill.victim]
                    assistants: List[PlayerModel] = []

                    for assist in kill.assistants:
                        assistants.append(players[assist])

                    damageItem: Union[Weapon, Ability, str] = None

                    if (kill.finishingDamage.damageType == "Weapon"):
                        try:
                            damageItem = ValorantDTO.WEAPONS[kill.finishingDamage.damageItem.lower()]
                        except:
                            damageItem = kill.finishingDamage.damageItem
                    elif (kill.finishingDamage.damageType == "Ability"):
                        damageItemStr = kill.finishingDamage.damageItem if kill.finishingDamage.damageItem != "GrenadeAbility" else "Grenade"
                        
                        for ability in players[kill.killer].agent.abilities:
                            if ability.slot == damageItemStr:
                                damageItem = ability
                                break
                    elif (kill.finishingDamage.damageType == ""):
                        kill.finishingDamage.damageType = "Bomb"
                        damageItem = ""

                    kills.append(KillModel.from_dto(kill, killer, victim, assistants, FinishingDamageModel.from_dto(kill.finishingDamage, damageItem)))
                    ordered_kills.extend(kills)

                damages: List[DamageModel] = []
                for damage in player.damage:
                    damages.append(DamageModel.from_dto(damage, players[damage.receiver]))

                player_stats[player.puuid] = PlayerRoundStatsModel.from_dto(player, players[player.puuid], kills, damages)

            ordered_kills.sort(key=lambda kill: kill.timeSinceRoundStartMillis)
            rounds.append(RoundResultModel.from_dto(round, winningTeam, bombPlanter, bombDefuser, player_stats, ordered_kills))
            players

        super().__init__(
            matchInfo=MatchInfoModel.from_dto(data.matchInfo),
            teams=teams,
            players=players,
            coaches=data.coaches,
            roundResults=rounds
        )
        self.observers = observers,
        self.raw_dto = data

    def get_puuids_from_team(self, team: TeamModel) -> List[str]:
        """
        Returns a list of PUUIDs from a specific team.

        Args:
            team (TeamModel): The team to get the PUUIDs from.

        Returns:
            List[str]: A list of PUUIDs from the specified team.
        """
        puuids: List[str] = []
        for player in self.players.values():
            if player.team == team:
                puuids.append(player.puuid)
        return puuids

    def get_team_by_puuids(self, puuids: List[str]) -> TeamModel:
        """
        Returns the team that contains any of the given PUUIDs.

        Args:
            puuids (List[str]): The list of PUUIDs to check.

        Returns:
            TeamModel: The team that contains any of the given PUUIDs.
        """
        any_in_team_red = any(element in set(self.get_puuids_from_team(self.teams[TeamId.RED.value])) for element in puuids)
        any_in_team_blue = any(element in set(self.get_puuids_from_team(self.teams[TeamId.BLUE.value])) for element in puuids)

        if any_in_team_red and not any_in_team_blue:
            return self.teams[TeamId.RED.value]
        elif any_in_team_blue and not any_in_team_red:
            return self.teams[TeamId.BLUE.value]

Ancestors

Class variables

var matchInfoMatchInfoModel
var model_computed_fields
var model_config
var model_fields
var observers : Optional[Dict[str, PlayerModel]]
var players : Dict[str, PlayerModel]
var raw_dto : Optional[MatchDto]
var roundResults : List[RoundResultModel]
var teams : Dict[str, TeamModel]

Methods

def get_puuids_from_team(self, team: TeamModel) ‑> List[str]

Returns a list of PUUIDs from a specific team.

Args

team : TeamModel
The team to get the PUUIDs from.

Returns

List[str]
A list of PUUIDs from the specified team.
Expand source code
def get_puuids_from_team(self, team: TeamModel) -> List[str]:
    """
    Returns a list of PUUIDs from a specific team.

    Args:
        team (TeamModel): The team to get the PUUIDs from.

    Returns:
        List[str]: A list of PUUIDs from the specified team.
    """
    puuids: List[str] = []
    for player in self.players.values():
        if player.team == team:
            puuids.append(player.puuid)
    return puuids
def get_team_by_puuids(self, puuids: List[str]) ‑> TeamModel

Returns the team that contains any of the given PUUIDs.

Args

puuids : List[str]
The list of PUUIDs to check.

Returns

TeamModel
The team that contains any of the given PUUIDs.
Expand source code
def get_team_by_puuids(self, puuids: List[str]) -> TeamModel:
    """
    Returns the team that contains any of the given PUUIDs.

    Args:
        puuids (List[str]): The list of PUUIDs to check.

    Returns:
        TeamModel: The team that contains any of the given PUUIDs.
    """
    any_in_team_red = any(element in set(self.get_puuids_from_team(self.teams[TeamId.RED.value])) for element in puuids)
    any_in_team_blue = any(element in set(self.get_puuids_from_team(self.teams[TeamId.BLUE.value])) for element in puuids)

    if any_in_team_red and not any_in_team_blue:
        return self.teams[TeamId.RED.value]
    elif any_in_team_blue and not any_in_team_red:
        return self.teams[TeamId.BLUE.value]
class PlayerModel (**data: Any)

Represents a player in the game.

Attributes

agent : Optional[Agent]
The agent chosen by the player.
competitiveTier : Tier
The competitive tier of the player.
playerCard : PlayerCard
The player's selected card.
playerTitle : Optional[PlayerTitle]
The player's selected title.
team : Optional[TeamModel]
The team the player belongs to.
stats : Optional[Union[SideStatsDto, NormalPlayerStatsDto]]
The player's statistics.

Methods

from_dto(cls, dto: PlayerDto, team: TeamModel, playerStats: PlayerStatsDto = None) -> PlayerModel: Creates a PlayerModel instance from a PlayerDto object. hash(self) -> int: Returns the hash value of the PlayerModel instance.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Expand source code
class PlayerModel(PlayerDto):
    """
    Represents a player in the game.

    Attributes:
        agent (Optional[Agent]): The agent chosen by the player.
        competitiveTier (Tier): The competitive tier of the player.
        playerCard (PlayerCard): The player's selected card.
        playerTitle (Optional[PlayerTitle]): The player's selected title.
        team (Optional[TeamModel]): The team the player belongs to.
        stats (Optional[Union[SideStatsDto, NormalPlayerStatsDto]]): The player's statistics.

    Methods:
        from_dto(cls, dto: PlayerDto, team: TeamModel, playerStats: PlayerStatsDto = None) -> PlayerModel:
            Creates a PlayerModel instance from a PlayerDto object.
        __hash__(self) -> int:
            Returns the hash value of the PlayerModel instance.
    """

    agent: Optional[Agent] = None
    competitiveTier: Tier
    playerCard: PlayerCard
    playerTitle: Optional[PlayerTitle] = None
    team: Optional[TeamModel] = None
    stats: Optional[Union[SideStatsDto, NormalPlayerStatsDto]] = None

    @classmethod
    def from_dto(cls, dto: PlayerDto, team: TeamModel, playerStats: PlayerStatsDto = None) -> "PlayerModel":
        """
        Converts a PlayerDto object to a PlayerModel object.

        Args:
            dto (PlayerDto): The PlayerDto object to convert.
            team (TeamModel): The TeamModel object to associate with the player.
            playerStats (PlayerStatsDto, optional): The PlayerStatsDto object to use for player stats. Defaults to None.

        Returns:
            PlayerModel: The converted PlayerModel object.
        """
        dumped_model = dto.model_dump()
        dumped_model.pop("competitiveTier")
        dumped_model.pop("playerCard")
        dumped_model.pop("playerTitle")
        dumped_model.pop("stats")
        return cls(
            **dumped_model,
            agent=ValorantDTO.AGENTS[dto.characterId.lower()] if dto.characterId != None else None,
            competitiveTier=get_competitive_tier_from_tier(dto.competitiveTier),
            playerCard=ValorantDTO.PLAYER_CARDS[dto.playerCard],
            playerTitle=ValorantDTO.PLAYER_TITLES[dto.playerTitle] if dto.playerTitle != "" else None,
            team=team,
            stats=playerStats.side if playerStats != None else dto.stats
        )

    def __hash__(self) -> int:
            """
            Returns the hash value of the object based on its 'puuid' attribute.

            Returns:
                int: The hash value of the object.
            """
            return hash(self.puuid)

Ancestors

Class variables

var agent : Optional[Agent]
var competitiveTierTier
var model_computed_fields
var model_config
var model_fields
var playerCardPlayerCard
var playerTitle : Optional[PlayerTitle]
var stats : Union[SideStatsDtoPlayerStatsDto, ForwardRef(None)]
var team : Optional[TeamModel]

Static methods

def from_dto(dto: PlayerDto, team: TeamModel, playerStats: PlayerStatsDto = None) ‑> PlayerModel

Converts a PlayerDto object to a PlayerModel object.

Args

dto : PlayerDto
The PlayerDto object to convert.
team : TeamModel
The TeamModel object to associate with the player.
playerStats : PlayerStatsDto, optional
The PlayerStatsDto object to use for player stats. Defaults to None.

Returns

PlayerModel
The converted PlayerModel object.
Expand source code
@classmethod
def from_dto(cls, dto: PlayerDto, team: TeamModel, playerStats: PlayerStatsDto = None) -> "PlayerModel":
    """
    Converts a PlayerDto object to a PlayerModel object.

    Args:
        dto (PlayerDto): The PlayerDto object to convert.
        team (TeamModel): The TeamModel object to associate with the player.
        playerStats (PlayerStatsDto, optional): The PlayerStatsDto object to use for player stats. Defaults to None.

    Returns:
        PlayerModel: The converted PlayerModel object.
    """
    dumped_model = dto.model_dump()
    dumped_model.pop("competitiveTier")
    dumped_model.pop("playerCard")
    dumped_model.pop("playerTitle")
    dumped_model.pop("stats")
    return cls(
        **dumped_model,
        agent=ValorantDTO.AGENTS[dto.characterId.lower()] if dto.characterId != None else None,
        competitiveTier=get_competitive_tier_from_tier(dto.competitiveTier),
        playerCard=ValorantDTO.PLAYER_CARDS[dto.playerCard],
        playerTitle=ValorantDTO.PLAYER_TITLES[dto.playerTitle] if dto.playerTitle != "" else None,
        team=team,
        stats=playerStats.side if playerStats != None else dto.stats
    )
class PlayerRoundStatsModel (**data: Any)

Represents the model for player round statistics.

Attributes

player : PlayerModel
The player associated with the round statistics.
kills : List[KillModel]
The list of kills made by the player.
damage : List[DamageModel]
The list of damage inflicted by the player.
economy : EconomyModel
The economy information of the player.

Methods

from_dto(cls, dto: PlayerRoundStatsDto, player: PlayerModel, kills: List[KillModel], damage: List[DamageModel]) -> PlayerRoundStatsModel: Creates a new instance of PlayerRoundStatsModel from the provided DTO and related models.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Expand source code
class PlayerRoundStatsModel(PlayerRoundStatsDto):
    """
    Represents the model for player round statistics.

    Attributes:
        player (PlayerModel): The player associated with the round statistics.
        kills (List[KillModel]): The list of kills made by the player.
        damage (List[DamageModel]): The list of damage inflicted by the player.
        economy (EconomyModel): The economy information of the player.

    Methods:
        from_dto(cls, dto: PlayerRoundStatsDto, player: PlayerModel, kills: List[KillModel], damage: List[DamageModel]) -> PlayerRoundStatsModel:
            Creates a new instance of PlayerRoundStatsModel from the provided DTO and related models.
    """
    player: PlayerModel
    kills: List[KillModel]
    damage: List[DamageModel]
    economy: EconomyModel

    @classmethod
    def from_dto(cls, dto: PlayerRoundStatsDto, player: PlayerModel, kills: List[KillModel], damage: List[DamageModel]) -> "PlayerRoundStatsModel":
        """
        Converts a PlayerRoundStatsDto object to a PlayerRoundStatsModel object.

        Args:
            dto (PlayerRoundStatsDto): The PlayerRoundStatsDto object to convert.
            player (PlayerModel): The PlayerModel object associated with the stats.
            kills (List[KillModel]): A list of KillModel objects representing the kills made by the player.
            damage (List[DamageModel]): A list of DamageModel objects representing the damage dealt by the player.

        Returns:
            PlayerRoundStatsModel: The converted PlayerRoundStatsModel object.
        """
        dumped_model = dto.model_dump()
        dumped_model.pop("kills")
        dumped_model.pop("damage")
        dumped_model.pop("economy")
        return cls(
            **dumped_model,
            player=player,
            kills=kills,
            damage=damage,
            economy=EconomyModel.from_dto(dto.economy)
        )

Ancestors

Class variables

var damage : List[DamageModel]
var economyEconomyModel
var kills : List[KillModel]
var model_computed_fields
var model_config
var model_fields
var playerPlayerModel

Static methods

def from_dto(dto: PlayerRoundStatsDto, player: PlayerModel, kills: List[KillModel], damage: List[DamageModel]) ‑> PlayerRoundStatsModel

Converts a PlayerRoundStatsDto object to a PlayerRoundStatsModel object.

Args

dto : PlayerRoundStatsDto
The PlayerRoundStatsDto object to convert.
player : PlayerModel
The PlayerModel object associated with the stats.
kills : List[KillModel]
A list of KillModel objects representing the kills made by the player.
damage : List[DamageModel]
A list of DamageModel objects representing the damage dealt by the player.

Returns

PlayerRoundStatsModel
The converted PlayerRoundStatsModel object.
Expand source code
@classmethod
def from_dto(cls, dto: PlayerRoundStatsDto, player: PlayerModel, kills: List[KillModel], damage: List[DamageModel]) -> "PlayerRoundStatsModel":
    """
    Converts a PlayerRoundStatsDto object to a PlayerRoundStatsModel object.

    Args:
        dto (PlayerRoundStatsDto): The PlayerRoundStatsDto object to convert.
        player (PlayerModel): The PlayerModel object associated with the stats.
        kills (List[KillModel]): A list of KillModel objects representing the kills made by the player.
        damage (List[DamageModel]): A list of DamageModel objects representing the damage dealt by the player.

    Returns:
        PlayerRoundStatsModel: The converted PlayerRoundStatsModel object.
    """
    dumped_model = dto.model_dump()
    dumped_model.pop("kills")
    dumped_model.pop("damage")
    dumped_model.pop("economy")
    return cls(
        **dumped_model,
        player=player,
        kills=kills,
        damage=damage,
        economy=EconomyModel.from_dto(dto.economy)
    )
class RoundResultModel (**data: Any)

Represents a round result in a match.

Attributes

roundCeremony : Optional[Ceremony]
The ceremony associated with the round.
winningTeam : TeamModel
The winning team of the round.
bombPlanter : Optional[PlayerModel]
The player who planted the bomb.
isBombPlantAfterRoundEnd : Optional[bool]
Whether the bomb was planted after the round ended.
bombDefuser : Optional[PlayerModel]
The player who defused the bomb.
plantPlayerLocations : Optional[Dict[str, PlayerLocationsDto]]
The locations of players who planted the bomb.
defusePlayerLocations : Optional[Dict[str, PlayerLocationsDto]]
The locations of players who defused the bomb.
playerStats : Dict[str, PlayerRoundStatsModel]
The statistics of players in the round.
kills : List[KillModel]
The kills that occurred in the round.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Expand source code
class RoundResultModel(RoundResultDto):
    """
    Represents a round result in a match.

    Attributes:
        roundCeremony (Optional[Ceremony]): The ceremony associated with the round.
        winningTeam (TeamModel): The winning team of the round.
        bombPlanter (Optional[PlayerModel]): The player who planted the bomb.
        isBombPlantAfterRoundEnd (Optional[bool]): Whether the bomb was planted after the round ended.
        bombDefuser (Optional[PlayerModel]): The player who defused the bomb.
        plantPlayerLocations (Optional[Dict[str, PlayerLocationsDto]]): The locations of players who planted the bomb.
        defusePlayerLocations (Optional[Dict[str, PlayerLocationsDto]]): The locations of players who defused the bomb.
        playerStats (Dict[str, PlayerRoundStatsModel]): The statistics of players in the round.
        kills (List[KillModel]): The kills that occurred in the round.
    """

    roundCeremony: Optional[Ceremony] = None
    winningTeam: TeamModel
    bombPlanter: Optional[PlayerModel] = None
    isBombPlantAfterRoundEnd: Optional[bool] = None
    bombDefuser: Optional[PlayerModel] = None
    plantPlayerLocations: Optional[Dict[str, PlayerLocationsDto]] = None
    defusePlayerLocations: Optional[Dict[str, PlayerLocationsDto]] = None
    playerStats: Dict[str, PlayerRoundStatsModel]
    kills: List[KillModel]

    @classmethod
    def from_dto(cls, dto: RoundResultDto, winningTeam: TeamModel, bombPlanter: PlayerModel, bombDefuser: PlayerModel, playerStats: Dict[str, PlayerRoundStatsModel], kills: List[KillModel]) -> "RoundResultModel":
        """
        Converts a RoundResultDto object into a RoundResultModel object.

        Args:
            dto (RoundResultDto): The RoundResultDto object to convert.
            winningTeam (TeamModel): The winning team of the round.
            bombPlanter (PlayerModel): The player who planted the bomb.
            bombDefuser (PlayerModel): The player who defused the bomb.
            playerStats (Dict[str, PlayerRoundStatsModel]): A dictionary of player round statistics.
            kills (List[KillModel]): A list of kill events.

        Returns:
            RoundResultModel: The converted RoundResultModel object.
        """
        dumped_model = dto.model_dump()
        dumped_model.pop("roundCeremony")
        dumped_model.pop("winningTeam")
        dumped_model.pop("bombPlanter")
        dumped_model.pop("bombDefuser")
        dumped_model.pop("plantPlayerLocations")
        dumped_model.pop("defusePlayerLocations")
        dumped_model.pop("playerStats")

        match dto.roundResult:
            case "Eliminated": isBombPlantAfterRoundEnd = True if dto.plantRoundTime > kills[-1].timeSinceRoundStartMillis else False
            case "Round timer expired": isBombPlantAfterRoundEnd = True if dto.plantRoundTime > 100*1000 else False
            case _: isBombPlantAfterRoundEnd = None

        return cls(
            **dumped_model,
            roundCeremony=get_ceremony_from_roundCeremony(dto.roundCeremony),
            winningTeam=winningTeam,
            bombPlanter=bombPlanter,
            isBombPlantAfterRoundEnd=isBombPlantAfterRoundEnd,
            bombDefuser=bombDefuser,
            plantPlayerLocations={player_location.puuid: player_location for player_location in dto.plantPlayerLocations} if dto.plantPlayerLocations != None else None,
            defusePlayerLocations={player_location.puuid: player_location for player_location in dto.defusePlayerLocations} if dto.defusePlayerLocations != None else None,
            playerStats=playerStats,
            kills=kills
        )

Ancestors

Class variables

var bombDefuser : Optional[PlayerModel]
var bombPlanter : Optional[PlayerModel]
var defusePlayerLocations : Optional[Dict[str, PlayerLocationsDto]]
var isBombPlantAfterRoundEnd : Optional[bool]
var kills : List[KillModel]
var model_computed_fields
var model_config
var model_fields
var plantPlayerLocations : Optional[Dict[str, PlayerLocationsDto]]
var playerStats : Dict[str, PlayerRoundStatsModel]
var roundCeremony : Optional[Ceremony]
var winningTeamTeamModel

Static methods

def from_dto(dto: RoundResultDto, winningTeam: TeamModel, bombPlanter: PlayerModel, bombDefuser: PlayerModel, playerStats: Dict[str, PlayerRoundStatsModel], kills: List[KillModel]) ‑> RoundResultModel

Converts a RoundResultDto object into a RoundResultModel object.

Args

dto : RoundResultDto
The RoundResultDto object to convert.
winningTeam : TeamModel
The winning team of the round.
bombPlanter : PlayerModel
The player who planted the bomb.
bombDefuser : PlayerModel
The player who defused the bomb.
playerStats : Dict[str, PlayerRoundStatsModel]
A dictionary of player round statistics.
kills : List[KillModel]
A list of kill events.

Returns

RoundResultModel
The converted RoundResultModel object.
Expand source code
@classmethod
def from_dto(cls, dto: RoundResultDto, winningTeam: TeamModel, bombPlanter: PlayerModel, bombDefuser: PlayerModel, playerStats: Dict[str, PlayerRoundStatsModel], kills: List[KillModel]) -> "RoundResultModel":
    """
    Converts a RoundResultDto object into a RoundResultModel object.

    Args:
        dto (RoundResultDto): The RoundResultDto object to convert.
        winningTeam (TeamModel): The winning team of the round.
        bombPlanter (PlayerModel): The player who planted the bomb.
        bombDefuser (PlayerModel): The player who defused the bomb.
        playerStats (Dict[str, PlayerRoundStatsModel]): A dictionary of player round statistics.
        kills (List[KillModel]): A list of kill events.

    Returns:
        RoundResultModel: The converted RoundResultModel object.
    """
    dumped_model = dto.model_dump()
    dumped_model.pop("roundCeremony")
    dumped_model.pop("winningTeam")
    dumped_model.pop("bombPlanter")
    dumped_model.pop("bombDefuser")
    dumped_model.pop("plantPlayerLocations")
    dumped_model.pop("defusePlayerLocations")
    dumped_model.pop("playerStats")

    match dto.roundResult:
        case "Eliminated": isBombPlantAfterRoundEnd = True if dto.plantRoundTime > kills[-1].timeSinceRoundStartMillis else False
        case "Round timer expired": isBombPlantAfterRoundEnd = True if dto.plantRoundTime > 100*1000 else False
        case _: isBombPlantAfterRoundEnd = None

    return cls(
        **dumped_model,
        roundCeremony=get_ceremony_from_roundCeremony(dto.roundCeremony),
        winningTeam=winningTeam,
        bombPlanter=bombPlanter,
        isBombPlantAfterRoundEnd=isBombPlantAfterRoundEnd,
        bombDefuser=bombDefuser,
        plantPlayerLocations={player_location.puuid: player_location for player_location in dto.plantPlayerLocations} if dto.plantPlayerLocations != None else None,
        defusePlayerLocations={player_location.puuid: player_location for player_location in dto.defusePlayerLocations} if dto.defusePlayerLocations != None else None,
        playerStats=playerStats,
        kills=kills
    )
class Side (value, names=None, *, module=None, qualname=None, type=None, start=1)

Enum representing the sides in a match.

Attributes

ATTACK : str
Represents the attacking side.
DEFENSE : str
Represents the defending side.
Expand source code
class Side(Enum):
    """
    Enum representing the sides in a match.

    Attributes:
        ATTACK (str): Represents the attacking side.
        DEFENSE (str): Represents the defending side.
    """
    ATTACK = "Attack"
    DEFENSE = "Defense"

Ancestors

  • enum.Enum

Class variables

var ATTACK
var DEFENSE
class TeamId (value, names=None, *, module=None, qualname=None, type=None, start=1)

Enum representing the team ID.

Attributes

RED : str
The team ID for the red team.
BLUE : str
The team ID for the blue team.
Expand source code
class TeamId(Enum):
    """
    Enum representing the team ID.

    Attributes:
        RED (str): The team ID for the red team.
        BLUE (str): The team ID for the blue team.
    """
    RED = "Red"
    BLUE = "Blue"

Ancestors

  • enum.Enum

Class variables

var BLUE
var RED
class TeamModel (**data: Any)

Represents a team model.

Attributes

teamId : int
The ID of the team.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Expand source code
class TeamModel(TeamDto):
    """
    Represents a team model.

    Attributes:
        teamId (int): The ID of the team.
    """

    @classmethod
    def from_dto(cls, dto:TeamDto) -> "TeamModel":
        """
        Creates a TeamModel instance from a TeamDto instance.

        Args:
            dto (TeamDto): The TeamDto instance.

        Returns:
            TeamModel: The created TeamModel instance.
        """
        return cls(**dto.model_dump())

    def side(self, roundNum:int) -> Side:
        """
        Determines the side of the team based on the round number.

        Args:
            roundNum (int): The round number.

        Returns:
            Side: The side of the team.
        """
        if(roundNum < 12 or (roundNum >= 24 and roundNum % 2 == 0)):
            return Side.ATTACK if self.teamId == TeamId.RED.value else Side.DEFENSE
        else:
            return Side.DEFENSE if self.teamId == TeamId.RED.value else Side.ATTACK

Ancestors

Class variables

var model_computed_fields
var model_config
var model_fields

Static methods

def from_dto(dto: TeamDto) ‑> TeamModel

Creates a TeamModel instance from a TeamDto instance.

Args

dto : TeamDto
The TeamDto instance.

Returns

TeamModel
The created TeamModel instance.
Expand source code
@classmethod
def from_dto(cls, dto:TeamDto) -> "TeamModel":
    """
    Creates a TeamModel instance from a TeamDto instance.

    Args:
        dto (TeamDto): The TeamDto instance.

    Returns:
        TeamModel: The created TeamModel instance.
    """
    return cls(**dto.model_dump())

Methods

def side(self, roundNum: int) ‑> Side

Determines the side of the team based on the round number.

Args

roundNum : int
The round number.

Returns

Side
The side of the team.
Expand source code
def side(self, roundNum:int) -> Side:
    """
    Determines the side of the team based on the round number.

    Args:
        roundNum (int): The round number.

    Returns:
        Side: The side of the team.
    """
    if(roundNum < 12 or (roundNum >= 24 and roundNum % 2 == 0)):
        return Side.ATTACK if self.teamId == TeamId.RED.value else Side.DEFENSE
    else:
        return Side.DEFENSE if self.teamId == TeamId.RED.value else Side.ATTACK