Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address #81: Missing metric after Jagex/WOM Update #82

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions tests/test_enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,12 @@ def test_hash() -> None:
def test_at_random(choice: mock.MagicMock) -> None:
_ = wom.Metric.at_random()
choice.assert_called_once_with(tuple(wom.Metric))


def test_base_enum_missing() -> None:
"""A test for the BaseEnum.__missing__ method."""
assert wom.Metric("new_fake_metric") == wom.Metric.Unknown
assert wom.Metric("another_fake_metric") == wom.Metric.Unknown
assert wom.Metric.Unknown.value == "unknown"
assert wom.Metric.Unknown != wom.Metric.Vardorvis
assert wom.Metric.Attack.value == "attack"
21 changes: 20 additions & 1 deletion wom/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from __future__ import annotations

import random
import sys
import typing as t
from enum import Enum

Expand Down Expand Up @@ -58,6 +59,15 @@ def __eq__(self, other: object) -> bool:
def __hash__(self) -> int:
return hash(self.value)

@classmethod
def _missing_(cls, value: object) -> BaseEnum:
print(
f"{value!r} is not a valid {cls.__name__} variant. "
"Please report this issue on github at https://github.com/Jonxslays/wom.py/issues/new",
file=sys.stderr,
)
return cls.Unknown # type: ignore

@classmethod
def at_random(cls: t.Type[T]) -> T:
"""Generates a random variant of this enum.
Expand All @@ -77,6 +87,9 @@ class Period(BaseEnum):
Month = "month"
Year = "year"

# Unknown metric
Unknown = "unknown"


class Metric(BaseEnum):
"""Represents all metrics including skills, bosses, activities, and
Expand Down Expand Up @@ -198,8 +211,11 @@ class Metric(BaseEnum):
Ehp = "ehp"
Ehb = "ehb"

# Unknown Metric
Unknown = "unknown"


ComputedMetrics: t.FrozenSet[Metric] = frozenset({Metric.Ehp, Metric.Ehb})
ComputedMetrics: t.FrozenSet[Metric] = frozenset({Metric.Ehp, Metric.Ehb, Metric.Unknown})
"""Set containing all the types of computed metrics."""

Skills: t.FrozenSet[Metric] = frozenset(
Expand Down Expand Up @@ -228,6 +244,7 @@ class Metric(BaseEnum):
Metric.Runecrafting,
Metric.Hunter,
Metric.Construction,
Metric.Unknown,
}
)
"""Set containing skills."""
Expand All @@ -250,6 +267,7 @@ class Metric(BaseEnum):
Metric.PvpArena,
Metric.SoulWarsZeal,
Metric.GuardiansOfTheRift,
Metric.Unknown,
}
)
"""Set containing activities."""
Expand Down Expand Up @@ -321,6 +339,7 @@ class Metric(BaseEnum):
Metric.Wintertodt,
Metric.Zalcano,
Metric.Zulrah,
Metric.Unknown,
}
)
"""Set containing bosses."""
3 changes: 3 additions & 0 deletions wom/models/competitions/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class CompetitionType(BaseEnum):

Classic = "classic"
Team = "team"
Unknown = "unknown"


class CompetitionStatus(BaseEnum):
Expand All @@ -41,6 +42,7 @@ class CompetitionStatus(BaseEnum):
Upcoming = "upcoming"
Ongoing = "ongoing"
Finished = "finished"
Unknown = "unknown"


class CompetitionCSVTableType(BaseEnum):
Expand All @@ -49,3 +51,4 @@ class CompetitionCSVTableType(BaseEnum):
Participants = "participants"
Team = "team"
Teams = "teams"
Unknown = "unknown"
2 changes: 2 additions & 0 deletions wom/models/groups/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class GroupActivityType(BaseEnum):
ChangedRole = "changed_role"
Joined = "joined"
Left = "left"
Unknown = "unknown"


class GroupRole(BaseEnum):
Expand Down Expand Up @@ -306,3 +307,4 @@ class GroupRole(BaseEnum):
Zarosian = "zarosian"
Zealot = "zealot"
Zenyte = "zenyte"
Unknown = "unknown"
2 changes: 2 additions & 0 deletions wom/models/names/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class NameChangeStatus(BaseEnum):
Pending = "pending"
Approved = "approved"
Denied = "denied"
Unknown = "unknown"


class NameChangeReviewReason(BaseEnum):
Expand All @@ -42,3 +43,4 @@ class NameChangeReviewReason(BaseEnum):
TransitionTooLong = "transition_period_too_long"
ExcessiveGains = "excessive_gains"
TotalLevelTooLow = "total_level_too_low"
Unknown = "unknown"
4 changes: 4 additions & 0 deletions wom/models/players/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class PlayerBuild(BaseEnum):
Def1 = "def1"
Hp10 = "hp10"
F2pLvl3 = "f2p_lvl3"
Unknown = "unknown"


class PlayerStatus(BaseEnum):
Expand All @@ -63,6 +64,7 @@ class PlayerStatus(BaseEnum):
Flagged = "flagged"
Archived = "archived"
Banned = "banned"
Unknown = "unknown"


class AchievementMeasure(BaseEnum):
Expand All @@ -73,6 +75,7 @@ class AchievementMeasure(BaseEnum):
Kills = "kills"
Score = "score"
Value = "value"
Unknown = "unknown"


class Country(BaseEnum):
Expand Down Expand Up @@ -327,3 +330,4 @@ class Country(BaseEnum):
Za = "ZA"
Zm = "ZM"
Zw = "ZW"
Unknown = "unknown"
6 changes: 1 addition & 5 deletions wom/services/efficiency.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,7 @@ async def get_global_leaderboards(
playerType=player_type.value if player_type else None,
playerBuild=player_build.value if player_build else None,
country=country.value if country else None,
metric=(
metric.value
if not both
else "+".join(sorted((m.value for m in enums.ComputedMetrics), reverse=True))
),
metric=(metric.value if not both else "ehp+ehb"),
)

route = routes.GLOBAL_EFFICIENCY_LEADERS.compile()
Expand Down