Source code for sidequest_common.models.pvp

 1"""Battleground scoreboards recorded by members' addons. Members-only data: other players' names and stats included."""
 2
 3from datetime import datetime  # SQLAlchemy resolves Mapped[] annotations at runtime
 4from uuid import UUID  # SQLAlchemy resolves Mapped[] annotations at runtime
 5
 6from advanced_alchemy.base import UUIDAuditBase
 7from advanced_alchemy.types import DateTimeUTC
 8from sqlalchemy import ForeignKey, Integer, String, Text
 9from sqlalchemy.orm import Mapped, mapped_column
10
11
[docs] 12class BattlegroundMatch(UUIDAuditBase): 13 """One finished battleground, stored once however many members recorded it. 14 15 ``external_id`` is the first recording's addon id. ``guild_faction`` is the side the recording member played on. 16 """ 17 18 __tablename__ = "battleground_match" 19 __table_args__ = {"comment": "Finished battlegrounds recorded by members' addons; one row per match."} 20 21 external_id: Mapped[str] = mapped_column(String(80), unique=True, index=True) 22 map: Mapped[str] = mapped_column(Text) 23 instance_id: Mapped[int] = mapped_column(Integer, index=True) 24 ended_at: Mapped[datetime] = mapped_column(DateTimeUTC(timezone=True), index=True) 25 duration: Mapped[int] = mapped_column(Integer, default=0) 26 winner: Mapped[str | None] = mapped_column(String(10), default=None) 27 guild_faction: Mapped[str] = mapped_column(String(10)) 28 recorder: Mapped[str] = mapped_column(Text)
29 30
[docs] 31class BattlegroundScore(UUIDAuditBase): 32 """One scoreboard row of a match. ``character_id`` links it to a guild character when the name matches one.""" 33 34 __tablename__ = "battleground_score" 35 __table_args__ = {"comment": "Scoreboard rows of recorded battlegrounds, one per player per match."} 36 37 match_id: Mapped[UUID] = mapped_column(ForeignKey("battleground_match.id", ondelete="CASCADE"), index=True) 38 character_id: Mapped[UUID | None] = mapped_column( 39 ForeignKey("wow_character.id", ondelete="SET NULL"), index=True, default=None 40 ) 41 name: Mapped[str] = mapped_column(Text) 42 faction: Mapped[str] = mapped_column(String(10)) 43 race: Mapped[str | None] = mapped_column(Text, default=None) 44 wow_class: Mapped[str | None] = mapped_column(String(20), default=None) 45 killing_blows: Mapped[int] = mapped_column(Integer, default=0) 46 honorable_kills: Mapped[int] = mapped_column(Integer, default=0) 47 deaths: Mapped[int] = mapped_column(Integer, default=0) 48 honor_gained: Mapped[int] = mapped_column(Integer, default=0) 49 damage_done: Mapped[int] = mapped_column(Integer, default=0) 50 healing_done: Mapped[int] = mapped_column(Integer, default=0)