Skip to content

Commit

Permalink
Update rosu-pp-py
Browse files Browse the repository at this point in the history
  • Loading branch information
Syriiin committed May 4, 2024
1 parent cee0016 commit 7cf5292
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 27 deletions.
24 changes: 16 additions & 8 deletions common/osu/difficultycalculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ class CalculationException(DifficultyCalculatorException):
pass


class NotYetCalculatedException(DifficultyCalculatorException):
pass


class AbstractDifficultyCalculator(AbstractContextManager, ABC):
def __init__(self):
self.closed = False
Expand Down Expand Up @@ -206,13 +210,15 @@ class RosuppDifficultyCalculator(AbstractDifficultyCalculator):
def __init__(self):
super().__init__()

self.rosupp_calc = rosu_pp_py.Calculator()
self.rosupp_calc = rosu_pp_py.Performance()
self.results = None

def _close(self):
pass

def _reset(self):
self.rosupp_calc = rosu_pp_py.Calculator()
self.rosupp_calc = rosu_pp_py.Performance()
self.results = None

def set_beatmap(self, beatmap_id: str) -> None:
beatmap_provider = BeatmapProvider()
Expand All @@ -235,7 +241,7 @@ def set_accuracy(self, count_100: int, count_50: int):
self.rosupp_calc.set_n50(count_50)

def set_misses(self, count_miss: int):
self.rosupp_calc.set_n_misses(count_miss)
self.rosupp_calc.set_misses(count_miss)

def set_combo(self, combo: int):
self.rosupp_calc.set_combo(combo)
Expand All @@ -244,17 +250,19 @@ def set_mods(self, mods: int):
self.rosupp_calc.set_mods(mods)

def _calculate(self):
# rosu_pp_py does lazy calculations it seems
pass
self.results = self.rosupp_calc.calculate(self.beatmap)

@property
def difficulty_total(self) -> float:
# TODO: PR to rosu-pp-py to add real type hints here
return self.rosupp_calc.difficulty(self.beatmap).stars or 0.0 # type: ignore
if self.results is None:
raise NotYetCalculatedException("Results have not been calculated")
return self.results.difficulty.stars

@property
def performance_total(self) -> float:
return self.rosupp_calc.performance(self.beatmap).pp or 0.0 # type: ignore
if self.results is None:
raise NotYetCalculatedException("Results have not been calculated")
return self.results.pp

@staticmethod
def engine():
Expand Down
9 changes: 5 additions & 4 deletions common/osu/test_difficultycalculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ def test_version(self):
def test_context_manager(self):
with RosuppDifficultyCalculator() as calc:
calc.set_beatmap("307618")
calc.calculate()
assert calc.difficulty_total == 4.457399442092882

def test_invalid_beatmap(self):
Expand Down Expand Up @@ -176,7 +177,7 @@ def test_calculate_score_batch(self):
]
assert calc.calculate_score_batch(scores) == [
Calculation(difficulty=6.264344677869616, performance=312.43705315450256),
Calculation(difficulty=6.531051472171891, performance=487.59048617563496),
Calculation(difficulty=6.531051472171891, performance=487.5904861756349),
Calculation(difficulty=6.531051472171891, performance=655.9388807525456),
]

Expand All @@ -202,13 +203,13 @@ def test_set_accuracy(self, calc: RosuppDifficultyCalculator):
calc.set_accuracy(14, 1)
calc.calculate()
assert calc.difficulty_total == 4.457399442092882
assert calc.performance_total == 124.11285312370455
assert calc.performance_total == 124.11285312370458

def test_set_misses(self, calc: RosuppDifficultyCalculator):
calc.set_misses(1)
calc.calculate()
assert calc.difficulty_total == 4.457399442092882
assert calc.performance_total == 130.64187056414588
assert calc.performance_total == 130.60976567558188

def test_set_combo(self, calc: RosuppDifficultyCalculator):
calc.set_combo(2000)
Expand All @@ -220,4 +221,4 @@ def test_set_mods(self, calc: RosuppDifficultyCalculator):
calc.set_mods(Mods.DOUBLETIME + Mods.HIDDEN)
calc.calculate()
assert calc.difficulty_total == 6.264344677869616
assert calc.performance_total == 425.80658059182343
assert calc.performance_total == 425.8065805918235
70 changes: 60 additions & 10 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions profiles/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def test_update_difficulty_values(self, beatmap: Beatmap):
beatmap.update_difficulty_values(DifficultyCalculator)
assert beatmap.difficulty_total == 6.711556915919059
assert beatmap.difficulty_calculator_engine == "rosu-pp-py"
assert beatmap.difficulty_calculator_version == "0.9.4"
assert beatmap.difficulty_calculator_version == "1.0.0"


@pytest.mark.django_db
Expand All @@ -68,11 +68,11 @@ def test_process(self, score: Score):

def test_update_performance_values(self, score: Score):
score.update_performance_values(DifficultyCalculator)
assert score.performance_total == 625.3261007335672
assert score.performance_total == 626.7353926695473
assert score.nochoke_performance_total == 626.7353926695473
assert score.difficulty_total == 8.975730066553297
assert score.difficulty_calculator_engine == "rosu-pp-py"
assert score.difficulty_calculator_version == "0.9.4"
assert score.difficulty_calculator_version == "1.0.0"


@pytest.fixture
Expand Down Expand Up @@ -119,4 +119,4 @@ def test_calculate_performance_values(
)
assert len(performance_values) == 1
assert performance_values[0].name == "total"
assert performance_values[0].value == 625.3261007335672
assert performance_values[0].value == 626.7353926695473
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ oppaipy = "^1.0.4"
psycopg2-binary = "^2.9.1"
pymemcache = "^4.0.0"
requests = "^2.25.1"
rosu-pp-py = "^0.9.3"
rosu-pp-py = "^1.0.0"
tqdm = "^4.64.0"
flower = "^2.0.0"
pydantic-settings = "^2.0.0"
Expand Down

0 comments on commit 7cf5292

Please sign in to comment.