1"""Gear-swap sims through wowsims/forever: the bot's ``#sim`` forum request and result shapes.
2
3A member names a character and up to 6 gear swaps; the API queues a sim job (``SimJob`` holds its own worn gear
4``wearing`` corrections, since Battle.net's copy of a character's gear is stale until it next logs out), runs
5``wowsimcli`` once per job, and returns one ``SimComparison`` per combination of swaps applied, each with one
6``SimRow`` per (targets, mob) scenario the request asked for.
7"""
8
9from datetime import datetime
10from typing import Literal
11from uuid import UUID
12
13from pydantic import BaseModel, Field
14
15SIM_SLOTS = (
16 "head",
17 "neck",
18 "shoulder",
19 "back",
20 "chest",
21 "wrist",
22 "hands",
23 "waist",
24 "legs",
25 "feet",
26 "finger1",
27 "finger2",
28 "trinket1",
29 "trinket2",
30 "main_hand",
31 "off_hand",
32 "ranged",
33)
34SIM_MOB_TYPES = ("humanoid", "undead", "beast", "demon", "dragonkin", "elemental", "giant", "mechanical")
35MAX_SIM_SWAPS = 6
36MAX_SIM_WEARING = 17
37MAX_QUEUED_SIM_JOBS = 3
38SIM_JOB_RETENTION_DAYS = 7
39SimSlot = Literal[
40 "head",
41 "neck",
42 "shoulder",
43 "back",
44 "chest",
45 "wrist",
46 "hands",
47 "waist",
48 "legs",
49 "feet",
50 "finger1",
51 "finger2",
52 "trinket1",
53 "trinket2",
54 "main_hand",
55 "off_hand",
56 "ranged",
57]
58SimMobType = Literal["humanoid", "undead", "beast", "demon", "dragonkin", "elemental", "giant", "mechanical"]
59SimRole = Literal["tank", "healer", "dps"]
60SimJobStatusName = Literal["queued", "running", "done", "failed"]
61
62
[docs]
63class SimItem(BaseModel):
64 """One item to try (a swap) or correct the baseline with (``wearing``)."""
65
66 item: str = Field(
67 description="The item's numeric game id, a wowhead URL containing `item=<id>`, or its name (case-insensitive)."
68 )
69 slot: SimSlot | None = Field(
70 default=None,
71 description=(
72 "The slot to put the item in. Required unless the item only fits one slot; a ring or trinket with no "
73 "slot is tried in both of its slots as separate comparisons."
74 ),
75 )
76 enchant: str | None = Field(default=None, description="An enchant name to apply to the item.")
77 suffix: str | None = Field(default=None, description="A random-suffix name (e.g. 'of the Bear') on the item.")
78
79
[docs]
80class SimRequest(BaseModel):
81 """Body for ``POST /api/guilds/{guild_id}/sims``."""
82
83 character: str = Field(description="The character's 'Name Surname' or slug, e.g. 'legs-behindhead'.")
84 swaps: list[SimItem] = Field(min_length=1, max_length=MAX_SIM_SWAPS, description="The items to try, up to 6.")
85 wearing: list[SimItem] = Field(
86 default_factory=list,
87 max_length=MAX_SIM_WEARING,
88 description=(
89 "Corrections to the character's stored gear, since Battle.net's copy is stale until the character "
90 "next logs out."
91 ),
92 )
93 spec: str | None = Field(
94 default=None,
95 description="Override the character's spec, e.g. 'feralbear' for a druid tanking instead of cat form.",
96 )
97 talents: str | None = Field(
98 default=None, description="A wowhead-style talent string; defaults to the spec preset's own talents."
99 )
100 targets: list[int] = Field(
101 default_factory=lambda: [1, 4], description="Target counts to sim, each 1-5 (default 1 and 4)."
102 )
103 mobs: list[SimMobType] = Field(default_factory=lambda: ["humanoid"], description="Mob types to sim against.")
104 duration: int = Field(default=90, ge=30, le=300, description="Fight length in seconds.")
105 requested_by: str | None = Field(default=None, description="The requesting Discord user's id, for rate limiting.")
106
107
[docs]
108class SimMetrics(BaseModel):
109 """One scenario's measured metrics. A metric a spec doesn't produce (e.g. ``hps`` for a dps spec) is `None`."""
110
111 dps: float | None = None
112 tps: float | None = None
113 dtps: float | None = None
114 hps: float | None = None
115
116
[docs]
117class ItemRef(BaseModel):
118 """An item as a changed-gear line names it."""
119
120 id: int = Field(description="The item's game id.")
121 name: str = Field(description="The item's display name.")
122
123
[docs]
124class GearChange(BaseModel):
125 """One slot changed between a comparison's baseline and swapped gear."""
126
127 slot: SimSlot = Field(description="The slot that changed.")
128 from_item: ItemRef | None = Field(default=None, description="What was in the slot before, if anything.")
129 to_item: ItemRef = Field(description="What's in the slot now.")
130
131
[docs]
132class SimRow(BaseModel):
133 """One (targets, mob) scenario's baseline vs. swapped metrics."""
134
135 targets: int = Field(description="How many targets this scenario simmed against.")
136 mob: SimMobType = Field(description="The mob type this scenario simmed against.")
137 baseline: SimMetrics = Field(description="Metrics with the character's current gear.")
138 swapped: SimMetrics = Field(description="Metrics with this comparison's gear changes applied.")
139 delta_pct: SimMetrics = Field(description="Percent change from baseline to swapped, per metric.")
140 noise: list[str] = Field(
141 default_factory=list, description="Metric names whose delta is within two standard errors of zero."
142 )
143
144
[docs]
145class SimComparison(BaseModel):
146 """One combination of swaps applied, across every requested scenario."""
147
148 label: str = Field(description="What changed, e.g. 'main_hand: Eater of the Dead -> Blade of Necromancy'.")
149 changes: list[GearChange] = Field(description="The gear changes this comparison applied.")
150 rows: list[SimRow] = Field(description="One row per requested (targets, mob) scenario.")
151
152
[docs]
153class SimResult(BaseModel):
154 """What a finished sim job found."""
155
156 character: str = Field(description="The character's 'Name Surname'.")
157 class_name: str = Field(description="The character's class.")
158 spec: str = Field(description="The spec simmed, e.g. 'protection'.")
159 role: SimRole = Field(description="The spec's role: tank, healer, or dps.")
160 level: int = Field(description="The character's level (the sim only models level 60).")
161 gear_fetched_at: datetime | None = Field(
162 default=None, description="When the character's gear was last fetched from Battle.net."
163 )
164 iterations: int = Field(description="Sim iterations run per scenario.")
165 duration: int = Field(description="Fight length in seconds.")
166 comparisons: list[SimComparison] = Field(description="One comparison per combination of swaps applied.")
167 notes: list[str] = Field(
168 default_factory=list,
169 description="Things the sim skipped or approximated, such as an enchant with no sim equivalent.",
170 )
171
172
[docs]
173class SimJobSchema(BaseModel):
174 """A sim job's status, and its result once done."""
175
176 id: UUID = Field(description="The job's id.")
177 status: SimJobStatusName = Field(description="queued, running, done, or failed.")
178 position: int | None = Field(
179 default=None, description="This job's place in the queue, counting other queued jobs ahead of it."
180 )
181 error: str | None = Field(default=None, description="A plain-English failure reason, if status is failed.")
182 result: SimResult | None = Field(default=None, description="The sim result, once status is done.")
183 created_at: datetime = Field(description="When the job was queued.")