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

Use json mods #189

Merged
merged 6 commits into from
Dec 18, 2024
Merged
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
29 changes: 12 additions & 17 deletions common/osu/difficultycalculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@

class Score(NamedTuple):
beatmap_id: str
mods: int | None = None
is_stable: bool = True
mods: dict[str, dict] = {}
statistics: dict[str, int] = {}
combo: int | None = None

Expand Down Expand Up @@ -108,6 +107,12 @@ def _get_url(self) -> str:
def _difficalcy_score_from_score(self, score: Score) -> dict:
raise NotImplementedError()

@staticmethod
def _get_difficalcy_mods(mods: dict[str, dict]) -> list[dict]:
return [
{"acronym": mod, "settings": settings} for mod, settings in mods.items()
]

def calculate_scores(self, scores: Iterable[Score]) -> list[Calculation]:
try:
response = self.client.post(
Expand Down Expand Up @@ -143,9 +148,7 @@ def _difficalcy_score_from_score(self, score: Score) -> dict:
k: v
for k, v in {
"BeatmapId": score.beatmap_id,
"Mods": get_json_array_mods(
score.mods if score.mods is not None else 0, score.is_stable
),
"Mods": self._get_difficalcy_mods(score.mods),
"Combo": score.combo,
"Misses": score.statistics.get("miss", 0),
"Mehs": score.statistics.get("meh", 0),
Expand Down Expand Up @@ -178,9 +181,7 @@ def _difficalcy_score_from_score(self, score: Score) -> dict:
k: v
for k, v in {
"BeatmapId": score.beatmap_id,
"Mods": get_json_array_mods(
score.mods if score.mods is not None else 0, score.is_stable
),
"Mods": self._get_difficalcy_mods(score.mods),
"Combo": score.combo,
"Misses": score.statistics.get("miss", 0),
"Oks": score.statistics.get("ok", 0),
Expand Down Expand Up @@ -210,9 +211,7 @@ def _difficalcy_score_from_score(self, score: Score) -> dict:
k: v
for k, v in {
"BeatmapId": score.beatmap_id,
"Mods": get_json_array_mods(
score.mods if score.mods is not None else 0, score.is_stable
),
"Mods": self._get_difficalcy_mods(score.mods),
"Combo": score.combo,
"Misses": score.statistics.get("miss", 0),
"SmallDroplets": score.statistics.get("small_tick_hit", 0),
Expand Down Expand Up @@ -243,9 +242,7 @@ def _difficalcy_score_from_score(self, score: Score) -> dict:
k: v
for k, v in {
"BeatmapId": score.beatmap_id,
"Mods": get_json_array_mods(
score.mods if score.mods is not None else 0, score.is_stable
),
"Mods": self._get_difficalcy_mods(score.mods),
"Combo": score.combo,
"Misses": score.statistics.get("miss", 0),
"Mehs": score.statistics.get("meh", 0),
Expand Down Expand Up @@ -280,9 +277,7 @@ def _difficalcy_score_from_score(self, score: Score) -> dict:
k: v
for k, v in {
"BeatmapId": score.beatmap_id,
"Mods": get_json_array_mods(
score.mods if score.mods is not None else 0, score.is_stable
),
"Mods": self._get_difficalcy_mods(score.mods),
"Combo": score.combo,
"Misses": score.statistics.get("miss", 0),
"Mehs": score.statistics.get("meh", 0),
Expand Down
37 changes: 36 additions & 1 deletion common/osu/enums.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# osu! related enums

from enum import IntEnum
from enum import IntEnum, StrEnum

# Mods
# https://github.com/ppy/osu-api/wiki#mods
Expand Down Expand Up @@ -65,6 +65,41 @@ class Mods(IntEnum):
)


class NewMods(StrEnum):
NOFAIL = "NF"
EASY = "EZ"
TOUCH_DEVICE = "TD"
HIDDEN = "HD"
HARDROCK = "HR"
SUDDEN_DEATH = "SD"
DOUBLETIME = "DT"
RELAX = "RX"
HALFTIME = "HT"
NIGHTCORE = "NC"
FLASHLIGHT = "FL"
AUTO = "AUTO"
SPUN_OUT = "SO"
AUTOPILOT = "AP"
PERFECT = "PF"
KEY_4 = "4K"
KEY_5 = "5K"
KEY_6 = "6K"
KEY_7 = "7K"
KEY_8 = "8K"
FADE_IN = "FI"
RANDOM = "RN"
CINEMA = "CN"
TARGET_PRACTICE = "TP"
KEY_9 = "9K"
KEY_COOP = "COOP"
KEY_1 = "1K"
KEY_2 = "2K"
KEY_3 = "3K"
SCORE_V2 = "V2"
MIRROR = "MI"
CLASSIC = "CL"


# Gamemodes


Expand Down
33 changes: 22 additions & 11 deletions common/osu/test_difficultycalculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
DifficalcyTaikoDifficultyCalculator,
Score,
)
from common.osu.enums import Mods
from common.osu.enums import NewMods


class TestDifficalcyDifficultyCalculator:
def test_context_manager(self):
with DifficalcyOsuDifficultyCalculator() as calc:
assert calc.calculate_scores([Score("307618")]) == [
assert calc.calculate_scores(
[Score("307618", mods={NewMods.CLASSIC: {}})]
) == [
Calculation(
difficulty_values={
"aim": 2.095341891859337,
Expand Down Expand Up @@ -44,7 +46,7 @@ def test_calculate_scores(self):
scores = [
Score(
"307618",
mods=int(Mods.DOUBLETIME + Mods.HIDDEN),
mods={NewMods.DOUBLETIME: {}, NewMods.HIDDEN: {}, NewMods.CLASSIC: {}},
statistics={
"ok": 14,
"meh": 1,
Expand All @@ -54,7 +56,12 @@ def test_calculate_scores(self):
),
Score(
"307618",
mods=int(Mods.DOUBLETIME + Mods.HIDDEN + Mods.HARDROCK),
mods={
NewMods.DOUBLETIME: {},
NewMods.HIDDEN: {},
NewMods.HARDROCK: {},
NewMods.CLASSIC: {},
},
statistics={
"ok": 14,
"meh": 1,
Expand All @@ -64,11 +71,15 @@ def test_calculate_scores(self):
),
Score(
"307618",
mods=int(Mods.DOUBLETIME + Mods.HIDDEN + Mods.HARDROCK),
mods={
NewMods.DOUBLETIME: {},
NewMods.HIDDEN: {},
NewMods.HARDROCK: {},
NewMods.CLASSIC: {},
},
),
Score(
"422328",
is_stable=False,
statistics={
"ok": 13,
"miss": 14,
Expand Down Expand Up @@ -158,7 +169,7 @@ def test_calculate_scores(self):
calc = DifficalcyOsuDifficultyCalculator()
score = Score(
"307618",
mods=int(Mods.DOUBLETIME + Mods.HIDDEN),
mods={NewMods.DOUBLETIME: {}, NewMods.HIDDEN: {}, NewMods.CLASSIC: {}},
statistics={
"ok": 14,
"meh": 1,
Expand Down Expand Up @@ -196,7 +207,7 @@ def test_calculate_scores(self):
calc = DifficalcyTaikoDifficultyCalculator()
score = Score(
"2",
mods=int(Mods.DOUBLETIME + Mods.HARDROCK),
mods={NewMods.DOUBLETIME: {}, NewMods.HARDROCK: {}, NewMods.CLASSIC: {}},
statistics={
"ok": 3,
"miss": 5,
Expand Down Expand Up @@ -231,7 +242,7 @@ def test_calculate_scores(self):
calc = DifficalcyCatchDifficultyCalculator()
score = Score(
"3",
mods=int(Mods.DOUBLETIME + Mods.HARDROCK),
mods={NewMods.DOUBLETIME: {}, NewMods.HARDROCK: {}, NewMods.CLASSIC: {}},
statistics={
"large_tick_hit": 18,
"small_tick_hit": 200,
Expand Down Expand Up @@ -262,7 +273,7 @@ def test_calculate_scores(self):
calc = DifficalcyManiaDifficultyCalculator()
score = Score(
"4",
mods=int(Mods.DOUBLETIME + Mods.EASY),
mods={NewMods.DOUBLETIME: {}, NewMods.EASY: {}, NewMods.CLASSIC: {}},
statistics={
"great": 1,
"good": 2,
Expand Down Expand Up @@ -301,7 +312,7 @@ def test_calculate_scores(self):
calc = DifficalcyPerformancePlusDifficultyCalculator()
score = Score(
"307618",
mods=int(Mods.DOUBLETIME + Mods.HIDDEN),
mods={NewMods.DOUBLETIME: {}, NewMods.HIDDEN: {}, NewMods.CLASSIC: {}},
statistics={
"ok": 14,
"meh": 1,
Expand Down
Loading