Source code for sidequest_common.schemas.heroes

  1"""Hall of Heroes: a members-only, raider.io-style leaderboard and per-member profile.
  2
  3Attendance for raids/events/EP/attendance-rate is defined once, in ``sidequest_api.lib.attendance.attended_condition``
  4(a SQLAlchemy condition over ``EventSignup`` joined to ``GuildEvent``); every stat here is derived from it rather
  5than from a separate "attended" concept.
  6
  7``SEASONS`` is the only thing to touch to add a season: append one more entry with a ``starts_at`` after the
  8previous season's ``ends_at`` (``None`` means "still running").
  9"""
 10
 11from datetime import date, datetime  # pydantic needs them at runtime
 12from uuid import UUID  # pydantic needs it at runtime
 13
 14from pydantic import BaseModel, ConfigDict, Field
 15
 16from sidequest_common.schemas.badges import EarnedBadge
 17from sidequest_common.schemas.events import EventKind, WowClass
 18from sidequest_common.schemas.stats import StatsHourCell
 19
 20
[docs] 21class Season(BaseModel): 22 """One competitive season. Open-ended (``ends_at: None``) until a later season starts.""" 23 24 id: str 25 name: str 26 starts_at: datetime 27 ends_at: datetime | None
28 29 30SEASONS: tuple[Season, ...] = ( 31 Season( 32 id="season-one", 33 name="Season One", 34 starts_at=datetime.fromisoformat("2026-11-04T00:00:00+00:00"), 35 ends_at=None, 36 ), 37) 38"""Ordered oldest-first. The last entry's ``ends_at`` is always ``None`` (the current season).""" 39 40
[docs] 41class HeroSeasonStats(BaseModel): 42 """One member's stats for one season (or all time).""" 43 44 ep: int = Field(description="Renown (EP) earned in this season.") 45 raids_attended: int 46 events_attended: int 47 attendance_rate: float = Field( 48 description="Attended divided by signed-up for completed events in range. 0.0 with no signed-up " 49 "completed events." 50 )
51 52
[docs] 53class HeroRow(BaseModel): 54 """One leaderboard row.""" 55 56 rank: int | None = Field(description="Position by EP this season, None for members listed with no EP yet.") 57 member_id: int 58 discord_id: str 59 display_name: str 60 avatar_url: str | None 61 wow_class: WowClass | None 62 chat_level: int 63 ep: int = Field(description="Renown (EP) earned this season.") 64 raids_attended: int 65 events_attended: int 66 badge_ids: list[str]
67 68
[docs] 69class HeroLeaderboard(BaseModel): 70 """``GET /api/heroes``.""" 71 72 season_id: str 73 season_name: str 74 rows: list[HeroRow]
75 76
[docs] 77class HeroRecentEvent(BaseModel): 78 """One recent event a member attended, for the profile's recent-events list.""" 79 80 model_config = ConfigDict(from_attributes=True) 81 82 id: UUID 83 kind: EventKind 84 title: str 85 starts_at: datetime 86 ep: int = Field(description="Renown (EP) this event awarded the member.")
87 88
[docs] 89class HeroProfile(BaseModel): 90 """``GET /api/heroes/{member_id}``.""" 91 92 member_id: int 93 discord_id: str 94 display_name: str 95 avatar_url: str | None 96 wow_class: WowClass | None 97 rank: int | None = Field( 98 description="Rank within the current season's leaderboard, None if outside it (no EP this season)." 99 ) 100 chat_level: int 101 chat_xp: int 102 chat_xp_into_level: int 103 chat_xp_for_next_level: int 104 seasons: dict[str, HeroSeasonStats] 105 all_time: HeroSeasonStats 106 first_event_date: date | None 107 recent_events: list[HeroRecentEvent] 108 badges: list[EarnedBadge]
109 110
[docs] 111class HeroXPSources(BaseModel): 112 """Breakdown of a member's lifetime XP by source. ``earlier`` is XP earned before per-source tracking started.""" 113 114 chat: int 115 voice: int 116 events: int 117 groups: int 118 earlier: int = Field(description="``max(0, xp - (chat + voice + events + groups))``.")
119 120
[docs] 121class HeroLevelReward(BaseModel): 122 """A level-role reward, with the role's current name.""" 123 124 level: int 125 role_name: str
126 127
[docs] 128class HeroDay(BaseModel): 129 """Activity on one America/Chicago calendar day.""" 130 131 day: date 132 messages: int 133 voice_minutes: int
134 135
[docs] 136class HeroActivity(BaseModel): 137 """``GET /api/heroes/{member_id}/activity``: MEE6-style stats for a member's Hall of Heroes profile.""" 138 139 member_id: int 140 level: int 141 xp: int 142 xp_into_level: int 143 xp_for_next_level: int 144 xp_rank: int | None = Field(description="Rank among guild members by total XP, like `/rank`; `null` if unranked.") 145 ranked_members: int 146 next_reward: HeroLevelReward | None = Field(description="The lowest level-role reward above the current level.") 147 message_count: int = Field(description="Lifetime message count.") 148 voice_minutes: int = Field(description="All tracked voice minutes, lifetime.") 149 events_attended: int 150 groups_joined: int 151 messages_30d: int 152 voice_minutes_30d: int 153 chat_rank_30d: int | None = Field(description="Rank among members by 30-day messages; `null` if they sent none.") 154 voice_rank_30d: int | None = Field( 155 description="Rank among members by 30-day voice minutes; `null` if they had none." 156 ) 157 current_streak_days: int = Field(description="Consecutive America/Chicago days with a message or voice minute.") 158 longest_streak_days: int 159 xp_sources: HeroXPSources 160 days: list[HeroDay] = Field(description="Last 30 days including today, oldest first, zero-filled.") 161 heatmap: list[StatsHourCell] = Field(description="Last 90 days, non-zero weekday/hour cells only.") 162 tracking_since: datetime | None