async def get_spec_ranking(spec_slug, boss_slug, difficulty: str = "mythic", metric: str = "", limit: int = 0): if not metric: spec = WowSpec.get(full_name_slug=spec_slug) metric = spec.role.metric spec_ranking = warcraftlogs_ranking.SpecRanking.get_or_create( boss_slug=boss_slug, spec_slug=spec_slug, difficulty=difficulty, metric=metric, ) fights = spec_ranking.fights or [] if limit: fights = fights[:limit] # remove bosses for fight in fights[1:]: fight.boss = None return { "fights": [fight.as_dict() for fight in fights], "updated": int(spec_ranking.updated.timestamp()), "difficulty": difficulty, "metric": metric, }
async def get_spec_spells(spec_slug: str): """Get all spells for a given spec. Args: spec_slug (str): name of the spec """ spec: WowSpec = WowSpec.get(full_name_slug=spec_slug) if not spec: return "Invalid Spec.", 404 abilities = spec.all_spells + spec.all_buffs + spec.all_debuffs + spec.all_events return {spell.spell_id: spell.as_dict() for spell in abilities}
def process_players(self, players_data): if not players_data: logger.warning("players_data is empty") return total_damage = players_data.get("damageDone", []) total_healing = players_data.get("healingDone", []) for composition_data in players_data.get("composition", []): spec_data = composition_data.get("specs", []) if not spec_data: logger.warning("Player has no spec: %s", composition_data.get("name")) continue spec_data = spec_data[0] spec_name = spec_data.get("spec") class_name = composition_data.get("type") spec = WowSpec.get(name_slug_cap=spec_name, wow_class__name_slug_cap=class_name) if not spec: logger.warning("Unknown Spec: %s", spec_name) continue # Get Total Damage or Healing spec_role = spec_data.get("role") total_data = total_healing if spec_role == "healer" else total_damage for data in total_data: if data.get("id", -1) == composition_data.get("id"): total = data.get("total", 0) / (self.duration / 1000) break else: total = 0 # create and return yield player object player = Player() player.fight = self player.spec_slug = spec.full_name_slug player.source_id = composition_data.get("id") player.name = composition_data.get("name") player.total = int(total) player.process_death_events(players_data.get("deathEvents", [])) self.players[str(player.source_id)] = player # call this before filtering to always get the full comp self.composition = get_composition(self.players.values())
def spec(self) -> WowSpec: return WowSpec.get(full_name_slug=self.spec_slug)
async def get_spec(spec_slug: str): spec = WowSpec.get(full_name_slug=spec_slug) if not spec: return "Invalid Spec.", 404 return spec.as_dict()